我试图用VHDL编写一个4位计数器,根据我的UD变量的值从"0000“到"1111”或者从"1111“到"0000”(如果UD='1‘它应该向下计数,如果它是’0‘up)。还有一个信号RCO_L,当我的计数器到达计数器(0或15)的一侧时,它得到值=‘0’。最后,当计数器设置为1时,有一个ENP_L信号会抑制它。
我发现很难编写代码,因为我对VHDL有点陌生,而且我遇到了很多错误。如果有人能帮我,我会很感激的。
这就是我到目前为止所做的:
*entity contador is
Port ( A : in STD_LOGIC_VECTOR(3 downto 0);
CLK : in STD_LOGIC;
LOAD_L : in STD_LOGIC;
UD : in STD_LOGIC;
ENP_L : in STD_LOGIC;
Q : out STD_LOGIC (3 downto 0);
RCO_L : out STD_LOGIC);
end contador;
architecture Behavioral_contador of contador is
signal contador : STD_LOGIC_VECTOR(3 downto 0);
begin
process (CLK,UD,LOAD_L,ENP_L)
begin
if (CLK'event AND LOAD_L='0') then
Q <= A;
elsif (CLK'event AND LOAD_L='1') then
if (UD='0') then
contador <= contador + 1;
elsif (UD='1') then
contador <= contador - 1;
end if;
if (contador="0000" and ENP_L='0') then
RCO_L='0';
if (UD='0') then
contador="0001";
elsif (UD='1') then
contador="1111";
end if;
else
RCO='1';
end if;
end if;
end process;
Q <= contador;
end Behavioral_contador;*如果它有帮助,这就是错误控制台的结果:
*ERROR:HDLCompiler:535 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 40: Index constraint prefix std_logic should be an array type
ERROR:HDLCompiler:854 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 34: Unit <contador> ignored due to previous errors.
ERROR:HDLCompiler:374 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 44: Entity <contador> is not yet compiled.
ERROR:HDLCompiler:69 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 46: <std_logic_vector> is not declared.
ERROR:HDLCompiler:69 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 53: <q> is not declared.
ERROR:HDLCompiler:69 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 56: <contador> is not declared.
ERROR:HDLCompiler:69 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 58: <contador> is not declared.
ERROR:HDLCompiler:69 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 57: <ud> is not declared.
ERROR:HDLCompiler:69 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 55: <ud> is not declared.
ERROR:HDLCompiler:806 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 61: Syntax error near "=".
ERROR:HDLCompiler:806 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 63: Syntax error near "=".
ERROR:HDLCompiler:837 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 63: Type void does not match with a string literal
ERROR:HDLCompiler:806 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 65: Syntax error near "=".
ERROR:HDLCompiler:837 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 65: Type void does not match with a string literal
ERROR:HDLCompiler:69 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 64: <ud> is not declared.
ERROR:HDLCompiler:69 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 62: <ud> is not declared.
ERROR:HDLCompiler:806 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 68: Syntax error near "=".
ERROR:HDLCompiler:69 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 60: <contador> is not declared.
ERROR:HDLCompiler:69 - "/home/edig/Escritorio/vhdl/contador.vhd" Line 54: <clk> is not declared.*发布于 2013-12-16 21:14:03
首先,计数变量应该是unsigned类型,而不是std_logic_vector类型。如果要用向量表示数字,请选择正确的类型。。
第二,只有一个clk'event行。事实上,现在的成语是用rising_edge(clk)函数代替。你不需要你的敏感列表中的所有信号,只需要时钟。
然后将所有控制逻辑都包含在if rising_edge(clk) then中。
一旦您修复了所有语法错误(使用编译器,或者获得像西加西氏这样的编辑器,那么就构建一个testbench,它将创建时钟和其他输入信号,这样您就可以看到它是否工作了。额外的功劳,让测试台实际上检查输出做你想做的,而不是盯着你自己的波形--这很快就会变得乏味!
还有,对未来的建议--如果你在这里问问题,请贴上代码
漫不经心地问问题不太可能得到太多的答案,对不起!
发布于 2013-12-16 19:26:49
其中大部分是语法错误。例如,std_logic_vector.应该是Q另外,当您需要在输出时写一些东西时,您会提到如下:output <= input而不是RCO_L='0';。Signal contador是std_logic_vector,不能以这种方式增加/减少std_logic_vector中的1。首先,您必须将它们转换为无符号值,刚才提到的是这里
https://stackoverflow.com/questions/20616597
复制相似问题