H6.6 Receiver Start-Bit Qualification

EasyFixIcarus · browser samples / server checksReview the topic

Fix a start-bit detector that accepts a low pulse one sample too short.

Hardware context: UART transmitter/receiver with a specified baud and sampling contract. Distinguish a low serial glitch from a qualified UART start bit.

A UART receiver kept producing bytes nobody sent. Short low noise pulses on the line looked like start bits. The detector decides too early.

A receiver samples the line 16 times per bit. A real start bit is low for 16 samples, but a glitch is shorter. So the receiver waits for eight low samples in a row before it believes a start.

The function qualify_start scans a list of samples. It returns the index of the eighth low sample in a row after a high sample, or 0xffff when there is none. The tests give it low runs of every length up to 12. Find the bug and fix it.

Signals in the Timeline

SignalWidthRole
samples64input of each check
count8input of each check
Full specification
The function (keep this name and these types)
function automatic logic [79:0] qualify_start(input logic [63:0] samples,
                                              input logic [7:0] count);
RuleMeaning
SamplesBit i of samples is sample i. Only samples 0 to count - 1 are used. count is 0 to 64.
ArmedThe scan starts disarmed. A high sample arms it. Low samples before the first high never count.
Low runWhile armed, each low sample adds 1 to the run. A high sample sets the run back to 0.
StartThe eighth low sample of a run is the start. Return its index in bits 15:0.
First onlyReturn the first start found. Ignore any later samples.
NoneReturn 0xffff (65535) when no start is found.

Bits 79:16 of the result are always 0. A start index says nothing about the data bits that follow.

Examples

Example 1

A Glitch, Then a Real Start
Input
count = 13; samples 0 and 4 are high, samples 1-3 and 5-12 are low
Output
start_index = 12

The three lows at samples 1 to 3 are a glitch. The high at sample 4 sets the run back to 0. Samples 5 to 12 are eight lows in a row, so the start is at index 12.

Example 2

A Line That Is Low from the Start
Input
count = 64; all samples are low
Output
start_index = 65535

No high sample ever arms the detector. The result is 65535, which means no start.

Example 3

Exactly Eight Lows
Input
count = 9; sample 0 is high, samples 1-8 are low
Output
start_index = 8

The run reaches eight at sample 8, the last sample in range. The start is at index 8.

Constraints and Contract

  • Samples at or above count are ignored.
  • Keep the function name, the argument types and the 80-bit return type.

Hints

Hint 1

Trace one high sample followed by exactly eight lows. Which index should come back? Then try seven lows.

Hint 2

Keep the arm bit and the run counter apart. Arming needs a high sample. The run counts lows after it.

Hint 3

Look at the compare on low_count. The counter goes up before the compare, so the eighth low makes it 8.

What the grader checks: The tests cover low runs of 0 to 12 samples after 1 to 4 high samples. They also cover a line stuck low and a glitch before a start. Samples are clean 0s and 1s; no input synchronizer or noise filter is modeled.

55 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 7 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

A Glitch, Then a Real Start

Input
count = 13; samples 0 and 4 are high, samples 1-3 and 5-12 are low
Expected output
start_index = 12

The three lows at samples 1 to 3 are a glitch. The high at sample 4 sets the run back to 0. Samples 5 to 12 are eight lows in a row, so the start is at index 12.

Run samples executes all 3 public checks. Check all tests runs 55 checks on the server.

Icarus · browser samples / server checks