一、分类
Mealy状态机:输出与输入有关;
Moore状态机:输出与输入无关。
二、状态机设计四段论
1、状态空间定义
parameter SLEEP = 4'b1000; //独热码
parameter STUDY = 4'b0100;
parameter EAT = 4'b0010;
parameter AMUSE = 4'b0001;
reg [3:0] current_state;
reg [3:0] next_state;
2、状态跳转
为时序逻辑,使用非阻塞赋值,敏感列表包括时钟信号以及复位信号边沿的组合。
always @(posedge clk or negedge rst_n) begin
if(!rst_n)
current_state <= SLEEP;
else
current_state <= next_state;
end
3、下一个状态判断
为组合逻辑,使用阻塞赋值,敏感信号表包括所有的影响状态改变的量。
if和else要配对,避免latch产生;case和default配对。
always @(current_state or input signals) begin
case (current_state)
SLEEP: begin
if(clock_alarm)
next_state = STUDY;
else
next_state = SLEEP;
end
STUDY: begin
if(lunch_time)
next_state = EAT;
else
next_state = STUDY;
end
EAT: ...;
AMUSE:...;
default:...;
endcase
end
4、各个状态下的动作
使用阻塞赋值。
always @(current_state)begin
if(current_state == STUDY)
read_book = 1;
else
read_book = 0;
end