How to create a sine wave with verilog ?

Status
Not open for further replies.
1. use Matlab to gen. a fix-point sin pcm code.
2. in verilog sim test bench. use $readmemh to put the pcm code to a Bus.
3. use waveform viewer to show the Bus data as "Analog".
 
Reactions: kermit

    kermit

    Points: 2
    Helpful Answer Positive Rating
nand_gates:

Why does is this Verilog cordic-like algorithm stable

assign sine = sine_r + {cos_r[7], cos_r[7], cos_r[7], cos_r[7:3]};
assign cos = cos_r - {sine[7], sine[7], sine[7], sine[7:3]};

and not the more traditional algorithm where the second line would read

assign cos = cos_r - {sine_r[7], sine_r[7], sine_r[7], sine_r[7:3]}; ?

This last line causes the amplitude to diverge.

Thanks,
mobedwell
 

From Cordic literature, it's obvious that the "more traditional" symmetrical form you're asking for would actually require an additional factor to achieve convergence.
See e.g.: CORDIC - Wikipedia, the free encyclopedia

It's not that obvious in my opinion, why the modification in the present algorithm achieves the required correction. But I assume, that the equivalence can be shown.

Another not obvious property of the fixed point implementation is, that it's apparently stable (with a small superimposed limit cycle) for different divider ratios, not only 8.
 

I finally found an explanation for the correction in the algorithm for generating the sine wave. This is a modified cordic algorithm called the "Goertzel Algorithm". For a good explanation, see paragraph 5 in the accompanying link.

**broken link removed**

Additional information on this algorithm can be found on wikipedia at

Goertzel algorithm - Wikipedia, the free encyclopedia
 

Use a Numerically controlled oscillator. The aforementioned CORDIC too is used, but use NCO. NCO is used in many places.

I only have the vhdl code, no verilog, so not posting it here.
 

ninju,

Please go ahead and post the vhdl code. I am sure I can figure it out.

Thanks.
 

regarding NCO, here's the thread. I myself referred to this while programming.

https://www.edaboard.com/threads/117304/

i haven't got the exact frequency for which i designed. So, if you just want to generate sin and cos, regardless of frequency, i'll post it here.
 

nand_gates,

Can you provide a reference for your algorithm? It seems very stable, but I would like some mathematical verifaction to make me feel comfortable using it.

Thanks,
Mike
 

Re: verilog sine wave

1 Lookup table
2 cordic
 

Re: verilog sine generator




thank you for the code but m not getting the answer ..
for cos = 120 i got sine = 15 and for cos = 30 i got sine = 3 ..
so please clarify your answer..
i am waiting for your reply...
 

Re: verilog sine generator

plz explain that code i didnlt understand it
 

The operation principle of the code presented in post #5 has been explained by nand_gates and thoroughly discussed in this thread. If you don't get it, please refer to general CORDIC literature, e.g. https://en.wikipedia.org/wiki/CORDIC.
 

how many stages should be there if i want to design a counter that counts 5-2-0-7-5

i'm confused .
8 stages or 4 stages??
 

Re: verilog sine generator

I want to generate a sine wave with 50Hz and peak amplitude 5.Can you please give the verilog code for that
 


wat about work.sine_package??? without it, this code is not working... please include this package also....asap
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…