4-Bit Counter: 0000 0001 0010 ... 1110 1111 Rolls Over 0000 0001 ..
4-Bit Counter: 0000 0001 0010 ... 1110 1111 Rolls Over 0000 0001 ..
4-Bit Counter: 0000 0001 0010 ... 1110 1111 Rolls Over 0000 0001 ..
Misc
4-bit counter
The rollover happens when the most significant bit of the final
addition gets discarded. When counter is at a maximum value
of 4'b1111 and gets one more count request, the counter tries
to reach 5'b10000 but since it can support only 4-bits, the
MSB will be discarded resulting in 0.
0000
0001
0010
...
1110
1111
rolls over
0000
0001
...
The design contains two inputs one for the clock and another
for an active-low reset. An active-low reset is one where the
design is reset when the value of the reset pin is 0. There is a
4-bit output called out which essentially provides the counter
values.
(/images/verilog/4-bit_counter_1.png)
9 if (! rstn)
10 out <= 0;
11 else
13 end
14 endmodule
Testbench
(/images/verilog/4-bit_counter_2.png)
1 module tb_counter;
8 .rstn (rstn),
9 .out (out));
10
14
19 rstn <= 0;
20
25
27 #20 $finish;
28 end
29 endmodule
Simulation Log
ncsim> run
(/images/verilog/waves/4-bit-counter-wave.PNG)
(/images/verilog/schematic/4b_counter_schematic.png)