Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Am I implementing a LSFR correct?

Status
Not open for further replies.

nutkin

Programmer
Nov 1, 2008
1
0
0
US
I'm creating a simple simon says game for a class of mine and at the beginning of the game, I try to generate 16 pseudo-random 2-bit pairs and store them into an array called storage. Could anyone tell me if I did this correctly using a linear feedback shift register?


architecture Behavioral of controller is

signal storage : std_logic_vector(31 downto 0); --storage holds 16 2-bit pairs
signal LFSR : std_logic_vector(2 downto 0);
signal linear_feedback : std_logic;
signal ps, ns : std_logic_vector(3 downto 0) := "0000"; -- next state and prev state

begin
process(clk)
begin
if(clk = '1' and clk'EVENT) then
linear_feedback <= (not LSFR(1) xor LSFR(0));
LFSR <= LFSR(1) & LFSR(0) & linear_feedback;
end if;
end process;



Then in a separate process I have

begin
if(clk = '1' and clk'EVENT) then
case ps is

when "0001" =>
counter16 := counter16 + 1;
if(counter16 < 16) then
storage <= LFSR(1 downto 0) & storage(31 downto 2);
outputs <= "000";
ns <= "0001";
else
ns <= "0010";
end if;



I cut out some of the irrelevant code like the other states. Does this look kosher?
 
The first thing I ever designed in vhdl was a PRBS tester which had an LFSR at its core. Your state machine process looks good to me but in your LFSR process I am not sure why you are using:

linear_feedback <= (not LSFR(1) xor LSFR(0));

I'm not too sure what initial value you use as a seed in your code, but if you load it with a seed of '111', or when the lfsr reaches the '111' state then it will not get out it

t=x 111 --> loaded value
t=x+1 111 --> new tap = not 1 xor 1 = 1
t=x+2 111 --> new tap = not 1 xor 1 = 1...

It is my understanding of max length pseudo random lfsr's that for your tap linear_feedback you should be using either

linear_feedback <= (LFSR(1) xor LFSR(0)); or...

linear_feedback <= (LFSR(2) xnor LFSR(1));

Note - When using an XOR lfsr, a lock up state will occur if all '0's are input to the system or all '1's when using XNOR so be careful of this.

Xilinx have a basic application note on this that you may find helpful (XAPP052):


regards gg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top