OpenCores
Issue List
The pseudo random number generator of srio_pcs_struct is incorrect #4
Closed magro732 opened this issue over 9 years ago
magro732 commented over 9 years ago

The pseudo_random_number_generator in srio_pcs_struct is incorrect. It does not generate random numbers with the expected randomness of a 7:th degree polynom.

magro732 commented over 9 years ago

The following code will generate a random number with the expected randomness.


--

entity pseudo_random_number_generator is port( clk : in std_logic; areset_n : in std_logic; enable : in std_logic;

q_o : out std_logic_vector(3 downto 0);
randomBit_o : out std_logic);

end entity;


--

architecture behavioral of pseudo_random_number_generator is signal lfsr : std_logic_vector(7 downto 1); signal q0 : std_logic;

begin

-- Output assignment. q_o <= lfsr(6) & lfsr(4) & lfsr(3) & lfsr(1); randomBit_o <= lfsr(7);

-- P(x) = x^7 + x^6 + 1 -- This is a maximal-length polynomial and repeats itself after 127 ticks. q0 <= lfsr(7) xor lfsr(6);

process(clk, areset_n) begin if areset_n = '0' then lfsr <= "0000001"; elsif rising_edge(clk) then if (enable = '1') then lfsr <= lfsr(6 downto 1) & q0; end if; end if; end process;

end architecture;

azdem was assigned over 9 years ago
magro732 commented over 9 years ago

entity pseudo_random_number_generator is port( clk : in std_logic; areset_n : in std_logic; enable : in std_logic;

q_o : out std_logic_vector(3 downto 0);
randomBit_o : out std_logic);

end entity;

architecture behavioral of pseudo_random_number_generator is signal lfsr : std_logic_vector(7 downto 1); signal q0 : std_logic;

begin

-- Output assignment. q_o <= lfsr(6) & lfsr(4) & lfsr(3) & lfsr(1); randomBit_o <= lfsr(7);

-- P(x) = x^7 + x^6 + 1 -- This is a maximal-length polynomial and repeats itself after 127 ticks. q0 <= lfsr(7) xor lfsr(6);

process(clk, areset_n) begin if areset_n = '0' then lfsr <= "0000001"; elsif rising_edge(clk) then if (enable = '1') then lfsr <= lfsr(6 downto 1) & q0; end if; end if; end process;

end architecture;

magro732 closed this over 9 years ago
magro732 commented over 9 years ago

hrmf cannot past code into this window :-(


Assignee
azdem
Labels
Request