Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

VHDL code for implementing NCO

Status
Not open for further replies.

Sherif Welsen

Junior Member level 1
Junior Member level 1
Joined
Feb 3, 2005
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
135
Hi every body,

Could anybody provide me with a VHDL code implementing the Numerically Controlled Osc. NCO "DDS".

Added after 2 minutes:

Could you provide me with a resources describing the NCO, typical example using LUT or any other method that could be implemented on FPGAs.
 

nand_gates

Advanced Member level 3
Advanced Member level 3
Joined
Jul 19, 2004
Messages
899
Helped
175
Reputation
350
Reaction score
53
Trophy points
1,308
Activity points
7,037
sin vhdl

Hi,
Here is one example of Qadrature oscillator I build and testted on FPGA.
Its a sine wave oscillator.
I posted this code here some time back also it was in verilog.

Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity sine_cos is
  
  port (
    clk   : in  std_logic;
    reset : in  std_logic;
    en    : in  std_logic;
    sine  : buffer std_logic_vector(7 downto 0);
    cos   : buffer std_logic_vector(7 downto 0));

end sine_cos;
architecture behave_sine_cos of sine_cos is
signal sine_r, cos_r : std_logic_vector(7 downto 0);
begin  -- behave_sine_cos
 sine <= sine_r + (cos_r(7) & cos_r(7) & cos_r(7) & cos_r(7 downto 3));
 cos  <= cos_r - (sine(7) & sine(7) & sine(7) & sine(7 downto 3));
   
registers: process (clk, reset)
begin  -- process registers
  if reset = '0' then                   -- asynchronous reset (active low)
    sine_r <= "00000000";    
    cos_r <= "01111000";
  elsif clk'event and clk = '1' then    -- rising clock edge
    if (en = '1') then
      sine_r <= sine;
      cos_r <= cos;      
    end if;
  end if;
end process registers;
end behave_sine_cos;

-------------------------------------------------------------------------------
-- Testbench
-------------------------------------------------------------------------------

library ieee;
use ieee.std_logic_1164.all;

entity sine_cos_tb is
  
end sine_cos_tb;
architecture behave of sine_cos_tb is
component sine_cos
  port (
    clk   : in  std_logic;
    reset : in  std_logic;
    en    : in  std_logic;
    sine  : buffer std_logic_vector(7 downto 0);
    cos   : buffer std_logic_vector(7 downto 0));
end component;
signal    clk   : std_logic := '0';
signal    reset : std_logic := '0';
signal    en    : std_logic := '1';
signal    sine  : std_logic_vector(7 downto 0);
signal    cos   : std_logic_vector(7 downto 0);

begin  -- behave
clk <= transport not clk after 5 ns;

u1 : sine_cos
      port map (
        clk   , 
        reset , 
        en    , 
        sine  , 
        cos    );
process
  begin  -- process
    wait for 50 ns;
    reset <= '1';
    wait for 10000 ns;
    wait;
  end process;  

end behave;

Hope this helps
 

Renjith

Full Member level 3
Full Member level 3
Joined
Jan 3, 2005
Messages
173
Helped
15
Reputation
30
Reaction score
6
Trophy points
1,298
Location
India
Activity points
1,710
nco architecture

Hi Sherif,
An NCO design has got just 2 major blocks.
Phase accumulator, LUT Rom( to store the phase angles of sine and cos).
I've attached a NCO design document, this gives a detailed explanation for the blocks i mentioned above.
Hope this helps
 

Black Jack

Full Member level 4
Full Member level 4
Joined
Dec 2, 2003
Messages
236
Helped
14
Reputation
28
Reaction score
3
Trophy points
1,298
Location
UKRAINE
Activity points
1,817
vhdl nco design

Thank for example.
But I can`t understand how sin and cos obtained.
CORDIC or other methods?
Could you share with this information (app. notes, data sheet, books)

Best Regards,
Victor
 

nand_gates

Advanced Member level 3
Advanced Member level 3
Joined
Jul 19, 2004
Messages
899
Helped
175
Reputation
350
Reaction score
53
Trophy points
1,308
Activity points
7,037
an nco design has got just 2 major blocks.

Hi,

Sine and cos waves are generated using Quadrature oscillator.
If you integrate sine wave you get cosine wave You integrate this cosine
wave to generate input sine wave...
This is done using digital filter techniqe here in the VHDL code...
Following figure will explain it well....


Code:
         +----+      +----+
   sine  | /  | -cos | /  |
    +--->| |  |----->| |  |---+
    |    | /  |      | /  |   |
    |    +----+      +----+   |
    |                         |
    +-------------------------+
 

Sherif Welsen

Junior Member level 1
Junior Member level 1
Joined
Feb 3, 2005
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
135
vhdl code for nco

Please colleagues, I want to collect every single detail about the Direct Digital Synthesizer (NCO). Please send every information you have.

Thanks inadvance, I remain.
 

Black Jack

Full Member level 4
Full Member level 4
Joined
Dec 2, 2003
Messages
236
Helped
14
Reputation
28
Reaction score
3
Trophy points
1,298
Location
UKRAINE
Activity points
1,817
vhdl nco example

Sherif Welsen said:
Please colleagues, I want to collect every single detail about the Direct Digital Synthesizer (NCO). Please send every information you have.

Thanks inadvance, I remain.

See www.analog.com for their DDS chips datasheet, app. notes, tutorials.

I think for DDS important 2 things
1) Architectures of Accumulators
2) SIN generation methods (table and table compression, CORDIC, series)

See this link
http://www.sss-mag.com/dds.html

I have this book "Direct Digital Frequency Synthesizers"
by Venceslav F. Kroupa and advice that you read this.
 

Sherif Welsen

Junior Member level 1
Junior Member level 1
Joined
Feb 3, 2005
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
135
cosine vhdl

Black Jack said:
I have this book "Direct Digital Frequency Synthesizers"
by Venceslav F. Kroupa and advice that you read this.

How could I get a copy of that book?
 

Black Jack

Full Member level 4
Full Member level 4
Joined
Dec 2, 2003
Messages
236
Helped
14
Reputation
28
Reaction score
3
Trophy points
1,298
Location
UKRAINE
Activity points
1,817
cosine series vhdl code

Sherif Welsen said:
Black Jack said:
I have this book "Direct Digital Frequency Synthesizers"
by Venceslav F. Kroupa and advice that you read this.

How could I get a copy of that book?

I have only printed version :(
 

jony

Newbie level 5
Newbie level 5
Joined
Feb 21, 2005
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,362
vhdl sin

first of all i realy liked your code
but i didn't few thing
1.how did you couculate the phase diffrance at the begining?
2.how did you know to to subscart this spacific vector?
 

TRUNGDPHAN

Member level 1
Member level 1
Joined
Jul 1, 2004
Messages
32
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
297
vhdl codes for nco

I need a detail diagram of NCO architecture. Anyone got it? If yes, please share it for me? Thanks a lot.
 

ddt694

Full Member level 3
Full Member level 3
Joined
Dec 12, 2002
Messages
170
Helped
4
Reputation
8
Reaction score
0
Trophy points
1,296
Activity points
1,400
nco filter tutorial

nco is in fact a accumulator and a lookup table

you can realize a accumulator like this

process(clk) begin
if rising_edge(clk) then
acc(23 downto 0) <= acc(23 downto 0) + input;
end if; end process;

then, you can address the lookup table like this

process(clk) begin
if rising_edge(clk) then
nco_out(7 downto 0) <= rom(conv_integer(acc(23 downto 14));
end if; end process;

the signal "rom" is a lookup table, a sine or cosine waveform is in it. you can generate a sine waveform by using matlab:

step = 1/1024;
t=0: step : 1-step;
sine = sin(2*pi * t);
 

jishnukkd

Newbie level 4
Newbie level 4
Joined
Feb 13, 2007
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,301
sine_cos

go to codesearch.google.com and search for the codes. I have got the codes fot NCO accumulator, LUT from there.You can select the code language from the Advanced search optin
 

nardo520

Newbie level 3
Newbie level 3
Joined
Apr 16, 2007
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,290
nco sine

I need the method of using CORDIC THEORY,who can help me?THANKS...

Added after 11 minutes:

HELP....
 

echo47

Advanced Member level 6
Advanced Member level 6
Joined
Apr 7, 2002
Messages
3,933
Helped
638
Reputation
1,274
Reaction score
90
Trophy points
1,328
Location
USA
Activity points
33,176
ncodesign

nardo520, here is some info on CORDIC:
**broken link removed**
 

arvindkts

Newbie level 3
Newbie level 3
Joined
Dec 20, 2009
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
noida
Activity points
1,289
Re: nco architecture

Renjith said:
Hi Sherif,
An NCO design has got just 2 major blocks.
Phase accumulator, LUT Rom( to store the phase angles of sine and cos).
I've attached a NCO design document, this gives a detailed explanation for the blocks i mentioned above.
Hope this helps
please send me flowchart of your nco code.
i m getting difficulty in understanding it.
I will be thankfull to you for this kind.[/youtube]\][/url][/code]
 

bijayamuni

Newbie level 1
Newbie level 1
Joined
May 23, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,284
Re: sin vhdl

Hi,
Here is one example of Qadrature oscillator I build and testted on FPGA.
Its a sine wave oscillator.
I posted this code here some time back also it was in verilog.

Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity sine_cos is
  
  port (
    clk   : in  std_logic;
    reset : in  std_logic;
    en    : in  std_logic;
    sine  : buffer std_logic_vector(7 downto 0);
    cos   : buffer std_logic_vector(7 downto 0));

end sine_cos;
architecture behave_sine_cos of sine_cos is
signal sine_r, cos_r : std_logic_vector(7 downto 0);
begin  -- behave_sine_cos
 sine <= sine_r + (cos_r(7) & cos_r(7) & cos_r(7) & cos_r(7 downto 3));
 cos  <= cos_r - (sine(7) & sine(7) & sine(7) & sine(7 downto 3));
   
registers: process (clk, reset)
begin  -- process registers
  if reset = '0' then                   -- asynchronous reset (active low)
    sine_r <= "00000000";    
    cos_r <= "01111000";
  elsif clk'event and clk = '1' then    -- rising clock edge
    if (en = '1') then
      sine_r <= sine;
      cos_r <= cos;      
    end if;
  end if;
end process registers;
end behave_sine_cos;

-------------------------------------------------------------------------------
-- Testbench
-------------------------------------------------------------------------------

library ieee;
use ieee.std_logic_1164.all;

entity sine_cos_tb is
  
end sine_cos_tb;
architecture behave of sine_cos_tb is
component sine_cos
  port (
    clk   : in  std_logic;
    reset : in  std_logic;
    en    : in  std_logic;
    sine  : buffer std_logic_vector(7 downto 0);
    cos   : buffer std_logic_vector(7 downto 0));
end component;
signal    clk   : std_logic := '0';
signal    reset : std_logic := '0';
signal    en    : std_logic := '1';
signal    sine  : std_logic_vector(7 downto 0);
signal    cos   : std_logic_vector(7 downto 0);

begin  -- behave
clk <= transport not clk after 5 ns;

u1 : sine_cos
      port map (
        clk   , 
        reset , 
        en    , 
        sine  , 
        cos    );
process
  begin  -- process
    wait for 50 ns;
    reset <= '1';
    wait for 10000 ns;
    wait;
  end process;  

end behave;

Hope this helps

Hi I am Bijaya
I want to see the verilog design can you post it please
thanks
Bijaya
 

VINU BASIL

Newbie level 1
Newbie level 1
Joined
Nov 22, 2013
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
5
Re: an nco design has got just 2 major blocks.

Hi,

Sine and cos waves are generated using Quadrature oscillator.
If you integrate sine wave you get cosine wave You integrate this cosine
wave to generate input sine wave...
This is done using digital filter techniqe here in the VHDL code...
Following figure will explain it well....


Code:
         +----+      +----+
   sine  | /  | -cos | /  |
    +--->| |  |----->| |  |---+
    |    | /  |      | /  |   |
    |    +----+      +----+   |
    |                         |
    +-------------------------+

Hello Sir, thanks for the code. I successfully simulated it. It would be very kind of you, if you could explain briefly about the filtering/integration technique that you used.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top