Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

Do you use LPMs for your LFSRs?

I want to implement an LFSR as a means of generating random numbers but I'm not sure whether to use an LPM or just code it in a process. I would be interested to hear how you choose to implement them and if possible, why? I considered using either LPM_SHIFTREG or altshift_taps but I'm not sure how suitable they are. Many thanks

12 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks again Kaz. I can't quite see where I was going wrong

    
    process(reset,clock)
    begin
    if reset = '1' then
       shift_reg <= "0001"; -- seed
    elsif rising_edge(clock) then
       shift_reg(1) <= shift_reg(0) XOR shift_reg(3); -- taps
       shift_reg(2) <= shift_reg(1); -- shift
       shift_reg(3) <= shift_reg(2);
    end if;
    output    <=    shift_reg;
    end process;

    When I simulate this the output is always 1?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Either way you end up with shift register.

    Inference is easier and portable.

    example

    --

    signal shift_reg : std_logic_vector(33 downto 1);

    
    process(reset,clk)
    begin
    if reset = '1' then
       shift_reg <= '0' & x"28EA5CB1"; -- seed
    elsif rising_edge(clk) then
       shift_reg(1) <= shift_reg(20) xor shift_reg(33); -- taps
       shift_reg(33 downto 2) <= shift_reg(32 downto 1); -- shift
    end if;
    end process;

    the final output could be any number of bits you choose from the shift_reg

    however, my favorite method is read a text file.