Practice
Pulse Stretcher
A network switch is passing traffic, yet the field complaint says the activity LEDs are dead on all 24 ports. The scope trace explains it. The packet engine marks each frame with a pulse on the link-activity signal that lasts exactly 1 clock cycle, but the LED driver misses such short pulses. A colleague who has since left pushed a hotfix, and it made things worse. His version reacted to the trigger being high instead of to it going high. So when a busy port held the trigger high, it kept restarting the pulse, and the LED stayed on continuously. Support now runs two ticket categories for the same board: "LED dead" and "LED stuck".
Your task: build the stretcher that sits between the blip and the LED driver. A rising edge of the trigger, and only a rising edge, produces exactly 4 clock cycles of output. Holding the trigger high is one event, not many. A fresh edge landing mid-pulse restarts the count, so back-to-back frames show as unbroken activity instead of a stutter.
Interface
| Port | Direction | Type | Description |
|---|---|---|---|
clk_i | in | 1 bit | Clock |
rst_i | in | 1 bit | Synchronous reset (active high) |
trig_i | in | 1 bit | Trigger input (synchronous) |
pulse_o | out | 1 bit | Stretched pulse |
Behavior
PULSE WIDTH: a rising edge of
trig_i(a clock edge samplingtrig_i = 1when the previous sample was 0) starts a pulse.pulse_ois 1 for exactly the next 4 clock cycles, then returns to 0.
- The trigger is edge-sensitive: holding
trig_ihigh produces one 4-cycle pulse, not a continuous one - A new rising edge of
trig_iwhile the pulse is active restarts the count:pulse_ostays 1 for exactly 4 more cycles from that edge rst_i = 1at a clock edge clears the pulse at that edge and cancels the remaining count, even if a trigger edge arrives at the same clock edge- A
trig_ialready high whenrst_iis released does not start a pulse; the next pulse requires a fresh rising edge oftrig_i
What the bench checks
- The testbench checks
pulse_oon every cycle - A one-cycle trigger must produce exactly four high cycles, followed by a clean low cycle
- Holding
trig_ihigh for six cycles must not retrigger or lengthen the pulse - A fresh trigger edge two cycles into a pulse must extend the total high time to six cycles
- Reset mid-pulse must win over a simultaneous trigger edge, and a high input across reset release must not start another pulse
- A later fresh edge must still produce a normal four-cycle pulse
Constraints
TIMING: everything is synchronous to
clk_i;pulse_ochanges only at clock edges.
SCOPE: this models the stretcher between the packet engine's blip and the LED driver;
trig_iis already synchronous. The packet engine, the LED driver, and the LED are out of scope.
Do not add ports.
Click Run to execute your code. Output will appear here.