VHDL信号不改变值
我目前正在尝试实现一个具有5种不同状态的状态机。基本上,我想停留在一个状态,等待一段时间,进入下一个状态,等待不同的时间,进入下一个状态等等 现在我实现了一个计数器,它从我在测试台上创建的1ms信号生成1s信号。我创建了一个进程来确定下一个状态,并从下一个状态升级当前状态。与我预期不符的信号是:next_stateHS应该升级stateHS。正在讨论的代码正在被称为“hsNextState”的过程中。我也无法解释的是信号“startCounter”的行为与预期一致。该信号接收一个与信号“next_StateHS”相同的else情况下的新值 现在,我将添加状态机和测试台的代码以及模拟波形的图片。 状态机:VHDL信号不改变值,vhdl,state-machine,Vhdl,State Machine,我目前正在尝试实现一个具有5种不同状态的状态机。基本上,我想停留在一个状态,等待一段时间,进入下一个状态,等待不同的时间,进入下一个状态等等 现在我实现了一个计数器,它从我在测试台上创建的1ms信号生成1s信号。我创建了一个进程来确定下一个状态,并从下一个状态升级当前状态。与我预期不符的信号是:next_stateHS应该升级stateHS。正在讨论的代码正在被称为“hsNextState”的过程中。我也无法解释的是信号“startCounter”的行为与预期一致。该信号接收一个与信号“next
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.ALL;
entity ampel is
port
(
clk : in std_ulogic;
reset : in std_ulogic;
enable : in std_ulogic;
haupt : out std_ulogic_vector(2 downto 0);
neben : out std_ulogic_vector(2 downto 0)
);
end ampel;
architecture ampel_behave of ampel is
--Codierung
-- idle = 000
-- gruen = 001
-- gelb = 010
-- rot = 011
-- rot_gelb = 100
signal stateHS, stateNS : std_ulogic_vector(2 downto 0) := (others => '0');
signal next_stateHS, next_stateNS : std_ulogic_vector(2 downto 0) := (others => '0');
signal startCounter : std_ulogic := '0';
signal counter : unsigned(9 downto 0) := (others => '0'); --für clk = 1ms im Testbench
signal count_seconds : unsigned(3 downto 0) := (others => '0');
begin
counterProcess : process(clk, reset, enable, startCounter)
begin
if enable = '0' or reset = '1' or startCounter = '0' then
counter <= (others => '0');
count_seconds <= (others => '0');
elsif rising_edge(clk) then
if counter < "1111101000" then
counter <= counter + 1;
else
counter <= (others => '0');
count_seconds <= count_seconds + 1;
end if;
end if;
end process counterProcess;
outputProcessHS : process(stateHS, reset, enable)
begin
if enable = '0' or reset = '1' then
haupt <= "000";
else
case (stateHS) is
when "000" =>
haupt <= "000";
when "001" =>
haupt <= "001";
when "010" =>
haupt <= "010";
when "011" =>
haupt <= "011";
when "100" =>
haupt <= "100";
when others =>
haupt <= "000";
end case;
end if;
end process outputProcessHS;
outputProcessNS : process(stateNS, reset, enable)
begin
if enable = '0' or reset = '1' then
neben <= "000";
else
case (stateNS) is
when "000" =>
neben <= "000";
when "001" =>
neben <= "001";
when "010" =>
neben <= "010";
when "011" =>
neben <= "011";
when "100" =>
neben <= "100";
when others =>
neben <= "000";
end case;
end if;
end process outputProcessNS;
hsNextState : process(reset, enable, stateHS, count_seconds)
begin
if enable = '0' or reset = '1' then
next_stateHS <= "000";
else
case (stateHS) is
when "000" =>
next_stateHS <= "001";
startCounter <= '1';
when "001" =>
if count_seconds < "1110" then
next_stateHS <= "001";
else
next_stateHS <= "010";
startCounter <= '0';
end if;
when "010" =>
next_stateHS <= "011";
when "011" =>
next_stateHS <= "100";
when "100" =>
next_stateHS <= "001";
when others =>
next_stateHS <= "000";
end case;
end if;
end process hsNextState;
hsState : process(reset, enable, next_stateHS, count_seconds)
begin
if enable = '0' or reset = '1' then
stateHS <= "000";
else
stateHS <= next_stateHS;
end if;
end process hsState;
-- nsStateProcess : process(reset, enable, stateNS, count_seconds)
-- begin
-- if enable = '0' or reset = '1' then
-- next_stateNS <= idle;
-- else
-- case (stateNS) is
-- when idle =>
-- next_stateNS <= gruen;
-- when gruen =>
-- next_stateNS <= gelb;
-- when gelb =>
-- next_stateNS <= rot;
-- when rot =>
-- next_stateNS <= rot_gelb;
-- when rot_gelb =>
-- next_stateNS <= gruen;
-- when others =>
-- next_stateNS <= idle;
-- end case;
-- end if;
-- stateNS <= next_stateNS;
-- end process nsStateProcess;
end ampel_behave;
IEEE库;
使用IEEE.STD_LOGIC_1164.ALL;
使用IEEE.numeric_std.ALL;
实体安瓿是
港口
(
时钟:标准逻辑;
重置:在标准逻辑中;
启用:在标准逻辑中;
haupt:out标准逻辑向量(2到0);
内本:输出标准逻辑向量(2到0)
);
末端安瓿;
建筑ampel_ampel的行为是
--科迪隆
--空闲=000
--gruen=001
--gelb=010
--rot=011
--rot_gelb=100
信号状态,状态:标准逻辑向量(2到0):=(其他=>'0');
信号下一个状态,下一个状态:标准逻辑向量(2到0):=(其他=>'0');
信号启动计数器:标准逻辑:='0';
信号计数器:无符号(9到0):=(其他=>“0”)--für clk=1ms im试验台
信号计数秒数:无符号(3到0):=(其他=>“0”);
开始
反进程:进程(时钟、复位、启用、启动计数器)
开始
如果enable='0'或reset='1'或startCounter='0',则
计数器“0”);
计数秒“0”);
elsif上升沿(clk)则
如果计数器<“11111 01000”,则
计数器不符合我预期的信号是:next_states,它应该升级states。
进程hsNextState
和进程hsState
都是组合的(不计时),并形成一个异步状态机。这就是你的想法吗?@user1155120谢谢你的回复。我仍然不明白,为什么“next_stateHS”永远不会变成“010”。@rtx13我认为只让计数器在时钟上可靠就足够了,因为改变状态的过程取决于计数器,因此间接地取决于时钟本身。@Alex在同步状态机中(如果这是你想要的),状态
是一个注册信号,换句话说,它是一个明确的时钟分配。如前所述,您有一个主要由同步输入驱动的异步状态机。行为不符合我预期的信号是:下一个状态应该升级状态。
进程hsNextState
和进程hsState
都是组合的(没有时钟),并形成一个异步状态机。这就是你的想法吗?@user1155120谢谢你的回复。我仍然不明白,为什么“next_stateHS”永远不会变成“010”。@rtx13我认为只让计数器在时钟上可靠就足够了,因为改变状态的过程取决于计数器,因此间接地取决于时钟本身。@Alex在同步状态机中(如果这是你想要的),状态
是一个注册信号,换句话说,它是一个明确的时钟分配。如前所述,您有一个主要由同步输入驱动的异步状态机。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.ALL;
entity ampel_tb is
end ampel_tb;
architecture test of ampel_tb is
component ampel
port
(
clk : in std_ulogic;
reset : in std_ulogic;
enable : in std_ulogic;
haupt : out std_ulogic_vector(2 downto 0);
neben : out std_ulogic_vector(2 downto 0)
);
end component;
signal clk : std_ulogic := '0';
signal reset : std_ulogic := '0';
signal enable : std_ulogic := '1';
signal haupt, neben : std_ulogic_vector(2 downto 0);
signal count_cycles : unsigned (19 downto 0) := (others => '0');
begin
ampel_1 : ampel port map
(
clk => clk,
reset => reset,
enable => enable,
haupt => haupt,
neben => neben
);
clock_signal : process
begin
if count_cycles < "0011100000000000000" then
clk <= '0';
wait for 500 us;
clk <= '1';
wait for 500 us;
count_cycles <= count_cycles + 1;
else
wait;
end if;
end process clock_signal;
end test;