|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
本人初学状态机,不知道状态机的结构,请各位大虾指教
本人的状态机结构是3段式:
1。时序电路:现代状态的赋值
[email=always@(posedge]always@(posedge[/email] clock or posedge reset)
begin
if(reset)
present_state<=s5;
else
present_state<=next_state;
end
2.组合电路:次态的赋值
[email=always@(reset]always@(reset[/email] or din or present_state)
begin
if(reset)
next_state=s5;
else
begin
case(present_state)
s5:
begin
if(din)
next_state=s0;
else
next_state=s5;
end
s0:
begin
if(!din)
next_state<=s1;
else
next_state<=s0;
end
s1:
begin
if(!din)
next_state=s2;
else
next_state=s0;
end
s2:
begin
if(din)
next_state=s3;
else
next_state=s5;
end
s3:
begin
if(!din)
next_state=s4;
else
next_state=s0;
end
s4:
begin
if(din)
next_state=s0;
else
next_state=s2;
end
default:next_state=s5;
endcase
end
end
3.时序电路
输出变量的赋值
[email=always@(posedge]always@(posedge[/email] reset or posedge clock )
begin
if(reset)
dout<=0;
else if(next_state==s4)
dout<=1;
else
dout<=0;
end
请问标准的3段式结构是这样的么?标准的应该是怎样的?请指教
总源代码如下:序列检测
module seqdet(
clock,
reset,
din,
dout);
input clock,reset,din;
output dout;
reg dout;
reg[5:0] present_state,next_state;
parameter s0=6'b100000,s1=6'b010000,s2=6'b001000;
parameter s3=6'b000100,s4=6'b000010,s5=6'b000000;
[email=always@(posedge]always@(posedge[/email] clock or posedge reset)
begin
if(reset)
present_state<=s5;
else
present_state<=next_state;
end
[email=always@(reset]always@(reset[/email] or din or present_state)
begin
if(reset)
next_state=s5;
else
begin
case(present_state)
s5:
begin
if(din)
next_state=s0;
else
next_state=s5;
end
s0:
begin
if(!din)
next_state<=s1;
else
next_state<=s0;
end
s1:
begin
if(!din)
next_state=s2;
else
next_state=s0;
end
s2:
begin
if(din)
next_state=s3;
else
next_state=s5;
end
s3:
begin
if(!din)
next_state=s4;
else
next_state=s0;
end
s4:
begin
if(din)
next_state=s0;
else
next_state=s2;
end
default:next_state=s5;
endcase
end
end
[email=always@(posedge]always@(posedge[/email] reset or posedge clock )
begin
if(reset)
dout<=0;
else if(next_state==s4)
dout<=1;
else
dout<=0;
end
endmodule |
|