Level 38: Step by Step
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
Without the register this loop would be a combinational cycle: signals would race around forever (a signal storm; in real hardware the circuit overheats and burns out). Reg8 is a dam: it cuts the loop and makes time discrete. The value updates strictly on the clock edge — exactly once per tick, not continuously.
- 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.