Practice

Jelly Tank Glow

The dimmer card above the moon jellyfish tank died on Tuesday in a puff of smoke, and the vendor closed down years ago. The card drove the ring of blue LEDs that keeps the jellies visible for late tours. Its brightness followed whatever the evening aquarist set on an 8-position knob. Tank 2 across the hall runs the same card, still working, and nobody wants to desolder a live board on a guess. So the aquarist clipped a logic analyzer onto tank 2: a tool that records every digital signal, cycle by cycle. It captured the card doing its job. The knob got turned during the recording, more than once in the middle of a dimming pattern. That capture is the only specification you get.

Your task: write a replacement that matches the capture cycle for cycle. Drive pwm exactly as recorded, following every level change the way the recording shows. Mark each frame start on frame, including the cycles nobody would think to ask about.

Interface

PortDirectionTypeDescription
clkin1 bitClock
rstin1 bitSynchronous reset (active high)
levelin3-bit vectorBrightness knob, 0 to 7
pwmout1 bitLED ring drive, changes only at clock edges
frameout1 bitHigh during the first slot of each frame

Behavior

Everything you need is in the trace: read it one column per clock cycle. Inputs are sampled at each rising edge, and outputs only ever move on a rising edge. level is decimal.

cycle |  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
------+------------------------------------------------------------------------------------
rst   |  1  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
level |  3  3  3  3  3  3  3  3  3  3  3  3  6  6  6  6  6  6  6  6  0  0  0  0  0  0  0  0
pwm   |  0  0  0  0  0  0  0  0  0  1  1  1  0  0  0  0  0  1  1  1  1  1  1  0  0  0  0  0
frame |  1  1  0  0  0  0  0  0  0  1  0  0  0  0  0  0  0  1  0  0  0  0  0  0  0  1  0  0
  • Output runs in frames of 8 cycles, slots 0 through 7; frame is high during slot 0
  • pwm is high while the slot number is below the brightness in force: a brightness of 3 lights slots 0, 1 and 2
  • Brightness 0 is a dark frame; brightness 7 lights slots 0 through 6 and always leaves slot 7 dark
  • The knob is sampled once per frame, at the rising edge that starts it
  • The level in a frame's first column is the brightness that whole frame uses; mid-frame knob turns wait for the next boundary
  • rst = 1 at a rising edge restarts the card at slot 0 with brightness 0, whatever was in flight
  • The frame in progress when reset hits is abandoned, and the next frame is dark, which is exactly the capture's opening

What the bench checks

  • The testbench replays this capture cycle for cycle and checks pwm and frame on every cycle
  • Past the capture it continues with brightness 7, then a knob turned during a frame's last slot, then a reset in mid-frame
  • The last-slot knob turn proves the frame boundary samples the live knob

Constraints

TIMING

everything is synchronous to clk; both outputs are decoded from registers and change only at clock edges.

SCOPE

this replicates the dimmer card's digital behavior, as the capture shows it. The LED ring, its drive electronics, and the knob hardware are out of scope.

Match the capture exactly, including the dark frame after reset. Do not add ports. Do not special-case the literal knob values in the trace: the bench continues past the capture with settings the recording never used.

Loading editor...

Click Run to execute your code. Output will appear here.