【问题标题】:4 bit U/D counter in VHDLVHDL 中的 4 位 U/D 计数器
【发布时间】:2013-12-16 17:11:26
【问题描述】:

我正在尝试在 VHDL 中编写一个 4 位计数器,该计数器从“0000”计数到“1111”或从“1111”到“0000”,具体取决于我的 UD 变量的值(如果 UD='1' 它应该倒计时,如果它是 ='0' 向上)。当我的计数器到达计数器的一侧(0 或 15)时,还有一个信号 RCO_L 获得 value='0'。最后还有一个 ENP_L 信号,当它设置为 1 时会禁止我的计数器。

我发现很难编写代码,因为我是 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.*

【问题讨论】:

    标签: counter vhdl


    【解决方案1】:

    首先,您的计数变量的类型应该是unsigned 而不是std_logic_vectorIf you want a vector to represent a number, choose the right type.

    其次,只需要一个 clk'event 行。事实上,这些天的习惯用法是改用rising_edge(clk) 函数。您不需要灵敏度列表中的所有这些信号,只需要时钟即可。

    然后将您的所有控制逻辑放入if rising_edge(clk) then

    一旦你修复了所有的语法错误(使用编译器,或获得像Sigasi's 这样的编辑器,然后构建一个测试平台,它将创建时钟和其他输入信号,这样你就可以看到它是否正常工作。额外信用,让测试台实际检查输出是否符合您的要求,而不是自己盯着波形 - 这很快就会变得乏味!

    另外,对未来的建议 - 如果您在这里提出问题,请发布代码

    • 正确缩进(再次,使用 Sigasi,它对于小代码是免费的,并且可以完成这项工作)
    • 没有语法错误。

    草率地提出的问题不太可能影响答案,抱歉!

    【讨论】:

      【解决方案2】:

      其中大部分是语法错误。例如 Q 应该是 std_logic_vector。此外,当您需要在输出中写一些东西时,您可以这样提及: output 而不是 RCO_L='0'; 。信号 contador 属于 std_logic_vector,您不能以这种方式在 std_logic_vector 中增加/减少 1。首先你必须将它们转换为无符号值,刚才提到here

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多