VHDL状态机描述
type state is (step1, step2, step3);
signal current_state, next_state : state;
STATE_REG : process(clk) is
begin
if rising_edge(clk) then
if reset = '1' then
current_state <= step1;
else
current_state <= next_state;
end if;
end if;
end process STATE_REG;
NEXT_STATE_REG : process (start) is
begin
case current_state is
when step1 =>
if start = '0' then
next_state <= step1;
else
next_state <= step2;
end if;
when step2 =>
next_state <= step3;
when step3 =>
next_State <= step1;
end case;
end process NEXT_STATE_REG;
对这个例子有一个疑问,为什么进程NEXT_STATE_REG 需要加入start敏感信号量,我记得进程是只有敏感信号量变化才会启动执行的,但事实上,在状态2到状态3的转化,并不需要敏感信号量start变化,这是为什么呢?
start是什么信号?
next_state_rge进程应该为一个组合进程,但敏感表中信号不全。
states step 1 to step 2 need start
NEXT_STATE_REG : process (start) is
begin
case current_state is
when step1 =>
if start = '0' then
next_state <= step1;
else
next_state <= step2;
end if;
when step2 =>
next_state <= step3;
when step3 =>
next_State <= step1;
end case;
end process NEXT_STATE_REG;
状态机切换这个process,你可以理解为一个组合逻辑。因为从step1变化到step2的时候,就是你的第一个when语句,需要根据start的变化来变化。所以,start必须是这个process的敏感信号,不加start的话,在start由0变1的时候,step1不会跳转到step2。
另外,这个敏感信号列表好像少加了一个信号,current_state也必须要加进去。
在你研究的这个程序里面,这种驱动方式是由状态机变量当前的状态,结合其他的状态信号,如start,去驱动状态变量转换到下一状态next_state的。process需要监控所有需要的信号的状态以判断状态机的下一状态,所以,所有驱动状态机转换的信号都必须要加到敏感列表里面。
还有一种写法,用时钟去驱动的,就只需要把时钟和复位加到敏感列表里面,这时候只需要定义一个状态机变量就可以了。你可以多看看别的例子。
