summaryrefslogtreecommitdiff
path: root/FPGA/vhdl/rom_sinus.vhd
diff options
context:
space:
mode:
Diffstat (limited to 'FPGA/vhdl/rom_sinus.vhd')
-rw-r--r--FPGA/vhdl/rom_sinus.vhd75
1 files changed, 75 insertions, 0 deletions
diff --git a/FPGA/vhdl/rom_sinus.vhd b/FPGA/vhdl/rom_sinus.vhd
new file mode 100644
index 0000000..7b3ce2c
--- /dev/null
+++ b/FPGA/vhdl/rom_sinus.vhd
@@ -0,0 +1,75 @@
1----------------------------------------------------
2-- QUART de SINUS : SYNCHRONOUS ROM
3----------------------------------------------------
4-- ESIEE
5-- creation : A. Exertier, 06/2009
6-- modification : A. Exertier, 12/2011
7----------------------------------------------------
8
9
10library ieee;
11use ieee.std_logic_1164.all;
12use ieee.numeric_std.all;
13use ieee.math_real.all;
14
15-----------------------------------------------------
16-- GENERIC PARAMETER
17-----------------------------------------------------
18-- N_data : output data number of bits
19-- N_adr_ROM : address number of bits
20-- amplitude : sinus amplitude
21-- should be < 2**N_data
22-----------------------------------------------------
23-- INPUTS
24-----------------------------------------------------
25-- clk : clock
26-- address : ROM address
27-----------------------------------------------------
28-- OUTPUT
29-----------------------------------------------------
30-- data : output data
31-----------------------------------------------------
32
33entity rom_sinus is
34 generic (
35 N_data : natural := 14;
36 N_adr_ROM : natural := 8;
37 amplitude : natural := 1024
38 );
39 port (
40 clk : in std_logic;
41 address : in std_logic_vector(N_adr_ROM-1 downto 0);
42 data : out std_logic_vector(N_data-2 downto 0));
43
44end entity rom_sinus;
45
46architecture RTL of rom_sinus is
47 subtype DAC_data_type is std_logic_vector (N_data-2 downto 0);
48 type memory_type is array (0 to 2**N_adr_ROM-1) of DAC_data_type;
49
50 function sinus_tabule return memory_type is
51 variable temp : memory_type;
52 variable sinus_real : real;
53 begin
54 for i in 0 to 2**N_adr_ROM-1 loop
55 sinus_real := real(amplitude)*(sin(math_pi_over_2 * real(i)/real(2**N_adr_ROM)));
56 if integer(sinus_real)= 2**(N_data-1) then
57 temp(i) := (others => '1');
58 else
59 temp(i) := std_logic_vector(to_unsigned(integer(sinus_real), N_data-1));
60 end if;
61 end loop;
62 return temp;
63 end sinus_tabule;
64
65 constant memory_values : memory_type := sinus_tabule;
66
67begin
68
69 process(clk) is
70 begin
71 if rising_edge(clk) then data<= memory_values(to_integer(unsigned(address)));
72 end if;
73 end process;
74
75end RTL;