?? seqdet.v
字號(hào):
/* File: seqdet.v
序列監(jiān)測器——X為輸入碼流,從中檢測出指定序列“10010”(對(duì)應(yīng)狀態(tài)A、B、C、D、E),
Z輸出為1。考慮到序列重疊的可能,還有狀態(tài)F,G。
*/
module seqdet (x, z, clk, rst);
input x, clk, rst;
output z;
reg [2:0] state;
wire z;
parameter IDLE = 'd0, A = 'd1, B = 'd2, C = 'd3, D = 'd4,
E = 'd5, F = 'd6, G = 'd7;
assign z = (state == D && x == 0) ? 1 : 0;
always @ (posedge clk or negedge rst)
if (!rst)
begin
state <= IDLE;
end
else
casex (state)
IDLE: if (x == 1)
begin
state <= A;
end
A: if (x == 0)
begin
state <= B;
end
B: if (x == 0)
begin
state <= C;
end
else
begin
state <= F;
end
C: if (x == 1)
begin
state <= D;
end
else
begin
state <= G;
end
D: if (x == 0)
begin
state <= E;
end
else
begin
state <= A;
end
E: if (x == 0)
begin
state <= C;
end
else
begin
state <= A;
end
F: if (x == 1)
begin
state <= A;
end
else
begin
state <= B;
end
G: if (x == 1)
begin
state <= F;
end
default: state <= IDLE;
endcase
endmodule
//以下為測試代碼
`timescale 1ns/1ns
module test_of_seqdet;
reg clk, rst;
reg [23:0] data;
wire z, x;
assign x = data[23];
initial
begin
clk <= 0;
rst <= 1;
#2 rst <= 0;
#30 rst <= 1;
data = 'b1100_1001_0000_1001_0100;
end
always #10 clk = ~clk;
always @ (negedge clk)
data = {data[22:0], data[23]};
seqdet m (.x(x), .z(z), .clk(clk), .rst(rst));
//Enter fixture code here
endmodule
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -