Counters
16-Bit Cycle Counter with Prescaler — L1 Upgrade — L2 Upgrade
16-bit cycle counter with prescaler, load enable, match interrupt, and synchronous reset.
About this block
Simulate it in the Verilog IDE
16-Bit Cycle Counter with Prescaler — 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 implements a configurable 16-bit cycle counter with prescaler support, load enable, match interrupt generation, and synchronous reset. It is designed for timing control and event counting applications in FPGA and ASIC designs.
The design is fully verified with Icarus Verilog and includes a comprehensive testbench.
This IP provides a configurable 16-bit counter capable of prescaling the input clock frequency. Key features include:
- Prescaler Support: Divides the input clock frequency by 2 when enabled.
- Load Enable: Allows immediate loading of a 16-bit value into the counter.
- Match Interrupt: Asserts an interrupt request (IRQ) when the counter value matches a target
match_value. - Synchronous Reset: Resets the counter and prescaler to zero on the active-low reset signal.
- Choose Open in IDE. RTL Studio loads the packaged workspace for 16-Bit Cycle Counter with Prescaler — L1 Upgrade — L2 Upgrade.
- Read the Verilog module in the editor. The catalog line for this block: 16-bit cycle counter with prescaler, load enable, match interrupt, and synchronous reset.
- 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.
Architecture
The design consists of two main stages:
- Prescaler Stage: A toggle flip-flop that divides the clock frequency by 2 when
prescale_enis high. - Counter Stage: A 16-bit counter that increments on the rising edge of the clock if the prescaler state is high. It supports immediate loading via
load_enand generates an IRQ whencount == match_value.
### Logic Flow
- Reset:
rst_nlow resetscountandirqto 0, andprescale_stateto 0. - Prescaler: Toggles
prescale_stateon every clock edge ifprescale_enis high. - Counter Update:
- If load_en is high, count loads load_value. - Else if prescale_state is high, count increments by 1.
- IRQ Generation:
irqis asserted high ifcountequalsmatch_value, otherwise it is deasserted.
Ports
| Port Name | Direction | Width | Description |
|---|---|---|---|
clk | Input | 1 | Clock input |
rst_n | Input | 1 | Active-low synchronous reset |
load_en | Input | 1 | Load enable signal |
prescale_en | Input | 1 | Prescaler enable signal |
load_value | Input | 16 | Value to load into counter |
match_value | Input | 16 | Value to match for IRQ assertion |
irq | Output | 1 | Interrupt request signal |
count | Output | 16 | Current counter value |
Verification
The testbench verifies the following functionalities:
- TC1: Checks that
countandirqare zero after reset. - TC2: Verifies that
load_encorrectly loadsload_valueintocount. - TC3: Confirms that the counter increments when
prescale_enis active. - TC4: Asserts that
irqgoes high whencountmatchesmatch_value. - TC5: Ensures that
irqgoes low when the match condition is cleared.
All five test cases passed successfully in simulation.
More in Counters
- 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
- Loadable Down Counter 8-Bit — L1 Upgrade — L2 Upgrade