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?
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?