Problems

12. Maximal-length LFSR

MediumWrite the moduleAbout 20 min
sequentiallfsrpseudo-random

Build an 8-bit Fibonacci linear feedback shift register that steps through all 255 non-zero values before repeating.

Use the feedback polynomial x^8 + x^6 + x^5 + x^4 + 1. With the register bits numbered q[7] (the oldest) down to q[0], the new bit is q[7] XOR q[5] XOR q[4] XOR q[3]. On each enabled edge the register shifts left by one place and the new bit enters at q[0].

rst (synchronous, active high) loads the seed 0000_0001. When en = 0 the register holds.

Ports

Module lfsr8

PortDirBitsWhat it is
clkin1Clock.
rstin1Synchronous reset to the seed 0x01.
enin1Step enable.
qout8Register contents.

Example

From the seed 0x01 the register reads 0x02, 0x04, 0x08, then 0x11 (the feedback picks up the 1 at q[3]), 0x23, 0x47, 0x8E. After 255 steps it is back at 0x01.

Stuck? . Sign in to save your progress. You can solve the free problems without an account.

Veriloglfsr8.v
14px
Loading the editor…

Submit your answer to have it graded. The hidden test runs on the server; you see whether it passes and, if not, the first case it gets wrong.

Maximal-length LFSR: Verilog interview question | breadboardhub