Counters
Parameterized N-Bit Counter with Enable and Wrap — L1 Upgrade — L2 Upgrade
Parameterized N-Bit Counter with Enable, Wrap, Load, Match IRQ
About this block
Simulate it in the Verilog IDE
Parameterized N-Bit Counter with Enable and Wrap — L1 Upgrade — L2 Upgrade is a Verilog reference block in the Counters catalog. Up/down, modulo, and loadable binary counters with enable logic. Marked Easy: a small block you can read, simulate, and synthesize in one sitting.
This IP implements a parameterized N-bit counter with enable, wrap, load, match, and IRQ capabilities.
The design is fully synthesizable Verilog-2001 code with no latch-free dependencies.
It supports asynchronous reset and synchronous load operations.
- Choose Open in IDE. RTL Studio loads the packaged workspace for Parameterized N-Bit Counter with Enable and Wrap — L1 Upgrade — L2 Upgrade.
- Read the Verilog module in the editor. The catalog line for this block: Parameterized N-Bit Counter with Enable, Wrap, Load, Match IRQ.
- Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
- Run Yosys in the same IDE for a generic netlist. Sky130 liberty mapping is a separate Pro library option.
RTL Studio is the Verilog simulator and IDE around this block: Slang lint, Verilator, VCD waveforms, and Yosys, in the browser. Simulation guide · Yosys guide.
Features
- Configurable bit-width: Default 8-bit, easily parameterized.
- Synchronous Enable: Counting occurs only when
enis high. - Synchronous Load: Load
load_valueinto the counter whenloadis high. - Automatic Wrap-Around: Counter resets to zero upon reaching maximum value.
- Match Detection: Configurable match value for event detection.
- Interrupt Request (IRQ): Asserted when
count == match_valueandmatch_enis high. - Asynchronous Reset: Active-low
rst_nresets counter and IRQ to zero.
Ports
| Port Name | Direction | Width | Description |
|---|---|---|---|
clk | Input | 1 | Clock input |
rst_n | Input | 1 | Asynchronous active-low reset |
en | Input | 1 | Count enable |
load | Input | 1 | Load control |
match_en | Input | 1 | Match enable |
load_value | Input | [N-1:0] | Value to load into counter |
match_value | Input | [N-1:0] | Value to match against |
count | Output | [N-1:0] | Current counter value |
irq | Output | 1 | Interrupt request signal |
*Note: N is the parameterized bit-width (default 8).*
Verification
The testbench verifies:
- Reset behavior (count and IRQ go to zero).
- Counting up when
enis high. - Loading
load_valuewhenloadis high. - IRQ assertion when
count == match_valueandmatch_enis high. - Wrap-around from max value to zero.
- IRQ deassertion when match condition is no longer met.
### Running Simulation
- Ensure Icarus Verilog is installed.
- Run the simulation script or command:
- Check the Log panel for the following expected results:
- TC1 PASS reset count - TC1 PASS reset irq - TC2 PASS count up - TC3 PASS load value - TC4 PASS irq asserted at match - TC5 PASS wrap - TC6 PASS irq deasserted - Simulation ends with INFO: PASS.
More in Counters
- 16-Bit Cycle Counter with Prescaler — L1 Upgrade — L2 Upgrade
- 4-Bit Counter Match Pulse
- 4-Bit Counter with Wrap Strobe
- 4-Bit Down Counter
- 4-Digit BCD Up/Down Counter with Carry/Borrow
- 8-Bit Binary Up Counter — L1 Upgrade — L2 Upgrade
- 8-Bit Johnson Counter (Twisted Ring) — L1 Upgrade — L2 Upgrade
- 8-Bit Leading Zero Counter — L1 Upgrade — L2 Upgrade
- 8-Bit Ring Counter
- 8-Bit Up/Down Counter
- Bidirectional Counter 4-Bit — L1 Upgrade — L2 Upgrade
- Decade BCD Counter 1-Digit — L1 Upgrade
- Dual Compare-Match Counter 8 — L1 Upgrade — L2 Upgrade
- Event Counter with Capture
- Gray-Code Counter 8-Bit — L2 Upgrade
- Loadable 4-Bit Up Counter