# Help me write a code for NCO in Verilog

Status
Not open for further replies.

#### rajsrikanth

##### Full Member level 2
can any one help me to write code for NCO (numerical control oscillator in verilog.

if anyone have the code pls can u send me.

thanx

#### echo47

NCO

An NCO can be quite simple: a delta-phase constant repeatedly added to an accumulator. It generates a sawtooth output value, and requires only a few lines of code.

Code:
module top (clk, out);
input             clk;
output reg [31:0] out = 0;  // assumes Verilog 2001

always @ (posedge clk)
out <= out + 170000 * 64'h100000000 / 50000000;  // 170 kHz output, 50 MHz clock
endmodule
Do you need anything fancier than that?
If you need a sinewave output, then you can feed the sawtooth into a sine lookup table.

Plenty of NCO/DDS info available on the web, such as this page:
https://www.hit.bme.hu/~papay/sci/DDS/start.htm

### rajsrikanth

Points: 2

Re: NCO

thank u

#### rajsrikanth

##### Full Member level 2
Re: NCO

and i want something in this to be clear. in the above what is the 64bit data.

actually my need is . iam taking samples from ADC and i get modulated data from that and i need to Multiply this NCO output to the ADC output . so in this case how i have to write the code.

#### echo47

NCO

The value 64'h100000000 equals 2^32, where 32 is the accumulator width, which I chose arbitrarily. I made the value 64 bits wide simply to avoid overflow during the multiplication.

I think you meant to say "i need to Multiply this NCO output by the ADC output". If that's correct, then it sounds like you intend to use the NCO as a local oscillator feeding into a mixer. If that's true, then you probably don't want to use my example until you have converted its sawtooth output into a sinewave. Check your synthesis software libraries for a sinewave table generator, or create your own module.

Depending on your overall system architecture and your synthesis software capabilities, you may be able to simply use Verilog's * multiply operator to mix the NCO and ADC outputs.

#### rajsrikanth

##### Full Member level 2
Re: NCO

in nco how do u take the frequency, and can u tell me how to design frequency syntehsizer,
i have to track the frequency that is obtained from adc. (this is part of a demodulation technique)

#### rajsrikanth

##### Full Member level 2
Re: NCO

track means. carrier tracking. as the signal i obtained is a modulated one so i have to remove the carrier then process actual signal
no confusion mine is a basic demodulation technique. i want to do the demodulation.

Status
Not open for further replies.