1 | library ieee;
|
2 | use ieee.std_logic_1164.all;
|
3 | use ieee.numeric_std.all;
|
4 | use work.sine_package.all;
|
5 |
|
6 | entity adc_out is
|
7 | port (
|
8 | clock : in std_logic;
|
9 | SPI_SCK : out std_logic;
|
10 | SPI_MOSI : out std_logic;
|
11 | DAC_CLR : out std_logic;
|
12 | DAC_CS : out std_logic;
|
13 | led : out std_logic_vector(7 downto 0);
|
14 | BTN_SOUTH : in std_logic; -- enable
|
15 | BTN_EAST : in std_logic; -- reset
|
16 | Rot_Center : in std_logic
|
17 | );
|
18 | end entity adc_out;
|
19 |
|
20 | architecture rtl of adc_out is
|
21 |
|
22 | component sekunden_takt
|
23 | port
|
24 | (
|
25 | clock : in std_logic;
|
26 | takt : out std_logic
|
27 | );
|
28 | end component sekunden_takt;
|
29 |
|
30 | component square_wave
|
31 | port (
|
32 | clock : in std_logic; -- Systemclock Pin
|
33 | wave_out : out signed(11 downto 0)
|
34 | );
|
35 | end component square_wave;
|
36 |
|
37 | component sine_wave
|
38 | port
|
39 | (
|
40 | clock : in std_logic;
|
41 | reset : in std_logic;
|
42 | enable : in std_logic;
|
43 | wave_out : out signed(11 downto 0)
|
44 | );
|
45 | end component sine_wave;
|
46 |
|
47 | type wave_mod is (sine_wave_mod, square_wave_mod);
|
48 | signal modus : wave_mod := square_wave_mod;
|
49 |
|
50 | type dacStateType is (idle, sendBit, clockHigh, csHigh);
|
51 | signal dacState : dacStateType := idle;
|
52 | signal enable : std_logic := '1';
|
53 | signal old_BTN_SOUTH : std_logic;
|
54 | signal old_Rot_Center : std_logic;
|
55 | signal reset : std_logic := '0';
|
56 | signal sine_wave_out : signed(11 downto 0);
|
57 | signal square_wave_out : signed(11 downto 0);
|
58 | signal output : unsigned(11 downto 0);
|
59 | -- 32 Bit Format
|
60 | signal dacCounter : integer range 0 to 31;
|
61 | signal DAC_OUT : unsigned(31 downto 0);
|
62 | signal takt : std_logic;
|
63 |
|
64 | begin
|
65 |
|
66 | takt_teiler : sekunden_takt
|
67 | port map
|
68 | (
|
69 | clock => clock,
|
70 | takt => takt
|
71 | );
|
72 |
|
73 | square_wave_label : square_wave
|
74 | port map
|
75 | (
|
76 | clock => clock,
|
77 | wave_out => square_wave_out
|
78 | );
|
79 |
|
80 | sine_wave_label : sine_wave
|
81 | port map
|
82 | (
|
83 | clock => clock,
|
84 | reset => BTN_EAST,
|
85 | enable => enable,
|
86 | wave_out => sine_wave_out
|
87 | );
|
88 |
|
89 | ----------------------------------------------------------------------------------------
|
90 |
|
91 | process (clock, BTN_SOUTH)
|
92 | begin
|
93 | if rising_edge(clock)
|
94 | then
|
95 | old_BTN_SOUTH <= BTN_SOUTH;
|
96 | -- Erkennung der steigenden Flanke
|
97 | if old_BTN_SOUTH = '0' and BTN_SOUTH = '1'
|
98 | then
|
99 | if enable = '0'
|
100 | then
|
101 | enable <= '1';
|
102 | else
|
103 | enable <= '0';
|
104 | end if;
|
105 | end if;
|
106 | end if;
|
107 | end process;
|
108 |
|
109 | process (clock, BTN_EAST)
|
110 | begin
|
111 | if rising_edge(clock)
|
112 | then
|
113 | if BTN_EAST = '1'
|
114 | then
|
115 | reset <= not reset;
|
116 | end if;
|
117 | end if;
|
118 | end process;
|
119 |
|
120 | ----------------------------------------------------------------------------------------
|
121 |
|
122 | leds : process (clock)
|
123 | begin
|
124 | if rising_edge(clock)
|
125 | then
|
126 | if modus = square_wave_mod
|
127 | then
|
128 | led(7 downto 6) <= "10";
|
129 | elsif modus = sine_wave_mod
|
130 | then
|
131 | led(7 downto 6) <= "01";
|
132 | end if;
|
133 | led(5 downto 2) <= "0000";
|
134 | led(1) <= enable;
|
135 | led(0) <= reset;
|
136 | end if;
|
137 | end process;
|
138 |
|
139 | -- rotary_knob : process (clock)
|
140 | -- begin
|
141 | -- if rising_edge(clock)
|
142 | -- then
|
143 | -- old_Rot_Center <= Rot_Center;
|
144 | -- -- Erkennung der Taktflanke
|
145 | -- if old_Rot_Center = '0' and Rot_Center = '1'
|
146 | -- then
|
147 | -- if modus /= wave_mod'high
|
148 | -- then
|
149 | -- modus <= wave_mod'succ(modus);
|
150 | -- else
|
151 | -- modus <= wave_mod'low;
|
152 | -- end if;
|
153 | -- end if;
|
154 | -- end if;
|
155 | -- end process;
|
156 |
|
157 | ----------------------------------------------------------------------------------------
|
158 |
|
159 | process(clock, enable)
|
160 | begin
|
161 | if enable = '0'
|
162 | then
|
163 | dacState <= idle;
|
164 | elsif rising_edge(clock)
|
165 | then
|
166 | -- Wellenform berücksichtigen
|
167 | if modus = sine_wave_mod
|
168 | then
|
169 | output <= unsigned(sine_wave_out);
|
170 | elsif modus = square_wave_mod
|
171 | then
|
172 | output <= unsigned(square_wave_out);
|
173 | end if;
|
174 |
|
175 | -- Daten an den ADC senden
|
176 | case dacState is
|
177 | when idle =>
|
178 | -- if takt = '1'
|
179 | -- then
|
180 | DAC_CS <= '0';
|
181 | SPI_SCK <= '0';
|
182 | dacState <= sendBit;
|
183 | dacCounter <= 31;
|
184 | -- 32 Bit Format
|
185 | -- 4Bit Dont care & output & Address & Command & 8Bit Dont care
|
186 | DAC_OUT <= "0000" & output & "1111" & "0011" & "00000000";
|
187 | -- end if;
|
188 | when sendBit =>
|
189 | SPI_SCK <= '0';
|
190 | -- SPI_MOSI <= DAC_OUT(23);
|
191 | SPI_MOSI <= DAC_OUT(31);
|
192 | DAC_OUT <= DAC_OUT(30 downto 0) & "0";
|
193 | dacState <= clockHigh;
|
194 | when clockHigh =>
|
195 | SPI_SCK <= '1';
|
196 | if dacCounter = 0
|
197 | then
|
198 | dacState <= csHigh;
|
199 | else
|
200 | dacCounter <= dacCounter - 1;
|
201 | dacState <= sendBit;
|
202 | end if;
|
203 | when csHigh =>
|
204 | DAC_CS <= '1';
|
205 | dacState <= idle;
|
206 | end case;
|
207 | end if;
|
208 | end process;
|
209 |
|
210 | DAC_CLR <= '1';
|
211 |
|
212 | end architecture rtl;
|