summaryrefslogtreecommitdiff
path: root/FPGA/vhdl/dds_sinus.vhd
diff options
context:
space:
mode:
Diffstat (limited to 'FPGA/vhdl/dds_sinus.vhd')
-rw-r--r--FPGA/vhdl/dds_sinus.vhd101
1 files changed, 101 insertions, 0 deletions
diff --git a/FPGA/vhdl/dds_sinus.vhd b/FPGA/vhdl/dds_sinus.vhd
new file mode 100644
index 0000000..d47f290
--- /dev/null
+++ b/FPGA/vhdl/dds_sinus.vhd
@@ -0,0 +1,101 @@
1----------------------------------------------------
2-- DDS : sinus
3----------------------------------------------------
4-- ESIEE
5-- creation : A. Exertier, 06/2009
6-- modification : A. Exertier, 12/2011
7----------------------------------------------------
8
9library ieee;
10use ieee.std_logic_1164.all;
11use ieee.numeric_std.all;
12-----------------------------------------------------
13-- GENERIC PARAMETER
14-----------------------------------------------------
15-- N_data : output data number of bits
16-- M : phase accumulator precision
17-- amplitude : sinus amplitude
18-- should be < 2**N_data
19-----------------------------------------------------
20-- INPUTS
21-----------------------------------------------------
22-- clk : clock
23-- resetn : asynchronous reset (active low)
24-- incr_step : incrementation step (N_adr_ROM bits)
25-- => sinus frequency
26-----------------------------------------------------
27-- OUTPUT
28-----------------------------------------------------
29-- dds_out : output data (N_data bits)
30-----------------------------------------------------
31
32entity dds_sinus is
33 generic(
34 N_data : positive := 16;
35 M : positive := 12
36 );
37 port (
38 resetn : in std_logic;
39 clk : in std_logic;
40 en : in std_logic;
41 incr_step : in std_logic_vector(M-1 downto 0);
42 dds_out : out std_logic_vector(N_data-1 downto 0)
43 );
44end dds_sinus;
45
46architecture RTL of dds_sinus is
47 constant amplitude : positive :=2**(N_data-1)-1;
48 constant N_adr_ROM : positive := M-2;
49 constant middle : unsigned (N_data-1 downto 0) := to_unsigned(2**(dds_out'length-1),dds_out'length); --(N_data-1=>'1', others => '0');
50
51 signal counter : unsigned(N_adr_ROM+1 downto 0);
52 signal address_sinus : std_logic_vector(N_adr_ROM-1 downto 0);
53 signal data_sinus : std_logic_vector(N_data-2 downto 0);
54 signal dds_out_int : std_logic_vector(dds_out'range);
55
56 begin
57------------------------------------
58-- counter & output register
59------------------------------------
60 process(resetn, clk) is
61 begin
62 if resetn = '0' then
63 counter <= (others => '0');
64 dds_out <= (others => '0');
65 dds_out(dds_out'high) <= '1';
66 elsif rising_edge(clk) then
67 if en = '1' then
68 counter <= counter+unsigned(incr_step);
69 dds_out <= dds_out_int;
70 end if;
71 end if;
72 end process;
73
74-------------------------------------
75-- address & signed output
76-------------------------------------
77
78address_sinus <= std_logic_vector(counter(address_sinus'range))
79 when counter <2**(N_adr_ROM) or (counter >= 2**(N_adr_ROM+1) and counter <2**(N_adr_ROM)*3)
80 else std_logic_vector(2**(N_adr_ROM)-1 - counter(address_sinus'range)) ;
81
82dds_out_int <= std_logic_vector(middle - unsigned(data_sinus))
83 when (counter >=(2**(N_adr_ROM+1)) + unsigned(incr_step)) or (counter <unsigned(incr_step))
84 else std_logic_vector(middle + unsigned(data_sinus));
85
86------------------------------------------------------
87-- sinus : fonction tabulee du quart de sinus
88------------------------------------------------------
89tab_sinus: entity work.rom_sinus
90 generic map (
91 N_data => N_data,
92 N_adr_ROM => N_adr_ROM,
93 amplitude => amplitude
94 )
95 port map(
96 address => address_sinus,
97 clk => clk,
98 data => data_sinus
99 );
100
101end architecture; \ No newline at end of file