我必须用 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;
提前谢谢
最佳答案
我认为你至少无法避免一个时钟延迟。原因是你必须记住你当前的状态。为了保存状态,您必须使用寄存器,这会导致延迟。否则,您可以通过使用异步状态机来避免这种情况,但是您必须小心您的输入。
通常的摩尔状态机具有:
\/-------------|
输入 --> 转换逻辑 --> 状态存储器 --> 输出逻辑 --> 输出
^-clk ^-rst ^-enable
这个结构可以用3个过程很好地表达。为了减少延迟,您可以将输出逻辑直接连接到转换逻辑,但无论如何您可能需要一个寄存器。
详情参见 this page i googled ,很详细。
关于delay - 带定时器时钟周期延迟的 vhdl-fsm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21066709/