← Protocols Interviews

Interview Question · Concept

Why a UART Oversamples

L0 FresherL1 Junioruartoversampling

The Question

The interviewer asks

Why does a UART receiver run at 16 times the baud rate? Walk me through how it finds and samples each bit.

Reveal the Model Answer

There is no clock on the wire, so a fast local clock finds the start edge to within one tick. It then counts to the middle of every bit. A typical receiver rejects glitches in the middle of the start bit. There, 8 ticks after the edge, the line must still be low. After that it samples every 16 ticks, often with a 2-of-3 vote over ticks. At 16x a sample is off by at most a sixteenth of a bit; at 2x, by half a bit.

The Sixteen-Tick ReceiverArrows show data moving from the wire to the holding register. Every box runs on the receiver's own tick clock.
The sixteen-tick receiverArrows show data moving from the wire to the holding register. Every box runs on the receiver's own tick clock. component rx wire no clock with it component Low-run counter counts consecutivelow ticks component Start check 8 low ticks: a start component Bit counter every 16th tick: asample component Vote 2 of the 3 ticksending on the sample component Shift register data bits, then stop component Holding register data, valid, flags 8gosample nowbitafter stop
  1. Find the start

    The low-run counter resets on every high tick. Eight lows in a row mean a start bit, and that tick is the middle of it.

  2. Count to each middle

    From the start, the bit counter fires every 16 ticks: the middle of data 0, data 1 and so on to the stop bit.

  3. Sample and deliver

    Each sample is a vote of three ticks. After the stop sample the byte and its flags go to the holding register.

Read the diagram as text
  • rx wire: no clock with it
  • Low-run counter: counts consecutive low ticks
  • Start check: 8 low ticks: a start
  • Bit counter: every 16th tick: a sample
  • Vote: 2 of the 3 ticks ending on the sample
  • Shift register: data bits, then stop
  • Holding register: data, valid, flags
  • rx wire → Low-run counter
  • Low-run counter → Start check: 8
  • Start check → Bit counter: go
  • Bit counter → Vote: sample now
  • Vote → Shift register: bit
  • Shift register → Holding register: after stop

Finding the start and finding the middle are one counter: eight ticks.

Measured sweepOne Sample per Bit Against SixteenThe same 64 seeded frames at each rate error, on one wire, into two receivers.
  • one sample per bit
  • sixteen per bit (rx0)
0102030405060Frames decoded of 64-3%-2%-1%01%2%3%Transmitter rate error0204060Frames decoded of 64-2%02%Transmitter rate error
Read the plot as a table
Transmitter rate errorone sample per bitsixteen per bit (rx0)
-3%4664
-2%5564
-1%6064
0%6464
1%5664
2%5564
3%5464

Measured. With one sample per bit, the receiver keeps only 46 of 64 frames at −3 %. The sixteen-tick receiver decodes all 64 at every step shown.

  1. Hunt

    Wait for a falling edge on the idle line.

  2. Confirm

    Eight ticks later, mid start bit, is the line still low? If not, it was a glitch: go back to hunting.

  3. Sample

    Every 16 ticks after that: data 0 at tick 24, data 7 at tick 136, the stop bit at tick 152.

  4. Check and deliver

    Stop sample 1: deliver the byte. Stop sample 0: framing error. Then hunt again; drift restarts at zero on the next edge.

Self-Check

Tick each key point you covered in your answer.

What Interviewers Listen For (Fresher)

A good fresher answer says there is no clock on the wire, so the receiver samples in the middle of each bit. It uses 16 ticks per bit to find that middle.

Cross-Questions

Where the interviewer goes next. Open a node to practise that follow-up.

WhyWhat IfProve ItBreak ItScale It

  1. Why a UART Oversamples
  2. WhyWhy 16 and Not 2L1 JuniorL2 Mid-Level

    Why 16x? Would 4x or 64x be better?

    Reveal the Model Answer

    The ratio sets the quantisation error of finding the start edge: up to one tick, or 1/N of a bit. At 2x that is half a bit, which already uses the whole budget; at 16x it is about 6 %. Beyond that, the rate mismatch between the two clocks dominates. So 64x buys little and costs a faster clock and wider counters. Sixteen also leaves room for a centred vote over several ticks.

    Self-Check

    Tick each key point you covered in your answer.

    What Interviewers Listen For (Junior)

    A good junior answer says the start edge is found to within one tick. That error is 1/N of a bit.

  3. Break ItBeating the Majority VoteL1 JuniorL2 Mid-Level

    Design the shortest glitch that corrupts a byte despite a 2-of-3 vote. How would your testbench inject it?

    Reveal the Model Answer

    Two low ticks on two of the three vote ticks of one sample win the vote. One tick never does. The bench must time the glitch against the receiver's own sample ticks. A random glitch time rarely lands on two vote ticks, so the bench must know or sweep the sample position. The P6.5 bench did this and turned 55h into 45h with no flag.

    A 1-tick low on the sample tick of data 4
    01234567tick8485868788899091rx at the tickones counted0120ticks to sample432116151413

    Measured, one column per tick for 0x55. Ticks 86 and 87 count two 1s; tick 88 reads 0 and is the sample tick. Two of three is a 1, and the counter restarts at 16.

    Self-Check

    Tick each key point you covered in your answer.

    What Interviewers Listen For (Junior)

    A good junior answer says a glitch must cover two of the three vote ticks to change a bit.

  4. Prove ItSolve P6.6.2: A Compact UART Voter and SamplerSimulator-graded

    Show it, don't just say it: this Silicon Lab problem is graded by the simulator.

    Open Problem P6.6.2

  5. What IfThe Baud Mismatch BudgetL1 JuniorL2 Mid-Level

    Asked if they assume both clocks are exact

    Your UART and its peer run from different clocks. How much baud-rate mismatch can the link tolerate, and which bit fails first?

    Reveal the Model Answer

    Drift is zero at each start edge and grows with every bit. So the last sample, the stop bit, fails first. A receiver that samples exact bit centres has half a bit of slack over the nine bits before the stop. That is about ±5.6 %, shared by both ends. Real receivers do worse: the site's bench receiver first loses 8N1 frames at +4.5 % and −6 %. The 8E1 format fails earlier, because parity puts the stop bit one bit later.

    Measured sweepFrames Decoded Against Rate Error, Back to Back64 seeded frames per 0.5 % step, frames back to back, the bench receiver. Positive error is a slower transmitter.
    • 8N1
    • 8E1
    • 8N2
    0102030405060Frames decoded of 64-8%-6%-4%-2%02%4%6%8%Transmitter rate error8N1 −6 %8N1 +4.5 %0204060Frames decoded of 64-5%05%Transmitter rate error8N1 −6 %8N1 +4.5 %
    Read the plot as a table
    Transmitter rate error8N18E18N2
    -8%009
    -6%0064
    -4%646464
    -2%646464
    0%646464
    2%646464
    4%645264
    6%745
    8%012

    Measured, 64 frames per step, back to back. 8N1 first loses frames at −6 % and at +4.5 %, and 8E1 fails one step earlier on both sides.

    Where the Budget GoesArrows read as "leads to". A slow transmitter moves the samples toward the start of each bit, a fast one toward the end.
    Where the budget goesArrows read as "leads to". A slow transmitter moves the samples toward the start of each bit, a fast one toward the end. component Rate error e TX bit = 16 × (1 + e)ticks component Drift 16·e·k ticks atsample k component Stop sample largest k, drifts most component Slow side, e > 0 room to the start ofthe bit component Fast side, e < 0 room to the end ofthe bit early samplelate sample
    Read the diagram as text
    • Rate error e: TX bit = 16 × (1 + e) ticks
    • Drift: 16·e·k ticks at sample k
    • Stop sample: largest k, drifts most
    • Slow side, e > 0: room to the start of the bit
    • Fast side, e < 0: room to the end of the bit
    • Rate error e → Drift
    • Drift → Stop sample
    • Stop sample → Slow side, e > 0: early sample
    • Stop sample → Fast side, e < 0: late sample

    The budget is about half a bit spread over the frame, split by where the sample sits.

    1. Drift

      A transmitter bit longer by a fraction e ends 16·e·k ticks late at bit k. The stop bit has the largest k.

    2. Slow side

      The stop bit starts at 144·(1 + e) ticks; the centre sample is at 152. It reads data 7 once e passes 8/144, about 5.6 %.

    3. Fast side

      Data 7 ends at 144·(1 + e); its sample is at 136. Past about −5.6 % it reads the stop bit: wrong data, and with an idle line after, no flag.

    4. Both ends

      Divisor rounding plus the peer's oscillator: 115200 from 50 MHz with divisor 27 is already +0.47 %.

    RUNIcarus Verilog · in your browser
    Edit the code, then run it
    Expected: e = +4.5 %: RX 55 ok e = +5.5 %: RX 55 ok e = +6.0 %: RX 55 FE e = -5.5 %: RX 55 ok e = -6.0 %: RX d5 ok

    Self-Check

    Tick each key point you covered in your answer.

    What Interviewers Listen For (Junior)

    A good junior answer says the stop bit fails first because drift grows from the start edge. It says both ends share a budget of roughly 5 %.

    Missed Corner

    "A rate error always shows up as a framing error."

    That holds only on the slow side. A fast transmitter sends the stop bit early, so the data 7 sample reads it. If the line idles after the frame, the stop sample still reads 1. In the run, −6 % delivers D5h for 55h with no flag.

    Source This question's run (Icarus Verilog 12): at −6 % it delivers D5h with no flag

    Half-Truth

    "Each end may be off by 5 %."

    The budget belongs to the link, not to each end. Divisor rounding at one end and the peer's oscillator error add up. Real receivers also have less than the ideal ±5.6 %.

    Misconception

    "Adding parity makes the link more robust to clock error."

    Parity makes the frame longer, so the stop sample sits one bit further from the start edge. In the P6.4 sweep, 8E1 first fails at +4 %, and 8N1 at +4.5 %.

    Source ASIC Point lesson P6.4 (measured sweep): 8E1 first fails at +4 %, 8N1 at +4.5 %

  6. WhyWhy the Stop Bit Fails FirstL1 Junior

    Why is it the stop bit that fails, and not data bit 0?

    Reveal the Model Answer

    The start edge is the only moment both ends agree on, and drift is zero there. Each later bit adds the same timing error. So the sample furthest from the start edge, the stop sample, has drifted most. This is also why the receiver restarts its count on every start edge. The error never carries from one frame to the next.

    Self-Check

    Tick each key point you covered in your answer.

    What Interviewers Listen For (Junior)

    A good junior answer says drift grows evenly from the start edge and resets with every new frame.

  7. What IfDoes a Second Stop Bit HelpL2 Mid-Level

    Would switching to two stop bits give you more tolerance?

    Reveal the Model Answer

    It helps only on the fast side, and only when frames stream back to back. There, with a fast transmitter, the stop sample comes late and can land in the next start bit. It then reads 0. A second stop bit puts idle time there instead. With idle time between frames it buys nothing: the P6.4 sweep shows 8N1 and 8N2 failing at the same steps.

    Measured sweepThe Same Sweep with an Idle Bit Between FramesOne idle bit plus a seeded fraction of a tick before every frame. Compare 8N1 and 8N2 on the fast side.
    • 8N1
    • 8E1
    • 8N2
    0102030405060Frames decoded of 64-8%-6%-4%-2%02%4%6%8%Transmitter rate error8N1 −6.5 %8N1 +4.5 %0204060Frames decoded of 64-5%05%Transmitter rate error8N1 −6.5 %8N1 +4.5 %
    Read the plot as a table
    Transmitter rate error8N18E18N2
    -8%959
    -6%644364
    -4%646464
    -2%646464
    0%646464
    2%646464
    4%644864
    6%547
    8%202

    Measured with an idle bit between frames. 8N1 and 8N2 first lose frames at the same steps, −6.5 % and +4.5 %.

    Self-Check

    Tick each key point you covered in your answer.

    What Interviewers Listen For (Mid-Level)

    A good mid-level answer says a second stop bit helps only on the fast side, with frames back to back. It cites the measured sweep: with idle gaps there is no gain.

  8. Scale ItSigning off a UART Link BudgetL2 Mid-LevelL3 Senior

    Your SoC talks to a module clocked by an RC oscillator. How do you sign off that the UART link works across temperature and parts?

    Reveal the Model Answer

    Add up the error sources: this end's divisor rounding and clock tolerance, and the peer's oscillator tolerance over temperature and voltage. Compare the sum, in both directions, with the receiver's measured budget for the frame format in use, not a quoted 5 %. In simulation, sweep the peer rate in fine steps, both ways, in every supported format. Run frames back to back and with gaps. Record the first failing step as the sign-off number.

    Self-Check

    Tick each key point you covered in your answer.

    What Interviewers Listen For (Mid-Level)

    A good mid-level answer adds up the errors of both ends. It compares them with the budget for the frame format really in use.

  9. WhyWhy the Baud Budget Is LopsidedL2 Mid-LevelL3 Senior

    Why is the measured 8N1 budget +4.5 % on one side and −6 % on the other, not ±5 %?

    Reveal the Model Answer

    A rate error moves each sample further from its bit centre, and the stop bit moves most. The total room is about half a bit over the frame. A receiver that samples a little before the centre has less room on one side and more on the other. So quote the budget with its receiver, format and pacing.

    Self-Check

    Tick each key point you covered in your answer.

    Misconception

    "Every UART tolerates ±5 %."

    The budget depends on the frame format and where the receiver samples. The lesson receiver measured +4.5 % and −6 % for 8N1.

    Source ASIC Point lesson P6.4 (measured)

  10. Prove ItSolve P6.4.1: A Receiver That Survives the SweepSimulator-graded

    Show it, don't just say it: this Silicon Lab problem is graded by the simulator.

    Open Problem P6.4.1

  11. Prove ItSolve P6.3.2: Move the Sample into the BitSimulator-graded

    Show it, don't just say it: this Silicon Lab problem is graded by the simulator.

    Open Problem P6.3.2

What People Get Wrong

Common wrong answers and why they fail. Run It shows the wrong belief failing on a real simulator.

Missed Corner

"The receiver starts a frame on any falling edge."

A short glitch then starts a phantom frame. The receiver is still busy when the real start edge arrives. In the twin, a receiver that trusts the edge delivers 5Fh with a framing error, then a phantom FFh. Re-checking the line in the middle of the start bit fixes it.

Run It

An edge-only receiver turns one glitch and one 41h frame into two wrong frames. The fixed receiver re-checks the line in the middle of the start bit.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: t=162: RX 5f FE t=380: RX ff ok FAIL: one 41h frame sent, 2 frames delivered
See the Fix
`timescale 1ns/1ps
// 16 ticks (ns) per bit. A 3-tick low glitch hits the idle line at t = 10, then one clean 8N1
// frame of 41h starts at t = 100. CHECK_MID = 1: the receiver re-checks that the line is still low 8 ticks after the edge, mid start bit.
module tb;
  localparam bit CHECK_MID = 1;
  reg line = 1;
  int frames = 0; reg [7:0] d; reg stop;
  initial forever begin
    @(negedge line);
    #8;
    if (!CHECK_MID || !line) begin
      #16; for (int i = 0; i < 8; i++) begin d[i] = line; #16; end
      stop = line; frames++;
      $display("t=%0d: RX %h %s", $time, d, stop ? "ok" : "FE");
    end
  end
  initial begin
    #10 line = 0; #3 line = 1;                       // the glitch
    #87;                                             // t = 100
    line = 0; #16;
    for (int i = 0; i < 8; i++) begin line = 8'h41 >> i; #16; end
    line = 1; #400;
    if (frames == 1 && d == 8'h41 && stop) $display("PASS: one frame, 41 ok");
    else $display("FAIL: one 41h frame sent, %0d frames delivered", frames);
    $finish;
  end
endmodule

Prints: t=252: RX 41 ok PASS: one frame, 41 ok

Misconception

"Sample at the bit edges, every 16 ticks from the falling edge."

An edge is exactly where the line changes. So any jitter or rate error picks the neighbouring bit. The P6.3 bench moved its sample to the edge. It decoded 55h as AAh with a framing error, even at zero rate error.

Source ASIC Point lesson P6.3 (measured): sampling at the bit edge decodes 55h as AAh with a framing error

Misconception

"The majority vote makes the receiver noise-proof."

A 2-of-3 vote outvotes a one-tick glitch. But a two-tick glitch on the right ticks wins the vote. The P6.5 bench sent 55h and delivered 45h with no flag.

Source ASIC Point lesson P6.5 (measured): a 2-tick hit on data 4 turns 55h into 45h with no flag

Learn It, Then Prove It