surabhig.com

No shortcuts. Work for it.

2-bit Signal Generator (NCO) in Verilog

Recently started using version control BitBucket and I must say sharing code is definitely easier.

So here is the link to the code that generates sin and cos signals according to the required frequency.

https://bitbucket.org/snippets/surabhisgp/Rnyaq

It is 2 bit only because the range of values is between [-1,1].

If you are looking for something in the range of [0,1], that would make it a 1 bit NCO which is even easier (you just have to ignore the LSB). Focus only on sin[1] or cos[1].

This module is great if you have to quickly test something like demodulators etc.

If you figure there are issues or even found a simpler way please feel free to share them.

Alright, I’m onto figuring out the next task, atan in verilog!

P.S. I’m also going to make sharing the code easier on the blog… will try to embed it here.

2 Comments

  1. can you give me a test bench for it

    • surabhig

      December 5, 2018 at 8:50 pm

      Hello,
      You can write a brief testbench for it like this example below:

      module nco_sig_tb ();

      reg clk, reset;
      wire sin_out, cos_out;
      reg [63:0] phase_inc_carr;

      nco_sig (
      .clk(clk),
      .reset(reset),
      .phase_inc_carr(phase_inc_carr),
      .sin_out(sin_out),
      .cos_out(cos_out)
      );

      initial begin
      clk = 0;
      reset = 0;
      phase_inc_carr= 64’h00FFF; //value according to the desired frequency of sin/cos
      //See how to calculate here: http://surabhig.com/phase-increment-calculator-for-nco/

      #100
      reset = 1’b1;
      end

      always
      # clk = ~clk;

      endmodule

      Hopefully this is what you were looking for!
      Good luck,
      Surabhi

Leave a Reply

© 2018 surabhig.com

Theme by Anders NorenUp ↑