Practice
Freight Lift Link
The freight lift in an old printing house is getting new electronics, but not new wiring. One twisted pair (a two-wire signal cable) runs from the cab panel down the shaft. Pulling fresh cable through 60 years of conduit is not in the budget. Over that pair the panel sends command frames, 1 bit per clock, synchronous to the clock the controller already distributes. A frame is a start bit, 4 data bits, and a stop bit. The line idles high.
The maintenance log records two recurring problems with the receiver you are replacing. When electrical noise corrupted a frame, the receiver flagged an error but then treated the next low sample from that damaged frame as a new start bit. It stayed misaligned until someone power-cycled the cab. It also needed an idle gap to re-arm. When the operator keyed commands quickly, the second frame was quietly dropped, and goods went to the wrong floor.
Your task: build the receiver. Watch rx, recover each frame's 4 data bits, and pulse valid for a good frame or ferr for a broken one.
Interface
| Port | Direction | Type | Description |
|---|---|---|---|
clk | in | 1 bit | Clock (also times the serial line) |
rst | in | 1 bit | Synchronous reset (active high) |
rx | in | 1 bit | Serial line, one bit per clock, idle high |
data | out | 4-bit vector | Payload of the last good frame |
valid | out | 1 bit | Good frame received (one-cycle pulse) |
ferr | out | 1 bit | Framing error (one-cycle pulse) |
Behavior
- A frame is 6 samples: start bit
0, four data bits LSB first (first data sample isdata(0)), stop bit1 rxis sampled at every rising clock edge- While hunting, a sampled
0is a start bit; the next four samples are data, and the sample after those is the stop bit - Stop bit sampled
1:validis high for exactly one cycle (the cycle after the stop sample) anddatapresents the frame's payload dataholds its value until the next good frame- Stop bit sampled
0: framing error;ferris high for exactly one cycle instead,validstays low, anddatakeeps its previous value - After a framing error the receiver ignores the line until it samples a
1; only after that may a sampled0start a new frame - After a good frame there is no idle requirement: the sample immediately after the stop bit may be the next start bit
- A line held low produces exactly one framing error, then silence until the line returns high
validandferrare never high in the same cyclerst = 1at a clock edge returns the receiver to hunting and clearsdata,valid, andferr
What the bench checks
- The testbench checks
validandferron every cycle - Normal and back-to-back frames must capture four data bits least-significant first and pulse
validfor one cycle - A bad stop bit must pulse only
ferrand preserve the last good data word - A low line after that error must not start another frame until the line returns high
- A sustained break must raise exactly one framing error, then recover for a clean frame after release
- Reset mid-frame must abandon the partial word, clear the saved data, and allow a new frame afterward
Constraints
everything is synchronous to clk; all outputs are registered.
this models the receiver end of the pair; the line is already bit-synchronous to clk. The cab panel, the cable's electrical behavior, and downstream command handling are out of scope.
Do not add ports.
Click Run to execute your code. Output will appear here.