1 |
2 |
lal87 |
----------------------------------------------------------------------------
|
2 |
|
|
---- Create Date: 13:06:08 07/28/2010 ----
|
3 |
|
|
---- Design Name: lfsr ----
|
4 |
|
|
---- Project Name: lfsr_randgen ----
|
5 |
|
|
---- Description: ----
|
6 |
|
|
---- A random number generator based on linear feedback shift ----
|
7 |
|
|
---- register(LFSR).A LFSR is a shift register whose input bit is a ----
|
8 |
|
|
---- linear function of its previous state.The detailed documentation ----
|
9 |
|
|
---- is available in the file named manual.pdf. ----
|
10 |
|
|
---- ----
|
11 |
|
|
----------------------------------------------------------------------------
|
12 |
|
|
---- ----
|
13 |
|
|
---- This file is a part of the lfsr_randgen project at ----
|
14 |
|
|
---- http://www.opencores.org/ ----
|
15 |
|
|
---- ----
|
16 |
|
|
---- Author(s): ----
|
17 |
|
|
---- Vipin Lal, lalnitt@gmail.com ----
|
18 |
|
|
---- ----
|
19 |
|
|
----------------------------------------------------------------------------
|
20 |
|
|
---- ----
|
21 |
|
|
---- Copyright (C) 2010 Authors and OPENCORES.ORG ----
|
22 |
|
|
---- ----
|
23 |
|
|
---- This source file may be used and distributed without ----
|
24 |
|
|
---- restriction provided that this copyright statement is not ----
|
25 |
|
|
---- removed from the file and that any derivative work contains ----
|
26 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
27 |
|
|
---- ----
|
28 |
|
|
---- This source file is free software; you can redistribute it ----
|
29 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
30 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
31 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
32 |
|
|
---- later version. ----
|
33 |
|
|
---- ----
|
34 |
|
|
---- This source is distributed in the hope that it will be ----
|
35 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
36 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
37 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
38 |
|
|
---- details. ----
|
39 |
|
|
---- ----
|
40 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
41 |
|
|
---- Public License along with this source; if not, download it ----
|
42 |
|
|
---- from http://www.opencores.org/lgpl.shtml ----
|
43 |
|
|
---- ----
|
44 |
|
|
----------------------------------------------------------------------------
|
45 |
|
|
|
46 |
|
|
library ieee;
|
47 |
|
|
use ieee.std_logic_1164.all;
|
48 |
|
|
use ieee.std_logic_arith.all;
|
49 |
|
|
use ieee.std_logic_unsigned.all;
|
50 |
|
|
library work;
|
51 |
|
|
use work.lfsr_pkg.ALL;
|
52 |
|
|
|
53 |
|
|
entity lfsr is
|
54 |
3 |
lal87 |
generic (width : integer := 4);
|
55 |
2 |
lal87 |
port (clk : in std_logic;
|
56 |
3 |
lal87 |
set_seed : in std_logic;
|
57 |
2 |
lal87 |
seed : in std_logic_vector(width-1 downto 0);
|
58 |
|
|
rand_out : out std_logic_vector(width-1 downto 0)
|
59 |
|
|
);
|
60 |
|
|
end lfsr;
|
61 |
|
|
|
62 |
|
|
architecture Behavioral of lfsr is
|
63 |
|
|
|
64 |
|
|
begin
|
65 |
|
|
|
66 |
3 |
lal87 |
process(clk)
|
67 |
2 |
lal87 |
|
68 |
|
|
variable rand_temp : std_logic_vector (width-1 downto 0):=(0 => '1',others => '0');
|
69 |
|
|
variable temp : std_logic := '0';
|
70 |
|
|
|
71 |
|
|
begin
|
72 |
3 |
lal87 |
|
73 |
|
|
if(rising_edge(clk)) then
|
74 |
|
|
|
75 |
2 |
lal87 |
if(set_seed = '1') then
|
76 |
3 |
lal87 |
rand_temp := seed;
|
77 |
|
|
end if;
|
78 |
|
|
|
79 |
2 |
lal87 |
temp := xor_gates(rand_temp);
|
80 |
|
|
rand_temp(width-1 downto 1) := rand_temp(width-2 downto 0);
|
81 |
3 |
lal87 |
rand_temp(0) := temp;
|
82 |
|
|
|
83 |
2 |
lal87 |
end if;
|
84 |
3 |
lal87 |
rand_out <= rand_temp;
|
85 |
2 |
lal87 |
|
86 |
|
|
end process;
|
87 |
|
|
|
88 |
|
|
end Behavioral;
|
89 |
|
|
|