-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRand_8bits.vhd
54 lines (46 loc) · 1.27 KB
/
Rand_8bits.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
--Pseudorandom number generator
-- Repository:
-- https://github.com/vasanza/MSI-VHDL
-- Read more:
-- https://vasanza.blogspot.com
--By: Angel Zumba and Jose Marquez (2021PAO1)
--Library
library ieee;
use ieee.std_logic_1164.all;
--Entity
entity Rand_8bits is
port (clk : in std_logic;
reset: in std_logic;
load: in std_logic;
seed: in std_logic_vector (7 downto 0);
random: out std_logic_vector (7 downto 0));
end Rand_8bits;
--Architecture
architecture funcional of Rand_8bits is
-- Signals,Constants,Variables,Components
signal lfsr_reg: std_logic_vector(7 downto 0);
begin
--Process #1
process(clk, reset)
--Sequential programming
begin
if (reset = '1') then
lfsr_reg <= (others => '0');
elsif (clk'event and clk = '1') then
if (load = '1') then
lfsr_reg <= seed;
else
lfsr_reg(0) <= lfsr_reg(7);
lfsr_reg(1) <= lfsr_reg(0);
lfsr_reg(2) <= lfsr_reg(1) xnor lfsr_reg(7);
lfsr_reg(3) <= lfsr_reg(2) xnor lfsr_reg(7);
lfsr_reg(4) <= lfsr_reg(3) xnor lfsr_reg(7);
lfsr_reg(5) <= lfsr_reg(4);
lfsr_reg(6) <= lfsr_reg(5);
lfsr_reg(7) <= lfsr_reg(6);
end if;
end if;
end process;
random <= lfsr_reg;
--Process #n...
end funcional;