Practice
Loft Clock Wire
A pigeon racing club times every returning bird with an electronic loft clock. When a bird lands, the clock stamps its ring number and arrival time. It sends each stamp, one byte at a time, over a serial wire to the logger in the clubhouse.
The old clock's transmitter board was built wrong. It sent every byte highest bit first. UART receivers expect the lowest bit first, so the logger recorded garbage ring numbers. Two race results were voided before anyone traced the fault.
Your task: build the clock's UART transmitter. When send pulses while the line is idle, capture the byte on data. Then drive tx with a start bit, the 8 data bits lowest bit first, and a stop bit, each lasting 8 clock cycles. Hold busy high while the frame is on the wire, and ignore send until the frame is done.
Interface
| Port | Direction | Type | Description |
|---|---|---|---|
clk | in | 1 bit | System clock |
rst | in | 1 bit | Synchronous reset (active high) |
send | in | 1 bit | Transmit request (one-cycle pulse) |
data | in | 8-bit vector | Byte to transmit |
tx | out | 1 bit | Serial line to the logger (idle high) |
busy | out | 1 bit | High while a frame is on the wire |
Behavior
- When idle,
txis high andbusyis low - While idle,
sendhigh at a rising clock edge accepts the byte ondata:busyrises and the start bit begins on that same edge - Cycle numbering: cycle 0 is the first full cycle with
busyhigh - A frame is 10 bits: a start bit
0, the 8 data bits LSB first (bit 0 of the byte first), and a stop bit1 - Each bit lasts exactly 8 clock cycles: the baud divisor is fixed, not a parameter
txdrives the start bit during cycles 0 to 7 and the stop bit during cycles 72 to 79- Data bit 0 is on the wire during cycles 8 to 15
- Each next data bit takes the next 8 cycles, ending with data bit 7 during cycles 64 to 71
- At cycle 80 the frame is over:
busyreturns low andtxstays high busyis high during cycles 0 through 79 and low at every other time- The byte is captured when
sendis accepted; later changes ondatado not affect the frame - A
sendpulse whilebusyis high is ignored: nothing is queued and nothing extra is sent later sendhigh during the first idle cycle after a frame begins a new frame on the next cyclerst = 1at a rising clock edge cancels any frame:txreturns high andbusylow on the next cycle
What the bench checks
- The testbench checks
txandbusyagainst the fixed timeline on every cycle of every frame - The testbench decodes the wire like a receiver: it samples each data bit mid-slot and compares the rebuilt byte
- The testbench sends byte values that expose reversed bit order, a missing start bit, and a broken stop bit
- The testbench changes
dataright after acceptance and checks the wire still carries the captured byte - The testbench pulses
sendwith a decoy byte in the middle of one frame and checks that no extra frame follows - The testbench pulses
sendwith a decoy byte on the last busy cycle of one frame and checks the line stays idle after it - The testbench starts one frame with
sendhigh during the first idle cycle after the previous frame - The testbench asserts
rstin the middle of one frame and checkstxandbusyare idle on the next cycle
Constraints
everything is synchronous to clk; all outputs are registered.
this models the transmitter side of the wire at a fixed 8-cycle bit time. The ring reading, the time stamping, and the logger's receiver are out of scope.
Do not add ports.
Click Run to execute your code. Output will appear here.