|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
本帖最后由 KevinIC 于 2011-6-1 17:33 编辑
“10010”序列检测器的状态是7个还是5个?
——这是夏宇闻《Verilog数字系统设计教程》(第二版)上的一个例题,在书中一共用了7个状态(IDLE,A,B,C,D,E,F,G)。而我自己在设计的时候只用了5个状态(没有原书中的F和G),通过仿真,结果依然正确,我想这本来是一个很简单的设计,书中这样写或许又他的道理,但是自己始终没有看出来,希望大家懂的,给小弟解释一下!这里附上原书中的代码和自己的代码。
--------------原书代码--------------------
module test(clock,reset,signalin,signalout);
input clock,signalin,reset;
output signalout;
reg [2:0] state;
parameter
idle = 3'd0,
a = 3'd1,
b = 3'd2,
c = 3'd3,
d = 3'd4,
e = 3'd5,
f = 3'd6,
g = 3'd7;
assign signalout = (state == e && signalin == 0)?1:0;
always@(posedge clock)
if(!reset)
begin
state <= idle;
end
else
begin
casex(state)
idle:
begin
if(signalin == 1)
state <= a;
else
state <= idle;
end
a:
begin
if(signalin == 0)
state <= b;
else
state <= a;
end
b:
begin
if(signalin == 0)
state <= c;
else
state <= f;
end
c:
begin
if(signalin == 1)
state <= d;
else
state <= g;
end
d:
begin
if(signalin == 0)
state <= e;
else
state <= a;
end
e:
begin
if(signalin == 0)
state <= c;
else
state <= a;
end
f:
begin
if(signalin == 1)
state <= a;
else
state <= b;
end
g:
begin
if(signalin == 1)
state <= a;
else
state <= f;
end
default:
state <= idle;
endcase
end
endmodule
------------------------自己的代码--------------------------------------------
module seqdet (
rst_n, clk,
seq, det
);
input clk, rst_n;
input seq;
output det;
reg det;
reg [2:0] cstate, nstate;
parameter IDLE = 3'd0,
A_1 = 3'd1,
B_10 = 3'd2,
C_100 = 3'd3,
D_1001 = 3'd4,
E_10010 = 3'd5;
always @ (posedge clk or negedge rst_n)
if (!rst_n)
cstate <= IDLE;
else
cstate <= nstate;
always @ (seq or cstate)
case (cstate)
IDLE : if (seq == 1) nstate <= A_1;
else nstate <= IDLE;
A_1: if (seq == 0) nstate <= B_10;
else nstate <= A_1;
B_10: if (seq == 0) nstate <= C_100;
else nstate <= A_1;
C_100: if (seq == 1) nstate <= D_1001;
else nstate <= IDLE;
D_1001: if (seq == 0) nstate <= E_10010;
else nstate <= A_1;
E_10010: if (seq == 0) nstate <= C_100;
else nstate <= A_1;
default: nstate <= IDLE;
endcase
always @ (cstate)
if (cstate == E_10010) det <= 1;
else det <= 0;
endmodule
-------------------------------完----------------------- |
|