forked from fpgacourse/fpga_course_code
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaudio_vhdl.vhd
66 lines (57 loc) · 2.06 KB
/
audio_vhdl.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
55
56
57
58
59
60
61
62
63
64
65
66
----------------------------------------------------------------------------------
-- Engineer: Mike Field <[email protected]>
--
-- Module Name: audio_sos - Behavioral
-- Description: Sends out a "... - - - ... " using a saw tooth
-- wave through a 1 bit dac
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity audio_sos is
Port ( clk : in STD_LOGIC;
audio : out STD_LOGIC_VECTOR (1 downto 0));
end audio_sos;
architecture Behavioral of audio_sos is
signal nextDacSum1 : std_logic_vector(16 downto 0);
signal nextDacSum2 : std_logic_vector(16 downto 0);
type reg is record
modulation : std_logic_vector(47 downto 0);
counter : std_logic_vector(20 downto 0);
dac_sum : std_logic_vector(15 downto 0);
dac_out : std_logic;
end record;
signal r : reg := ( "10101000001110111011100000101010" & x"0000", (others => '0'), (others => '0'), '0');
signal n : reg;
begin
-- Assign the outputs
audio <= r.dac_out & r.dac_out;
-- the two options for the next value of the sigma/delta DAC
nextDacSum1 <= ("0" & r.dac_sum(15 downto 0)) + r.counter(16 downto 1);
nextDacSum2 <= ("0" & r.dac_sum(15 downto 0)) + "1000000000000000";
process(r, nextDacSum1,nextDacSum2)
begin
n.counter <= r.counter + 1;
-- shift the modulation through when the counter wraps
if r.counter = "00000000000000000000" then
n.modulation <= r.modulation(46 downto 0) & r.modulation(47);
else
n.modulation <= r.modulation;
end if;
-- decide if we make a tone or not
if r.modulation(0) = '1' then
n.dac_out <= nextDacSum1(16);
n.dac_sum <= nextDacSum1(15 downto 0);
else
n.dac_out <= nextDacSum2(16);
n.dac_sum <= nextDacSum2(15 downto 0);
end if;
end process;
process (clk, n)
begin
if rising_edge(clk) then
r <= n;
end if;
end process;
end Behavioral;