Level 38: Counter (Verilog)
Task
Build an 8-bit counter that increments by 1 on each clock tick. The counter uses feedback: the Reg8 output is fed back into the Adder8 input.
Module Counter8 takes clk and outputs out[7:0]. Use Reg8 (level 37) and Adder8 (level 35).
Related Materials
- Adder8 — 8-bit adder
Solution
- Declare intermediate wires:
wire [7:0] sum;andwire carry_unused; - Adder adds current
outplus constant8'b00000001:Adder8 adder(sum, carry_unused, out, 8'b00000001); - Register stores the sum:
Reg8 cnt(out, sum);
Adder8 port order: (sum, c_out, a, b, c_in). Leave c_in unconnected (defaults to 0). Constant 8'b00000001 is Verilog notation for the 8-bit value 1.