Saturating Counter Logic Sharing
High-speed telemetry systems often track event occurrences using hardware counters. When an event rate exceeds the maximum countable value within a polling window, the counter must saturate rather than wrap around to zero, preventing catastrophic data misinterpretation downstream. In highly pipelined designs, separating the state elements from the next-state logic allows for better timing analysis and logic sharing.
This module computes the next value for an 8-bit saturating counter purely combinationally. It receives the current count value and an enable signal. If the enable is asserted, it adds one to the current count. If the current count is already at its maximum value of 255, the output must remain 255. If the enable is de-asserted, the output simply passes through the current count unmodified.
To optimize for area and timing, the synthesis tool must not infer any comparators. Checking if a counter reached its maximum before incrementing typically requires an 8-bit comparator; however, checking the carry-out of the incrementer is entirely free.
Timing and Reset Rules
- This module is purely combinational; there is no clock or reset signal.
- All outputs must continuously reflect the combinational evaluation of the inputs.
- Priority: The saturation limit takes precedence over the enable signal.
Worked Trace
Evaluation 1: count_in=0, en=1 → count_out=1 Evaluation 2: count_in=254, en=1 → count_out=255 Evaluation 3: count_in=255, en=1 → count_out=255 (saturation) Evaluation 4: count_in=100, en=0 → count_out=100 (hold)
Port Table
| Signal | Direction | Width | Description | |--------|-----------|-------|-------------| | count_in | input | 8 | Current value of the counter | | en | input | 1 | Enable signal; requests an increment when 1 | | count_out | output | 8 | Next value of the counter; saturates at 255 |
Constraints
- Purely combinational logic; do not infer any flip-flops or latches.
- Do not use equality (
==,!=) or relational (>,<,>=,<=) operators. - The output must saturate at 255 and never wrap around to 0.
- You must handle the saturation check by evaluating the carry-out of a 9-bit addition.
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against a real testbench — you get the waveform back, not a stored answer.
This problem is part of Codiode Pro. The statement above is free to read.
The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.