- 4
- 0
- 约3.83千字
- 约 36页
- 2021-10-10 发布于广东
- 举报
第八章 有限状态机设计;教学重点;8.1 有限状态机;摩尔型(Moore)状态机 ;Moore型状态图;module fsm(clk,clr,z,qout);//模5计数器
input clk,clr; output reg z; output reg[2:0] qout;
always @(posedge clk or posedge clr) //此过程定义状态转换
begin if(clr) qout=0; //异步复位
else case(qout)
3b000: qout=3b001;
3b001: qout=3b010;
3b010: qout=3b011;
3b011: qout=3b100;
3b100: qout=3b000;
default: qout=3b000; /*default语句*/
endcase
end
always @(qout) /*此过程产生输出逻辑*/
begin case(qout)
3b100: z=1b1;
default:z=1b0;
endcase
end
endmodule;Mealy型状态图;【例10.7】状态机设计举例
module FSM( clk, clr, out, start, step2, step3 );
input clk, clr, start, step2, step3;
output[2:0] out;
reg[2:0] out;
reg[1:0] state, next_state;
parameter state0 = 2’b00, state1 = 2’b01, // 状态编码
state2 = 2’b11, state3 = 2’b10; // 格雷码
always @( posedge clk or posedge clr )
begin
if( clr ) state = state0; // 定义初态
else state = next_state;
end;always @( state or start or step2 or step3 ) // 状态转换
begin
case (state)
state0:
begin
if( start ) next_state = state1;
else next_state = state0;
end
state1:
begin
next_state = state2;
end; state2:
begin
if( step2 ) next_state = state3;
else next_state = state0; end
state3:
begin
if( step3 ) next_state = state0;
else next_state = state3; end
default: next_state = state0;
endcase
end;always @( state ) // 状态译码及输出
begin
case( state )
state0: out = 3b001;
state1: out = 3b010;
state2: out = 3b100;
state3: out = 3b111;
default: out = 3b001;
endcase
end
endmodule;(1)用三个过程描述:即现态(CS)、次态(NS)、输出逻辑(OL)各用一个always过程描述。
(2)双过程描述(CS+NS、OL双过程描述):使用两个always过程来描述有限状态机,一个过程描述现态和次态时序逻辑(CS+NS);另一个过程描述输出逻辑(OL)???
(3)双过程描述(CS、NS+OL双过程描述):一个过程用来描述现态(CS);另一个过程描述次态和输出逻辑(NS+OL)。
(4)单过程描述:在单过程描述方式中,将状态机的现态、次态和输出逻辑(CS+NS+OL)放在一个always过程中进行描述。;“101”序列检测器的Verilog描述(三个过程) ;“101”序列检测器的Verilog描述(三个过程) ;S2:begin
if(x) next_state=S3;
else next_state=S0; end
S3:begin
原创力文档

文档评论(0)