I want to generate sine wave in vhdl
1 | library ieee; |
2 | use ieee.std_logic_1164.all; |
3 | use ieee.numeric_std.all; |
4 | |
5 | entity simple_sine_gen is |
6 | port
|
7 | (
|
8 | clk : in std_ulogic; |
9 | --
|
10 | sine : out signed( 7 downto 0) |
11 | );
|
12 | end entity simple_sine_gen; |
13 | |
14 | architecture rtl of simple_sine_gen is |
15 | |
16 | constant amplitude : natural := 15; -- max. 15 |
17 | constant frequency : natural := 1; -- 1..16(?) |
18 | --
|
19 | constant value : natural := 512; |
20 | |
21 | type reg_t is record |
22 | x : signed( 15 downto 0); |
23 | xt : signed( 15 downto 0); |
24 | xa : signed( 15 downto 0); |
25 | y : signed( 15 downto 0); |
26 | yt : signed( 15 downto 0); |
27 | ya : signed( 15 downto 0); |
28 | end record; |
29 | constant default_reg_c : reg_t := |
30 | (
|
31 | x => to_signed( 0, 16), |
32 | xt => ( others => '0'), |
33 | xa => ( others => '0'), |
34 | y => to_signed( amplitude * value, 16), |
35 | yt => ( others => '0'), |
36 | ya => ( others => '0') |
37 | );
|
38 | |
39 | signal r : reg_t := default_reg_c; |
40 | signal r_in : reg_t := default_reg_c; |
41 | |
42 | begin
|
43 | |
44 | |
45 | comb: process( r) |
46 | variable v : reg_t; |
47 | begin
|
48 | v := r; |
49 | |
50 | -- output
|
51 | sine <= resize( shift_right( v.x, 6), 8); |
52 | |
53 | -- calculation
|
54 | v.xa := v.x + v.xt; |
55 | v.xt := resize( frequency * v.ya / value, 16); |
56 | v.x := v.x + v.xt; |
57 | |
58 | v.ya := v.y - v.yt; |
59 | v.yt := resize( frequency * v.xa / value, 16); |
60 | v.y := v.y - v.yt; |
61 | |
62 | r_in <= v; |
63 | end process; |
64 | |
65 | |
66 | seq : process |
67 | begin
|
68 | wait until rising_edge(clk); |
69 | r <= r_in; |
70 | end process; |
71 | |
72 | end architecture rtl; |
Can you explain how it works?
Thanks to Duke, you now know about the way to realise 2 stage diff equations in VHDL. Anyway you should have been able to figure that out yourself.
Sheikh S. wrote: > I want to generate sine wave in vhdl And what's the problem? How far did you get? How can we help?
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
Log in with Google account
No account? Register here.