0
0
Verilogprogramming~20 mins

Linear Feedback Shift Register (LFSR) in Verilog - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
LFSR Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a 4-bit LFSR with given taps
What is the output sequence of this 4-bit LFSR after 5 clock cycles?
module lfsr_4bit(
  input clk,
  input rst,
  output reg [3:0] q
);
  wire feedback = q[3] ^ q[2];
  always @(posedge clk or posedge rst) begin
    if (rst) q <= 4'b0001;
    else q <= {q[2:0], feedback};
  end
endmodule
A0001, 0010, 0100, 1000, 0001
B0001, 1000, 0100, 0010, 0001
C0001, 0010, 0100, 1001, 0011
D0001, 0011, 0111, 1110, 1101
Attempts:
2 left
💡 Hint
Think about how the feedback bit is calculated and shifted in.
🧠 Conceptual
intermediate
1:00remaining
Purpose of the feedback bit in an LFSR
What is the main role of the feedback bit in a Linear Feedback Shift Register (LFSR)?
ATo count the number of clock cycles
BTo introduce new bits based on XOR of selected bits, creating a pseudo-random sequence
CTo hold the current state without change
DTo reset the register to zero
Attempts:
2 left
💡 Hint
Think about how LFSR generates sequences.
🔧 Debug
advanced
2:00remaining
Identify the error in this LFSR Verilog code
This 3-bit LFSR code is intended to generate a pseudo-random sequence. What error will it cause when synthesized?
module lfsr_3bit(
  input clk,
  input rst,
  output reg [2:0] q
);
  wire feedback = q[2] ^ q[0];
  always @(posedge clk or posedge rst) begin
    if (rst) q <= 3'b001
    else q <= {q[1:0], feedback};
  end
endmodule
ASyntax error due to missing semicolon after if statement
BRuntime error because feedback is not declared as reg
CNo error, code works correctly
DSynthesis error because q is not initialized
Attempts:
2 left
💡 Hint
Check the if statement syntax carefully.
Predict Output
advanced
1:30remaining
Number of unique states in a 3-bit maximal LFSR
How many unique non-zero states will a 3-bit maximal LFSR cycle through before repeating?
Assume the feedback polynomial is x^3 + x + 1.
A8
B6
C3
D7
Attempts:
2 left
💡 Hint
A maximal LFSR cycles through all possible states except zero.
🚀 Application
expert
2:30remaining
Determine the next state of a 5-bit LFSR
Given this 5-bit LFSR with taps at bits 5 and 3 (positions 4 and 2 in zero-based indexing), and current state 10110, what is the next state?
Current state q = 5'b10110
Feedback = q[4] ^ q[2]
Next state = {q[3:0], feedback}
A01100
B11011
C01101
D10101
Attempts:
2 left
💡 Hint
Calculate feedback bit first, then shift left and insert feedback at LSB.