Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LIBRARY IEEE;
- USE IEEE.Std_Logic_1164.ALL;
- use WORK.convpack.all;
- entity randomGen is
- generic (n:integer := 13; -- bit width
- pl:integer := 220);
- port (clock,reset: in STD_LOGIC;
- y: out STD_LOGIC_VECTOR(n-1 downto 0);
- pulse:out STD_LOGIC);
- end randomGen;
- architecture a01 of randomGen is
- type intArray is array (positive range <>) of integer;
- constant feedBackTable: intArray(1 to 5*15) :=
- -----------------------------------------------------------
- -- This table implements the taps, for the EXOR-feedback
- -- in the pseudo random generator.
- -- in the first column we have the number of feedbacks, for
- -- the bitWidth, indicated on the right side in the comment.
- -- the following numbers in a line are the feedback taps,
- -- we start counting positions from zero
- -- taps | positions
- ( 2, 0, 1, 0, 0, -- for the minimum bitWith of 2
- 2, 2, 1, 0, 0, -- 3
- 2, 3, 2, 0, 0, -- 4
- 2, 4, 2, 0, 0, -- 5
- 2, 5, 4, 0, 0, -- 6
- 2, 6, 5, 0, 0, -- 7
- 4, 3, 4, 5, 7, -- 8
- 2, 8, 4, 0, 0, -- 9
- 2, 9, 6, 0, 0, -- 10
- 2, 10, 8, 0, 0, -- 11
- 0, 0, 0, 0, 0, -- no polynom for 12 bit found yet
- 0, 0, 0, 0, 0, -- neiter for 13 bit
- 0, 0, 0, 0, 0, -- neiter for 14 bit
- 2, 14,13, 0, 0, -- 15
- 4, 3, 12,14, 15);-- 16
- -- the following table is used to be able to synthesize the unit with 12,13
- -- and 14 bit, with an internal 15 bit register,
- -- the datawidth n will be replaced by internalN(n)
- constant internalN : intArray(2 to 32):=
- ( 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 );
- signal Q:STD_LOGIC_VECTOR(internalN(n)-1 downto 0);
- begin
- p01: process(reset,clock,Q)
- variable feedBack : STD_LOGIC;
- begin
- if (reset='1') then
- for i in (internalN(n)-1) downto 1 loop
- Q(i) <= '0';
- end loop;
- Q(0) <= '1';
- else
- if (clock'event) and (clock='1') then
- for i in 0 to internalN(n)-2 loop
- Q(i+1) <= Q(i);
- end loop;
- feedBack := Q(feedBackTable(5*internalN(n)+1-9));
- for i in 2 to feedBackTable(5*internalN(n)-9) loop
- feedBack := feedBack xor Q(feedBackTable(5*internalN(n)+i-9));
- end loop;
- Q(0) <= feedBack;
- end if;
- end if;
- if n < 16 then
- y <= Q(internalN(n)-1 downto internalN(n)-n);-- (others => '0');
- else
- y <= (others => '0'); -- ugly random distribution
- y( internalN(n)-1 downto 0 ) <= Q( internalN(n)-1 downto 0 );
- end if;
- if slv2int(Q) > pl then
- pulse <= '1';
- else
- pulse <= '0';
- end if;
- end process;
- end a01;
Add Comment
Please, Sign In to add comment