【问题标题】:state transition falling edge状态转换下降沿
【发布时间】:2013-05-23 16:24:02
【问题描述】:

多年后我正在重新审视 VHDL。我正在尝试在某个溢出期间设置一个带有计数器触发器的基本状态机。

由于某种原因,我在 m_tick 时钟的下降沿得到状态转换。基于状态过程中的 m_tick

我正在 isim 中进行测试。我确信我可能在做一些不太聪明的事情。

谢谢。

entity nes_ctl is
generic(
        N: integer :=  3;       --17 bit overflow 131k
 );
port(
        clk : in std_logic;
        n_reset : in std_logic
);
end nes_ctl;

architecture Behavioral of nes_ctl is

signal count_reg, count_next: unsigned(N-1 downto 0);   --counter to produce tick
signal m_tick: std_logic;
--state variable
type state_type is (s0,s1,s2,s3,s4,s5);
signal state_reg, state_next: state_type;
signal reset: std_logic;    --inverted reset signal

begin

reset <= not(n_reset);  --invert the reset signal

--syncronos logic
process(clk)
begin
    if(reset= '1') then
        count_reg <= (others=>'0');
        state_reg <= s0;
    elsif (clk'event and clk = '1') then
        count_reg <= count_next;
        state_reg <= state_next;
    end if;
end process;

count_next <= count_reg +1;     --increment counter, will overflow
m_tick <= '1' when count_reg = 0 else '0';      -- tick on every overflow

--STATE MACHINE
process(m_tick)
begin
    if(m_tick <= '1') then  --only when m_tick goes high
        case state_reg is
            when s0 =>
                state_next <= s1;
            when s1 =>
                state_next <= s2;
            when s2 =>
                state_next <= s3;
            when s3 =>
                state_next<= s4;
            when s4 =>
                state_next<= s5;
            when s5 =>
                state_next <= s0;
        end case;   
    else 
        state_next <= state_reg; --keep same state.  no       latches.
    end if;
end process;


end Behavioral;

【问题讨论】:

  • 关系运算符&lt;= 在std_logic 上做了什么?如果您想检测上升沿,if rising_edge(m_tick) 将是显而易见的方法
  • 好点。应该是 if (m_tick = '1')。
  • 我的逻辑是m_tick触发了进程,所以m_tick有优势。 if(m_tick = '1') 是检查它是否是上升沿。这种支票的实际标准是什么?像你建议的那样上升边缘(m_tick)?
  • 我将原始代码更改为 m_tick='1' 而不是 m_tick

标签: vhdl state-machine


【解决方案1】:

m_tick

process(clk)
begin
    if (clk'event and clk = '1') then
        m_tick_q <= m_tick;

        -- only when m_tick goes high
        if m_tick='1' and m_tick_q='0' then
            case state_reg is
            ...

【讨论】:

  • " m_tick
  • 实际上,由于 m_tick 大概可以是 0 或 1,因此您的 m_tick
  • 太棒了。感谢您提供有用的反馈!
猜你喜欢
  • 2021-06-19
  • 2018-02-20
  • 2016-11-15
  • 1970-01-01
  • 2014-01-08
  • 2018-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多