-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseq_det1.v
More file actions
93 lines (85 loc) · 1.82 KB
/
seq_det1.v
File metadata and controls
93 lines (85 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
//
// Engineer: Ghada
//
// Create Date: 07/01/2025 01:29:29 AM
// Design Name: Seq Detector
// Module Name: seq_det1
// Project Name: fsm-sequence-detector
// Revisions:
// Revision 0.01 - File Created
//
//////////////////////////////////////////////////////////////////////////////////
//1101
module seq_det1(
input in,
input rst,
input clk,
output reg out
);
parameter S0=3'd0, S1=3'd1, S2=3'd2, S3=3'd3;
reg [1:0] cs, ns;
always @ (posedge clk or posedge rst)begin
//current state logic
if(rst)
cs<=S0;
else
cs<=ns;
end
//ns & out logic
always @(*)
begin
out<=0;
case(cs)
S0: if (in)
ns<=S1;
else
ns<=S0;
S1: if (in)
ns<=S2;
else
ns<=S1;
S2: if (!in)
ns<=S3;
else
ns<=S2;
S3: if (in)begin
ns<=S0;
out<=1;
end
else begin
ns<=S3;
out<=0;
end
endcase
end
endmodule
module seq_det_tb;
reg rst,in,clk;
wire out;
seq_det1 uut (
.in(in),
.rst(rst),
.clk(clk),
.out(out)
);
always #5 clk=~clk;
initial begin
clk=0 ;rst = 1; in = 0;
#10;
rst = 0;
// Apply serial bits: sequence = 1 1 0 1
in = 1; #10;
in = 1; #10;
in = 0; #10;
in = 1; #10;// At this point, output should go high
// Another sequence (with overlap)
in = 1; #10;
in = 0; #10;
in = 1; #10;
in = 1; #10;
in = 0; #10;
in = 1; #10;
end
endmodule