Lfsr. Can somebody help me understand this code?

Status
Not open for further replies.

Ferfil

Newbie level 4
Joined
Sep 27, 2013
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
57

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
module LFSR(
  input clk,
  output reg [15:0] LFSR = 65535
);
 
always @(posedge clk)
begin
  LFSR[0] <= LFSR[0] ^ LFSR[13] ^ LFSR[14] ^ LFSR[15];
  LFSR[15:1] <= LFSR[14:0];
end
endmodule


- - - Updated - - -

please also help me with the testbench. thanks
 
Last edited by a moderator:

This is an LFSR. Presumably, taps 0, 13, 14, 15 have been chosen to generate a maximal length sequence. The selection of taps is not arbitrary, though several options exist. For example, the LFSR using taps 14, 15 would be the more common choice. The code is a shift register that shifts in a new bit based on the xor of bits 0, 13, 14, 15. If this is a maximal length sequence, then the lfsr state will reach all non-zero values and then repeat. The all-zero state would transition to itself, and is thus not part of the sequence.

The testbench should create a sequence that repeats after 65535 cycles.

If the taps do not create a maximal length sequence, then it will repeat after fewer cycles and will depend on the initial state.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…