OpenCores
URL https://opencores.org/ocsvn/waveform_gen/waveform_gen/trunk

Subversion Repositories waveform_gen

[/] [waveform_gen/] [trunk/] [vhdl/] [waveform_gen.vhd] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sdoherty
----------------------------------------------------------------------
2
--                                                                  --
3
--  THIS VHDL SOURCE CODE IS PROVIDED UNDER THE GNU PUBLIC LICENSE  --
4
--                                                                  --
5
----------------------------------------------------------------------
6
--                                                                  --
7
--    Filename            : waveform_gen.vhd                        --
8
--                                                                  --
9
--    Author              : Simon Doherty                           --
10
--                          Senior Design Consultant                --
11
--                          www.zipcores.com                        --
12
--                                                                  --
13 4 sdoherty
--    Date last modified  : 24.10.2008                              --
14 2 sdoherty
--                                                                  --
15
--    Description         : NCO / Periodic Waveform Generator       --
16
--                                                                  --
17
----------------------------------------------------------------------
18
 
19
 
20
library ieee;
21
use ieee.std_logic_1164.all;
22
use ieee.std_logic_arith.all;
23
 
24
 
25
entity waveform_gen is
26
 
27
port (
28
 
29
  -- system signals
30
  clk         : in  std_logic;
31
  reset       : in  std_logic;
32
 
33 4 sdoherty
  -- clock-enable
34
  en          : in  std_logic;
35
 
36 2 sdoherty
  -- NCO frequency control
37
  phase_inc   : in  std_logic_vector(31 downto 0);
38
 
39
  -- Output waveforms
40
  sin_out     : out std_logic_vector(11 downto 0);
41
  cos_out     : out std_logic_vector(11 downto 0);
42
  squ_out     : out std_logic_vector(11 downto 0);
43
  saw_out     : out std_logic_vector(11 downto 0) );
44
 
45
end entity;
46
 
47
 
48
architecture rtl of waveform_gen is
49
 
50
 
51
component sincos_lut
52
 
53
port (
54
 
55
  clk      : in  std_logic;
56 4 sdoherty
  en       : in  std_logic;
57 2 sdoherty
  addr     : in  std_logic_vector(11 downto 0);
58
  sin_out  : out std_logic_vector(11 downto 0);
59
  cos_out  : out std_logic_vector(11 downto 0));
60
 
61
end component;
62
 
63
 
64
signal  phase_acc     : std_logic_vector(31 downto 0);
65
signal  lut_addr      : std_logic_vector(11 downto 0);
66
signal  lut_addr_reg  : std_logic_vector(11 downto 0);
67
 
68
 
69
begin
70
 
71
 
72
--------------------------------------------------------------------------
73
-- Phase accumulator increments by 'phase_inc' every clock cycle        --
74
-- Output frequency determined by formula: Phase_inc = (Fout/Fclk)*2^32 --
75
-- E.g. Fout = 36MHz, Fclk = 100MHz,  Phase_inc = 36*2^32/100           --
76
-- Frequency resolution is 100MHz/2^32 = 0.00233Hz                      --
77
--------------------------------------------------------------------------
78
 
79
phase_acc_reg: process(clk, reset)
80
begin
81
  if reset = '0' then
82
    phase_acc <= (others => '0');
83
  elsif clk'event and clk = '1' then
84 4 sdoherty
    if en = '1' then
85
      phase_acc <= unsigned(phase_acc) + unsigned(phase_inc);
86
    end if;
87 2 sdoherty
  end if;
88
end process phase_acc_reg;
89
 
90
---------------------------------------------------------------------
91
-- use top 12-bits of phase accumulator to address the SIN/COS LUT --
92
---------------------------------------------------------------------
93
 
94
lut_addr <= phase_acc(31 downto 20);
95
 
96
----------------------------------------------------------------------
97
-- SIN/COS LUT is 4096 by 12-bit ROM                                --
98
-- 12-bit output allows sin/cos amplitudes between 2047 and -2047   --
99
-- (-2048 not used to keep the output signal perfectly symmetrical) --
100
-- Phase resolution is 2Pi/4096 = 0.088 degrees                     --
101
----------------------------------------------------------------------
102
 
103
lut: sincos_lut
104
 
105
  port map (
106
 
107
    clk       => clk,
108 4 sdoherty
    en        => en,
109 2 sdoherty
    addr      => lut_addr,
110
    sin_out   => sin_out,
111
    cos_out   => cos_out );
112
 
113
---------------------------------
114
-- Hide the latency of the LUT --
115
---------------------------------
116
 
117
delay_regs: process(clk)
118
begin
119
  if clk'event and clk = '1' then
120 4 sdoherty
    if en = '1' then
121
      lut_addr_reg <= lut_addr;
122
    end if;
123 2 sdoherty
  end if;
124
end process delay_regs;
125
 
126
---------------------------------------------
127
-- Square output is msb of the accumulator --
128
---------------------------------------------
129
 
130
squ_out <= "011111111111" when lut_addr_reg(11) = '1' else "100000000000";
131
 
132
-------------------------------------------------------
133
-- Sawtooth output is top 12-bits of the accumulator --
134
-------------------------------------------------------
135
 
136
saw_out <= lut_addr_reg;
137
 
138
 
139
end rtl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.