Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Lfsr. Can somebody help me understand this code?

Status
Not open for further replies.

Ferfil

Newbie level 4
Newbie level 4
Joined
Sep 27, 2013
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top