1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 |
|
4 | entity noise_bit_gen is
|
5 | Generic ( n_invChain_osc1 : integer := 8;
|
6 | n_invChain_osc2 : integer := 12);
|
7 | Port ( rst : in std_logic;
|
8 | output : out std_logic);
|
9 | end noise_bit_gen;
|
10 |
|
11 | -- Quelle:
|
12 | -- https://www.mikrocontroller.net/articles/Digitaler_Rauschgenerator_im_FPGA
|
13 |
|
14 | architecture Behavioral of noise_bit_gen is
|
15 |
|
16 | constant k1 : integer := 13;
|
17 | constant k2 : integer := 27;
|
18 |
|
19 | constant n_invChain_secondBlock : integer := 4;
|
20 |
|
21 | signal cnt1 : integer range 0 to k1 := 0;
|
22 | signal cnt2 : integer range 0 to k2 := 0;
|
23 |
|
24 | signal invChain_osc1 : std_logic_vector(n_invChain_osc1 - 1 downto 0) := (others => '0');
|
25 | signal invChain_osc2 : std_logic_vector(n_invChain_osc2 - 1 downto 0) := (others => '0');
|
26 |
|
27 | signal invChain_secondBlock_1 : std_logic_vector(n_invChain_secondBlock - 1 downto 0) := (others => '0');
|
28 | signal invChain_secondBlock_2 : std_logic_vector(n_invChain_secondBlock - 1 downto 0) := (others => '0');
|
29 |
|
30 | signal mux1_out : std_logic := '0';
|
31 | signal mux2_out : std_logic := '0';
|
32 |
|
33 | signal short_feedback_osc1 : std_logic := '0';
|
34 | signal short_feedback_osc2 : std_logic := '0';
|
35 |
|
36 |
|
37 | attribute dont_touch : string;
|
38 | attribute dont_touch of cnt1 : signal is "true";
|
39 | attribute dont_touch of cnt2 : signal is "true";
|
40 | attribute dont_touch of invChain_osc1 : signal is "true";
|
41 | attribute dont_touch of invChain_osc2 : signal is "true";
|
42 | attribute dont_touch of invChain_secondBlock_1 : signal is "true";
|
43 | attribute dont_touch of invChain_secondBlock_2 : signal is "true";
|
44 | attribute dont_touch of mux1_out : signal is "true";
|
45 | attribute dont_touch of mux2_out : signal is "true";
|
46 | attribute dont_touch of short_feedback_osc1 : signal is "true";
|
47 | attribute dont_touch of short_feedback_osc2 : signal is "true";
|
48 |
|
49 |
|
50 | begin
|
51 |
|
52 | ----------------------------------------------------------------------------
|
53 | -- OSC 1
|
54 |
|
55 | -- inverter chain OSC1
|
56 | invChain_osc1(0) <= not(mux2_out) when (rst = '0') else '0';
|
57 | invChain_osc1(1) <= not(invChain_osc1(0)) when (rst = '0') else '0';
|
58 | invChain_osc1(2) <= not(invChain_osc1(1)) when (rst = '0') else '0';
|
59 | invChain_osc1(3) <= not(invChain_osc1(2)) when (rst = '0') else '0';
|
60 | invChain_osc1(4) <= not(invChain_osc1(3)) when (rst = '0') else '0';
|
61 | invChain_osc1(5) <= not(invChain_osc1(4)) when (rst = '0') else '0';
|
62 | invChain_osc1(6) <= not(invChain_osc1(5)) when (rst = '0') else '0';
|
63 | invChain_osc1(7) <= not(invChain_osc1(6)) when (rst = '0') else '0';
|
64 |
|
65 | -- signle inverter
|
66 | short_feedback_osc1 <= not(invChain_osc1(invChain_osc1'left)) when (rst = '0') else '0';
|
67 |
|
68 | -- inverter chain OSC1 second block
|
69 | invChain_secondBlock_1(0) <= not(short_feedback_osc1) when (rst = '0') else '0';
|
70 | invChain_secondBlock_1(1) <= not(invChain_secondBlock_1(0)) when (rst = '0') else '0';
|
71 | invChain_secondBlock_1(2) <= not(invChain_secondBlock_1(1)) when (rst = '0') else '0';
|
72 | invChain_secondBlock_1(3) <= not(invChain_secondBlock_1(2)) when (rst = '0') else '0';
|
73 |
|
74 | -- counter for OSC1
|
75 | process
|
76 | begin
|
77 | wait until rising_edge(invChain_osc1(invChain_osc1'left));
|
78 | if cnt1 < k1 then
|
79 | cnt1 <= cnt1 + 1;
|
80 | else
|
81 | cnt1 <= 0;
|
82 | end if;
|
83 | end process;
|
84 |
|
85 | -- comparator and multiplexer
|
86 | mux1_out <= short_feedback_osc1 when (cnt1 < (k1/2)) else
|
87 | invChain_secondBlock_1(3);
|
88 |
|
89 | ----------------------------------------------------------------------------
|
90 | ----------------------------------------------------------------------------
|
91 |
|
92 |
|
93 | ----------------------------------------------------------------------------
|
94 | -- OSC 2
|
95 |
|
96 | -- inverter chain OSC1
|
97 | invChain_osc2(0) <= not(mux1_out) when (rst = '0') else '0';
|
98 | invChain_osc2(1) <= not(invChain_osc2(0)) when (rst = '0') else '0';
|
99 | invChain_osc2(2) <= not(invChain_osc2(1)) when (rst = '0') else '0';
|
100 | invChain_osc2(3) <= not(invChain_osc2(2)) when (rst = '0') else '0';
|
101 | invChain_osc2(4) <= not(invChain_osc2(3)) when (rst = '0') else '0';
|
102 | invChain_osc2(5) <= not(invChain_osc2(4)) when (rst = '0') else '0';
|
103 | invChain_osc2(6) <= not(invChain_osc2(5)) when (rst = '0') else '0';
|
104 | invChain_osc2(7) <= not(invChain_osc2(6)) when (rst = '0') else '0';
|
105 | invChain_osc2(8) <= not(invChain_osc2(7)) when (rst = '0') else '0';
|
106 | invChain_osc2(9) <= not(invChain_osc2(8)) when (rst = '0') else '0';
|
107 | invChain_osc2(10) <= not(invChain_osc2(9)) when (rst = '0') else '0';
|
108 | invChain_osc2(11) <= not(invChain_osc2(10)) when (rst = '0') else '0';
|
109 |
|
110 | -- signle inverter
|
111 | short_feedback_osc2 <= not(invChain_osc2(invChain_osc2'left)) when (rst = '0') else '0';
|
112 |
|
113 | -- inverter chain OSC1 second block
|
114 | invChain_secondBlock_2(0) <= not(short_feedback_osc2) when (rst = '0') else '0';
|
115 | invChain_secondBlock_2(1) <= not(invChain_secondBlock_2(0)) when (rst = '0') else '0';
|
116 | invChain_secondBlock_2(2) <= not(invChain_secondBlock_2(1)) when (rst = '0') else '0';
|
117 | invChain_secondBlock_2(3) <= not(invChain_secondBlock_2(2)) when (rst = '0') else '0';
|
118 |
|
119 | -- counter for OSC1
|
120 | process
|
121 | begin
|
122 | wait until rising_edge(invChain_osc2(invChain_osc2'left));
|
123 | if cnt2 < k2 then
|
124 | cnt2 <= cnt2 + 1;
|
125 | else
|
126 | cnt2 <= 0;
|
127 | end if;
|
128 | end process;
|
129 |
|
130 | -- comparator and multiplexer
|
131 | mux2_out <= short_feedback_osc2 when (cnt2 < (k2/2)) else
|
132 | invChain_secondBlock_2(3);
|
133 |
|
134 | ----------------------------------------------------------------------------
|
135 | ----------------------------------------------------------------------------
|
136 |
|
137 |
|
138 | ----------------------------------------------------------------------------
|
139 | -- output
|
140 |
|
141 | output <= invChain_osc1(invChain_osc1'left) XOR invChain_osc2(invChain_osc2'left);
|
142 |
|
143 | ----------------------------------------------------------------------------
|
144 | ----------------------------------------------------------------------------
|
145 |
|
146 | end Behavioral;
|