【问题标题】:if statement inside counter in VHDLVHDL中的计数器内的if语句
【发布时间】:2023-03-09 06:24:01
【问题描述】:

我有一个从“000”向上计数的 3 位计数器。每次达到“101”时,我都希望 o_en 信号为高电平。
我有以下 VHDL 文件。
不幸的是,行为不同。
o_en 信号为 HIGH,当达到“110”时(延迟一个时钟周期)。

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity special_counter is
    port(
        i_clk : in std_logic;
        i_en : in std_logic;
        i_rst : in std_logic;
        o_data : out std_logic_vector(2 downto 0);
        o_en : out std_logic
    );
end entity;

architecture behave of special_counter is
signal w_data : std_logic_vector(2 downto 0);
signal w_en : std_logic;

begin
    process(i_clk, i_rst) begin
        if i_rst = '1' then
            w_data <= "000";
        elsif rising_edge(i_clk) then
            if i_en = '1' then
                if w_data = "101" then
                    w_en <= '1';
                    w_data <= w_data + 1;
                else
                    w_en <= '0';
                    w_data <= w_data + 1;
                end if;
            end if;
        end if;
    end process;
    o_data <= w_data;
    o_en <= w_en;
end architecture;

如何更改我的程序以执行预期的行为?

【问题讨论】:

    标签: if-statement vhdl counter


    【解决方案1】:

    这完全正确,这就是您编写的代码。

    用一句话来形容: “在时钟的上升沿,当计数器的值为 101 时,w_en 将被设置为高电平。”

    因此,派生o_enw_en 信号将在时钟上升沿之后为高电平。
    w_data 更改和之后 上升时钟变为“110”的同时。

    有两种解决方案:

    1. 测试“100”(因此提前一个周期)

    2. 使 w_en(因此 o_en)组合。

    对于后者,您必须将作业移到“时钟”部分之外 并使用例如

    w_en

    【讨论】:

      猜你喜欢
      • 2016-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多