【问题标题】:vhdl-fsm with timer- clock cycle delay具有定时器时钟周期延迟的 vhdl-fsm
【发布时间】:2014-01-11 19:15:27
【问题描述】:

我必须在 vhdl 中编写一个带有计时器的 FSM。

我认为,您无需厌倦了解我的电路将做什么。

我只是想帮助我解决这个问题: 每次从一种状态到另一种状态的变化,都会有一个(或多个)时钟周期延迟。 问题是,我怎样才能避免呢?

我的 vhdl 代码:

library IEEE;
   use IEEE.STD_LOGIC_1164.ALL;
   use IEEE.STD_LOGIC_unsigned.ALL;

entity fsm_timers is
port( x: in bit; 
      clk, rst: in std_logic;
        y: out bit);
end fsm_timers;

architecture Behavioral of fsm_timers is
constant T1: std_logic_vector(7 downto 0) :="00000011";                                                       
constant T2: std_logic_vector(7 downto 0) :="00000111";               
signal t: std_logic_vector(7 downto 0) := (others=>'0');
signal rst_cnt: std_logic :='0';

Type state is (A,B,C);
signal pr_state, nx_state : state := A;

component counter is
 port(reset,clock, inner_rst:in std_logic;
      cnt:out std_logic_vector(7 downto 0));
 end component;
begin
U_sum_counter: counter port map(
        reset => rst,
        inner_rst => rst_cnt,
        clock => clk,
        cnt => t);

process(clk,rst)
begin
    if (rst='1') then
        pr_state<= A;
    elsif (rising_edge(clk)) then
       pr_state<=nx_state;
    end if;

end process;

process(x,t,pr_state)
begin
    case pr_state is
        when A =>
            y<='0';
            rst_cnt<='1';
            if (x='1') then             
                nx_state<= B;
            else 
                nx_state<= A;
            end if;
        when B =>
            y<='0';
          rst_cnt<='0';
            if (x='0' and t=(T1-1)) then
                nx_state<= C;
            end if;
            if ((x='0' and t<(T1-1)) or (x/='0' and t<(T2-1))) then
                nx_state<= B;                   
            end if;
            if (t=(T2-1)) then
                nx_state<= A;
            end if;
        when C =>
            y<='1';
          rst_cnt<='0';
            if (t=(T2-1)) then
                nx_state<= A;
            else
                nx_state<= C;
            end if;
    end case;
end process;
end Behavioral;

提前谢谢你

【问题讨论】:

    标签: delay vhdl cycle clock fsm


    【解决方案1】:

    我认为您至少无法避免一个时钟延迟。原因是你必须记住你当前的状态。为了保存状态,您必须使用寄存器,这将导致延迟。否则,您可以通过使用异步状态机来避免这种情况,但是您必须小心输入。

    通常的摩尔状态机有:

               \/-------------|
    

    输入 --> 转换逻辑 --> 状态存储器 --> 输出逻辑 --> 输出

                        ^-clk ^-rst ^-enable
    

    这个结构可以用 3 个进程很好地表达。为了尝试减少延迟,您可以将输出逻辑直接连接到转换逻辑,但无论如何您可能需要一个寄存器。

    详情见this page i googled,很详细。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-17
      • 1970-01-01
      • 2012-11-19
      • 2016-07-09
      • 2017-02-23
      • 1970-01-01
      相关资源
      最近更新 更多