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.

How to develop algorithm to generate sine wave at different frequency range?

Status
Not open for further replies.

Maverickmax

Advanced Member level 1
Joined
Dec 6, 2004
Messages
404
Helped
8
Reputation
16
Reaction score
3
Trophy points
1,298
Activity points
3,689
Hi

I am interested to develop algorithm to generate sine wave at different range of frequency for my microcontroller. Does anyone know how to do it or know the link for me to look up?

Please let me know asap

Kind regards

Maverick Max
 

Re: VARIABLE FREQUENCY

This is what I was asking for....

It is the software Im interested in

MM

Added after 2 hours 4 minutes:

I am bloody frustrated with it as I could not find any algorithm or pseduo code to help me to develop variable frequency generator.

I would be really grateful if you help me asap

MM
 

Re: VARIABLE FREQUENCY

Hi,

Three ways to do it:

1. Make a square wave (easy) and filter it

2. Use PWM and filter it

3. Use a DAC, fed by a look-up table, and filter it


If you use the look-up table to DAC method, to change thre frequency you just change the speed at which you increment the table pointer.

For method 3, take a look here (there is a code sample in a link)

**broken link removed**



Personally, I like the look of (1), if you don't mind putting a good filter after it. The software would be a bit simple though. Take a look here:

**broken link removed**


FoxyRick.
 

Re: VARIABLE FREQUENCY

Here is another one:

h**p://www.elecdesign.com/Articles/ArticleID/12002/12002.html

Good luck
 

Re: VARIABLE FREQUENCY

Very Simple !!!!

The simplest way to generate a Sine wave using a microcontroller is implement a digital Filter in software whose impulse response is a Sine Wave. Then excite that filter with a '1' (an impulse) at start and it will automatically generate samples of sine wave. The number of samples per cycle 'N' can be choosen as u desire. Variable frequency option is achieved by throwing the samples after a delay. Changing the delay will change the output frequency.

Another crude way to generate Sine wave using microcontroller is to make a lookup table for the sine wave and then throw those samples to DAC after some time but that impulse response method is more professional. I implemented this project in hardware and it worked successfully. I generated a Sine Wave using AT89c51 microcontroller and then converted it to Analog using DAC0808. I know that both these IC's are not that fast but i had these ones available to me.

Here is the link for the whole presentation for this project of generating Sine wave using microcontroller. Software of generating Sine wave alongwith the hardware design is discussed. PPT File is uploaded in the IEEE papers , Study papers section with the topic title "Sine Wave Generation using Recursion". Link is given below





Hope that this helps u
 

Re: VARIABLE FREQUENCY

If you have enough pins available, how about a R2R ladder + opamp? Then go through a sine table at the speed you want...

Christian
 

Re: VARIABLE FREQUENCY

I also think the R2R ladder process is an interesting single-chip solution for a 1.0-hz to 100-KHz Sine, Square, Sawtooth, or Triangle waveform generator.

Please check out **broken link removed** for an AVR example.

Regards, Mike
 

Re: VARIABLE FREQUENCY

Guys

Thank you for contributing information but it is NOT what I want to do. Basically I have produced a LUT (LookUp Table) for sine wave. Since Im using 10kHz PWM and 512 data array. So that means the sin frequency would be roughly 19.53Hz. The BURNING question is how to produce the low frequency, let say, 5 Hz. This must be done by skipping index corresponding to the 512 LUT.

You see, if I skip 2 time in the LUT which is 256, the frequency would be double. I know it is the possible solution to increase the size of LUT but I don't want to because of the limited RAM size.

I welcome to hear your suggestion

Kind regards

MM :roll:
 

VARIABLE FREQUENCY

Maverick Max,

You can do the same, except instead of skipping you "stick" to the same position in your LUT on the next cycle. You nead a "stick" counter, that is all. If you want to get very fancy you can interpolate between values in your LUT.

-jonathan
 

Re: VARIABLE FREQUENCY

Can you please tell me about interpolate between the value? I am not famaliar with 'interpolate'.

MM
 

Re: VARIABLE FREQUENCY

Probably the most easy way is to use XR2206 function generator IC along with digital potentiometers. Interface this setup to PIC or AVR and u can get virtually any signal.
 

Re: VARIABLE FREQUENCY

Maverickmax said:
Guys


You see, if I skip 2 time in the LUT which is 256, the frequency would be double. I know it is the possible solution to increase the size of LUT but I don't want to because of the limited RAM size.

I welcome to hear your suggestion


If you want to move through your table at a slower rate, you need a lower fractional byte for your counter.

If you advance by +1, you get a new value each time because you went up one index.


Instead of adding +1 each time, use a new lower byte and add +1 in it each time. If the lower byte has 0x01, then after 256 adds you get a carry into the higher byte, and your index goes up one. You go through the table at x/256th the rate. (This is not limited to +1, +16 in the lower byte will roll over after 16 adds, 256/x will tell how many loops until it rolls over..)

Binary works in fractions too. 00.00 The right bit from the decimal is 1/2, the next right is 1/4, etc etc. It is just 2 ^ -1 then 2^-2 etc..

Instead of index hex 01. counting 1 to 256 you use index hex 00.01 counting 1/256th. Add that then use the high byte as your index, there's a carry every 256 with 1 in the low byte etc. If you need even slower, use another lower byte for 1/65536th as the minimum. Hex 00.0001 adds 65536 times before there's a carry into the high byte and the index increments to 1. The byte above the decimal is still your index, you're just keeping track of smaller fractional increments instead of incrementing by the whole 1 each time. Hex 00.8000 is 1/2, you will get a carry into the high byte every 2 adds, 00.4000 is 1/4 etc etc.

Alan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top