我正在学习VHDL,从昨天开始,我一直在努力处理下面的这个简单示例。
在VHDL中为一个零(0)至九(9)计数器编写一个实体,该实体由一个上升沿时钟触发,并具有一个异步有效高电平“复位为零”输入。系统具有三(3)个输出信号“ LOW”,“ MID”和“ HIGH”,它们产生以下值:
假定所有信号均为Std_logic类型。
代码是这样的
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_arith.all;
USE ieee.std_logic_unsigned.all;
ENTITY LMHcounter IS
PORT(clk,reset:in std_logic;
L:out std_logic;
M:out std_logic;
H:out std_logic);
END LMHcounter;
ARCHITECTURE behavior OF UPcounter IS
SIGNAL count:std_logic_vector(3 downto 0);
BEGIN
PROCESS(clk,reset)
BEGIN
if reset='1' then count<="0000";
elsif (rising_edge(clk))then
if count<="1001" then
count<="0000";
else count<=count+"0001";
end if;
end if;
END PROCESS;
L<='1' when count<="0101";
else '0';
M<='1' when count="0110";
else '0';
H<='1' when count>="0111";
else '0';
END behavior;
如果我最后使用L = '1',我会得到
Error: C:/DL_Project/LMH Counter.vhd(29): near "=": (vcom-1576) expecting == or '+' or '-' or '&'.
如果我在末尾使用L <= '1',
Error: C:/DL_Project/LMH Counter.vhd(29): Illegal target for signal assignment.
Error: C:/DL_Project/LMH Counter.vhd(29): (vcom-1136) Unknown identifier "L".
Error: C:/DL_Project/LMH Counter.vhd(30): near "else": (vcom-1576) expecting END.
我不能使用':=',因为modelim显然不支持
Error: C:/DL_Project/LMH Counter.vhd(29): (vcom-1441) CONDITIONAL VARIABLE ASSIGNMENT is not defined for this version of the language.
** Error: C:/DL_Project/LMH Counter.vhd(30): near "else": (vcom-1576) expecting END.
我确定这是微不足道的,但我似乎找不到任何答案。如果我使用'='或'<=',有人还可以解释一下背景中发生了什么吗?
谢谢
答案 0 :(得分:3)
我发现了很多错误,
ARCHITECTURE behavior OF LMHcounterIS
而不是ARCHITECTURE behavior OF UPcounter IS
signal <= [expression when condition else ...] expression;
。在您的代码中应为L<='1' when count<="0101" else '0'; M<='1' when count="0110" else '0'; H<='1' when count>="0111" else '0';