请帮我解决VHDL编译错误

时间:2018-06-07 04:58:38

标签: compilation vhdl

library IEEE;
use IEEE.std_logic_1164.all;

entity doorlock is
port(   reset : in std_logic;
    enable : in std_logic;
    password : in std_logic_vector (7 downto 0);
    door : out std_logic_vector (7 downto 0);
    lock : out std_logic;
    alarm : out std_logic;
    turnoff : out std_logic);
end doorlock;

--password is 10(decimal no.) which is 00010000(binary no.)

architecture DDL of doorlock is
signal err_count : integer range 0 to 5 := 0;

begin
lock <= '0' when (reset = '0');
alarm <= '0' when (reset = '0');
turnoff <= '0' when (reset = '0');
door <= "00000000" when (reset = '0');
lock <= '0' when (enable <= '0');

process(password)
begin
    if (password = "-------1") then
    door <= "00000000";
    elsif (password = "------10") then
    door <= "00000001";
    elsif (password = "-----100") then
    door <= "00000011";
    elsif (password = "----1000") then
    door <= "00000111";
    elsif (password = "---00000") then
    door <= "00001111";
    elsif (password = "--110000") then
    door <= "00011111";
    elsif (password = "-1010000") then
    door <= "00111111";
    elsif (password = "10010000") then
    door <= "01111111";
    elsif (password = "00010000") then
    door <= "11111111";
    end if;

    err_count <= err_count + 1;
end process;

alarm <= '1' when (err_count = 3);
turnoff <= '1' when (err_count = 5);
lock <= '1' when (door = "11111111" and turnoff = '0' and alarm = '0');

end DDL;

我为我的家庭作业制作了数字门锁的代码。 当我编译它时,这一行有错误。

lock <= '1' when (door = "11111111" and turnoff = '0' and alarm = '0');

错误如下所示

**错误:D:\ modelsim \ Door.vhd(53):无法读取输出“报警”。

VHDL 2008允许读取输出。 通过使用-2008进行编译来启用此功能。

**错误:D:\ modelsim \ Door.vhd(53):无法读取输出“门”。

VHDL 2008允许读取输出。 通过使用-2008进行编译来启用此功能。

**错误:D:\ modelsim \ Door.vhd(53):无法读取输出“关闭”。

VHDL 2008允许读取输出。 通过使用-2008进行编译来启用此功能。

**错误:D:\ modelsim \ Door.vhd(55):VHDL编译器退出

我不知道为什么会这样,请帮帮我

1 个答案:

答案 0 :(得分:2)

首先:“请帮帮我”不是一个好问题。更好的是像“Modelsim错误”无法读取输出“编译时”

第二关:错误非常具有描述性。 “无法读取输出”报警“”。 alarm被声明为

alarm : out std_logic;

因此它是输出端口。在2008年之前的VHDL中,不允许读取输出端口。接下来,编译器提示如何修复它:

  

“VHDL 2008允许读取输出。通过使用-2008进行编译来启用此功能。”

所以这样做! 在modelsim编辑窗口中选择“默认选项”

enter image description here

然后设置为VHDL-2008

enter image description here

或者,您可以在命令行上实际执行所描述的内容(添加-2008):

  

vcom -reportprogress 300 -work work -2008 doorlock.vhd

瞧。完了!不?

不等,仍然无法正常工作!

您有多个驱动程序错误。第23行说明:

door <= "00000000" when (reset = '0');

这用作锁存器,实际上与

相同
process(reset) begin
    if reset = '0' then
        door <= "00000000";
    end if;
end process;

因此,一旦reset='0'发生,该过程就会将door驱动到固定值。在password - 触发的流程中,您再次开启door!这将很难解决。例如。如果(password = "------10"),则door <= "00000001"。这将解决:

resolve("00000000", "00000001") = "0000000X"

因为将'0'连接到'1'等同于短路。

让我们来看看正确的设计。您现在正在触发password的更改。不太好,但这是可能的。我会使用另一个触发器,例如未使用的enable信号。但无论如何:我们引入了额外的信号来检测变化password_delay。但更重要的是我们引入了一个时钟。在数字硬件中,大多数系统使用时钟。最后,我们使用新的VHDL-2008语句case?来解码不关心。

VHDL-2008代码一起成为:

library IEEE;
use IEEE.std_logic_1164.all;

entity doorlock is
    port(
        clk : in std_logic;
        reset : in std_logic;
        enable : in std_logic;
        password : in std_logic_vector (7 downto 0);
        door : out std_logic_vector (7 downto 0);
        lock : out std_logic;
        alarm : out std_logic;
        turnoff : out std_logic
        );
end doorlock;

--password is 10(decimal no.) which is 00010000(binary no.)

architecture DDL of doorlock is
    signal password_delay : std_logic_vector(password'range) := password;
    use ieee.numeric_std_unsigned.all;
    signal err_count : integer range 0 to 5 := 0;
begin
    clk_proc : process(clk) begin
        if rising_edge(clk) then
            if reset = '0' then
                door <= (others => '0');
                lock <= '0';
                alarm <= '0';
                turnoff <= '0';
                err_count <= 0;
            else -- no reset :)
                if password /= password_delay then
                    case? password is
                        when "-------1" => door <= "00000000";
                        when "------10" => door <= "00000001";
                        when "-----100" => door <= "00000011";
                        when "----1000" => door <= "00000111";
                        when "---00000" => door <= "00001111";
                        when "--110000" => door <= "00011111";
                        when "-1010000" => door <= "00111111";
                        when "10010000" => door <= "01111111";
                        when "00010000" => door <= "11111111";
                        when others => null;
                    end case?;
                    err_count <= err_count + 1;
                end if;
                case err_count is
                    when 3 => alarm <= '1';
                    when 5 => turnoff <= '1';
                    when others => null;
                end case;
                if door = "11111111" and turnoff = '0' and alarm = '0' then
                    lock <= '1';
                end if;
            end if;
            password_delay <= password;
        end if;
    end process;
end DDL;

那是不同的东西,是吗?对不起,我没时间为你写一个测试台。

注意:代码提供编译器警告

  

警告:C:/HDL/doorlock/doorlock.vhd(20):( vcom-1013)“password_delay”的初始值取决于信号“password”的值。

忽略这一点。这是模拟所必需的,因为未定义的password_delay初始值将导致password /= password_delay的触发。