-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoddeven.v
More file actions
89 lines (77 loc) · 1.57 KB
/
oddeven.v
File metadata and controls
89 lines (77 loc) · 1.57 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
`timescale 1ns/10ps
module oddeven(z,y,clk,rst);
input y,clk,rst;
output reg z;
reg [1:0]currentstate,nextstate;
parameter idle= 2'b00, st1= 2'b01, st2= 2'b11, st3= 2'b10;
always @(posedge clk or negedge rst)
begin
if(!rst) currentstate <= idle;
else currentstate <= nextstate;
end
always @(*)
begin
case(currentstate)
2'b00: begin
if(y) nextstate <= st2;
else nextstate <= st1;
end
2'b01: begin
if(y) nextstate <= st2;
else nextstate <= idle;
end
2'b11: begin
if(y) nextstate <= st3;
else nextstate <= st1;
end
2'b10: begin
if(y) nextstate <= st2;
else nextstate <= st1;
end
default: nextstate <= idle;
endcase
end
always @(*)
begin
case(currentstate)
2'b00: begin if(y) z <= 1'b0 ;
else z <= 1'b0;
end
2'b01: begin if(y) z<= 1'b1 ;
else z <= 1'b0 ;
end
2'b11: begin if(y) z <= 1'b0 ;
else z <= 1'b0 ;
end
2'b10: begin if(y) z <= 1'b0;
else z <= 1'b1;
end
default: z <=1'b0;
endcase
end
endmodule
module tb_oddeven();
wire z;
reg y,clk,rst;
oddeven uut(z,y,clk,rst);
initial $monitor("t=%3d, z=%b, y=%b, clk=%b, rst=%b",$time,z,y,clk,rst);
initial
begin
$dumpfile("oddeven.vcd");
$dumpvars;
end
initial
begin #00 clk <= 1'b0 ;
forever #50 clk <= ~ clk ;
end
initial forever #100 y = $random %2 ;
initial
begin #0000 rst = 1'b1;
#0050 rst = 1'b0;
#0050 rst = 1'b1;
#2000 rst = 1'b0;
#0050 rst = 1'b1;
end
initial
#4000 $stop ;
endmodule