Binary Counter using verilog |
A binary counter is a simple counter that has an initial value of 0 at the time of reset. It value keeps incrementing by 1 at each clock cycle. And finally it reaches its maximum value, say 1111 in binary for a 4 bit counter, it again reaches 0000 in binary and keeps counting one.
Here is the verilog implemmentation of shift register.
|
Explanation |
We make use of the simple addition statement for incrementing value. We should note the property of addition that - it wraps when it reaches its max value.
assign r_next = r_reg+1;; |
The testbech for the binary counter
|
Exercise
1. Change the binary counter so that it counts down in place of count up
- Answer here
2. Modify the code so that, it gives output 1 ( define another output wire), for one clock period every time it reaches max value.
Answer here
and test bench here
2. Modify the code so that, it has another input, call it load. When it is 1, at the next rising edge of clock, the counter value is uploaded with N bit wide input - call it input_load. It then keeps counting from there.