Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • RTL Foundations36
  • Combinational Design25
  • Sequential Design27
    • Flip-Flops and Registers
    • Counters and Timers
    • Shift Registers and LFSRs
      • Serial and Parallel Data Movement
      • Universal Shift Register
      • LFSR for PRBS Generation
    • Pipelining
    • Stalls, Bubbles and Hazards
    • Retiming
  • FSM & Control27
  • Timing & Clocking39
  • Reset & CDC34
  • Memory & Buses57
  • Advanced RTL28
  • Senior & Interview76
  • Glossary and Notation
Loading lesson

‹Shift Registers and LFSRs
  1. Topics
  2. RTL Design
  3. Sequential Design
  4. Shift Registers and LFSRs
  5. LFSR for PRBS Generation

Part 3 · Sequential · Intermediate

LFSR for PRBS Generation

A maximal-length LFSR sequence from XOR feedback, with rules and uses.

On this page

    Why this matters

    XOR feedback on a shift register gives a long pseudo-random sequence from n flops and a few gates. Pick the wrong taps and the sequence is short; seed it with zero and it stops for good.

    After this lesson you can: build a maximal-length LFSR from a primitive polynomial, trace its state and serial output, and say what it is and is not used for.

    Feedback turns a shift register into a sequence generator

    A linear-feedback shift register shifts every clock. Its input bit is the XOR of selected tap bits.

    For this XOR-feedback topology, a primitive polynomial selects taps that make every nonzero seed visit all 2ⁿ − 1 nonzero states before repeating. That maximal period is the useful behavior to check; an arbitrary tap choice need not achieve it. Hardware uses n flops and an XOR feedback network.

    sequence length=2n−1

    Here x⁷ + x⁶ + 1 is implemented as a left-shifting Fibonacci register: keep s[5:0], append s[6] ^ s[5] as the new LSB. The tap positions 7 and 6 use one-based numbering. A right-shifting or Galois implementation needs its own topology mapping; do not copy indices without checking direction, numbering and XOR/XNOR convention. AMD/Xilinx XAPP052 provides maximum-length tap tables and discusses feedback conventions.

    The PRBS7 register x^7 + x^6 + 1 as drawn by this page: seven flops shift left, the two tap bits s[6] and s[5] are XORed and the result enters at s[0]; the serial output is s[6]

    Read the row as the register: every clock each bit moves one box to the left, s[6] leaves as the output bit, and the XOR of the two highlighted taps becomes the new s[0].

    • Taps: s[6] and s[5] are polynomial terms x⁷ and x⁶ in one-based numbering.

    • Seed 01: s[6] and s[5] are both 0, so the new s[0] is 0 and the register becomes 02, as in slot 1 of the trace below.

    • State 20: s[5] is 1, so the feedback is 1 and the next state is 41.

    The state row steps through the first twelve states after reset.

    • Slot 1: state 02.

    • Slot 2: state 04.

    • Slot 3: state 08.

    • Slot 4: state 10.

    • Slot 5: state 20.

    • Slot 6: state 41.

    • Slot 7: state 03.

    • Slot 8: state 06.

    • Slot 9: state 0c.

    • Slot 10: state 18.

    • Slot 11: state 30.

    • Slot 12: state 61.

    From state to a serial bit stream

    Define prbs = s[6]. A receiver samples this bit just before each rising-edge update, so the emitted bit belongs to the old state, while the waveform displays the new state. Starting from seed 01, the first twelve emitted bits are 000000100000. Predict the next state and emitted bit for 20 and 41, then compare the retained bits and XOR below.

    Old state s[6:0]

    Emitted s[6]

    Feedback s[6] XOR s[5]

    Retained s[5:0] + feedback

    New state

    20 = 0100000

    0

    0 XOR 1 = 1

    100000 + 1 = 1000001

    41

    41 = 1000001

    1

    1 XOR 0 = 1

    000001 + 1 = 0000011

    03

    The plus signs in that table mean concatenation, not arithmetic addition. A different output tap, seed or pre/post-edge sampling convention changes the stream phase; agree on these before connecting a checker or receiver.

    Try it: step the register

    The stepper starts on this page's PRBS7 register: taps 7 and 6, seed 0000001, Fibonacci structure, shifting left with the old s[6] as the output bit.

    LFSR stepper

    Loading lfsr stepper…

    The highlighted cells are the taps that feed the XOR. The table shows the bit emitted from each old state and the new state after the clock edge.
    • Press Step twelve times: the states run 02, 04, 08, 10, 20, 41, 03, 06, 0c, 18, 30, 61 and the output so far is 000000100000, as in the trace above. Run carries on until the seed returns after 127 steps.

    • Untap x⁶ and tap x⁵ (taps 7,5): the period drops to 93, because x⁷ + x⁵ + 1 is not primitive. Taps 7,4 give the full 127 again.

    • Switch to Galois with taps 7,6: the period is still 127, but the states differ (02, 04, 08, 10, 20, 40, 41), so the two structures are not interchangeable in a checker.

    The rules that make it work

    Rule

    Why

    Use a primitive polynomial

    Only primitive polynomials give the full 2ⁿ−1 period; other taps give shorter cycles.

    Never seed with all zeros (for XOR feedback)

    All-zeros is a lock-up state: 0 XOR 0 = 0, so it stays zero forever.

    XNOR feedback flips the forbidden state

    With XNOR the lock-up state is all ones; useful when reset to zero is convenient.

    Taps are fixed by the polynomial

    Change a tap and you change the period and the statistics.

    Standard PRBS polynomials

    Name

    Polynomial

    Length

    Typical use

    PRBS7

    x⁷ + x⁶ + 1

    127

    Short link tests

    PRBS9

    x⁹ + x⁵ + 1

    511

    Serial link testing

    PRBS15

    x¹⁵ + x¹⁴ + 1

    32,767

    Serial link testing

    PRBS23

    x²³ + x¹⁸ + 1

    8,388,607

    Long-pattern link margin tests

    PRBS31

    x³¹ + x²⁸ + 1

    2,147,483,647

    Stress testing, jitter measurement

    What it is used for

    • Built-in self-test (BIST): an LFSR drives test patterns into logic and a second LFSR-like register compresses the responses into a signature.

    • Scramblers: XORing data with an LFSR sequence whitens the data, which usually gives enough transitions for clock recovery. It gives no guaranteed run length (data matching the sequence still gives all zeros), and the receiver must align its matching sequence to recover the data.

    • CRC generators: a CRC is a division by a polynomial, computed with a similar feedback shift register.

    • Pseudo-random stimulus in hardware testbenches and traffic generators.

    Common mistakes

    An LFSR is not cryptographically secure: given a few outputs, the taps and state can be recovered. It suits testing and scrambling, never secrets.

    Interview

    “How would you generate a pseudo-random bit stream in hardware?” An LFSR with primitive-polynomial taps, a non-zero seed, and a comment on the lock-up state. Bonus: mention that a parallel (unrolled) LFSR produces several bits per clock.

    Check yourself An LFSR is reset to all zeros by mistake. What does the output do?

    Nothing: with XOR feedback the all-zero state feeds back 0, so the register stays at zero forever. Fix it by choosing a non-zero seed or by detecting the all-zero state and loading a seed.

    Testbench

    The bounded test checks the defined pre-edge serial output, the twelve worked bits and an integer next-state reference, then checks return to seed after 127 steps and coverage of every nonzero state. Unknown state is diagnosed before indexing the coverage array. The 300-step bound catches failure to return; diagnostics identify the step and failed expectation.

    lfsr7.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    module lfsr7 (
      input  logic       clk, rst_n,
      output logic [6:0] s,
      output logic       prbs
    );
      assign prbs = s[6];                              // sample old MSB at each rising edge
      always_ff @(posedge clk or negedge rst_n)
        if (!rst_n) s <= 7'h01;                         // seed must be non-zero
        else        s <= {s[5:0], s[6] ^ s[5]};          // x^7 + x^6 + 1
    endmodule
    

    Remember

    • A primitive polynomial makes every nonzero seed visit all 2^n - 1 states before repeating.

    • The all-zero state never leaves with XOR feedback, so the seed must be nonzero.

    • Tap numbering, shift direction and the sampling point change the stream phase; agree on them before connecting a checker.

    Rule of thumb: an LFSR suits test and scrambling, never secrets.

    How this was checked

    The test is an executable RTL example, not a recorded simulation result or a link-quality measurement.

    Keep going

    • Code lab: PRBS generator

    • Interview: run a mock interview on this topic

    Related topics

    • DFT and scan (BIST)

    Previous

    75 / 350

    Next: Pipelining

    Up next

    Up nextPipelining

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Serial and Parallel Data Movement
    PRBS7 LFSR, seed = 0x01 (first 12 states after reset)clkstate (hex)02040810204103060c183061
    Expected RTL trace, observed after each rising-edge update. Each state is the previous one shifted left, with the new LSB = s[6] XOR s[5].