Counters
Bidirectional Counter 4-Bit — L1 Upgrade — L2 Upgrade
Bidirectional Counter 4-Bit with load enable and match interrupt generation.
About this block
Simulate it in the Verilog IDE
Bidirectional Counter 4-Bit — L1 Upgrade — L2 Upgrade is a Verilog reference block in the Counters catalog. Up/down, modulo, and loadable binary counters with enable logic. Marked Medium: more state or a wider datapath, still one workspace in the IDE.
This IP core implements a 4-bit bidirectional counter with synchronous load, direction control, and a match-based interrupt generation feature. It is designed for applications requiring precise counting, event detection, and interrupt-driven control logic.
The design is fully verified with Icarus Verilog and ready for integration into larger systems.
- Choose Open in IDE. RTL Studio loads the packaged workspace for Bidirectional Counter 4-Bit — L1 Upgrade — L2 Upgrade.
- Read the Verilog module in the editor. The catalog line for this block: Bidirectional Counter 4-Bit with load enable and match interrupt generation.
- 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
- 4-Bit Bidirectional Counting: Counts up or down based on the
up_dncontrol signal. - Synchronous Parallel Load: Loads a 4-bit value from
load_valuewhenload_enis high. - Match Interrupt: Generates an interrupt request (
irq) whencount == match_valueandmatch_enis high. - Synchronous Active-Low Reset: Resets the counter and interrupt to zero on the active edge of
rst_n. - Verified Design: All functional scenarios verified via Icarus Verilog simulation.
Ports
| Port Name | Direction | Width | Description |
|---|---|---|---|
| clk | Input | 1 | Clock input |
| rst_n | Input | 1 | Active-low synchronous reset |
| load_en | Input | 1 | Parallel load enable |
| up_dn | Input | 1 | Direction control (1=Up, 0=Down) |
| load_value | Input | 4 | Parallel load data input |
| match_value | Input | 4 | Match comparison value |
| match_en | Input | 1 | Match interrupt enable |
| irq | Output | 1 | Interrupt request signal |
| count | Output | 4 | Counter output value |
Verification
The testbench (tb_bidirectional_counter_load_enable_4bit_match_irq_load.v) verifies the following scenarios:
- TC1: Reset: Verifies that
countandirqare initialized to 0 whenrst_nis low. - TC2: Load: Verifies that
countupdates toload_valuewhenload_enis high. - TC3: Up Count: Verifies that
countincrements whenup_dnis high andload_enis low. - TC4: Down Count: Verifies that
countdecrements whenup_dnis low andload_enis low. - TC5: Match IRQ: Verifies that
irqasserts high whencount == match_valueandmatch_enis high. - TC6: No Match IRQ: Verifies that
irqdeasserts whencount != match_value.
All test cases passed successfully.
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
- 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
- Loadable Down Counter 8-Bit — L1 Upgrade — L2 Upgrade