|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
利用状态机编写时序电路设计,用于检测10010序列,Verilog程序如下:
module seqdet(x,clk,rst,z,state);
input clk,x,rst;
output z,state;
reg [2:0] state;
parameter IDLE='d0,A='d1,B='d2,
C='d3,D='d4,E='d5;
always @(posedge clk)
if(!rst)
state<=IDLE;
else
case(state)
IDLE
: if(x)
state<=A;
else
state<=IDLE;
A
:
if(!x)
state<=B;
else
state<=A;
B
:
if(!x)
state<=C;
else
state<=B;
C
:if(x)
state<=D;
else
state<=IDLE;
D
:if(!x)
state<=E;
else
state<=A;
E
:if(x)
state<=A;
else
state<=C;
default
:
state<=IDLE;
endcase
assign z=(state==D&&x==0)?1:0;
endmodule
但是仿真时输入数据、输出z都满足时序,但是状态state的变化总是落后输入数据x一个周期。
仿真testbech程序如下:
`timescale 1ns/1ns
module seqdet_tb();
reg clk,rst;
reg [23:0] data;
wire z,x;
wire [2:0] state;
assign x=data[23];
always #10 clk=~clk;
always @(posedge clk)
data={data[22:0],data[23]};
initial
begin
clk=0;
rst=1;
#2 rst=0;
#30 rst=1;
data='b1100_1011_0000_1001_0100;
#500 $stop;
end
seqdet m(.x(x),.clk(clk),.rst(rst),.z(z),.state(state));
endmodule |
|