Sine wave from microcontroller

Thread Starter

sanketh

Joined Jul 11, 2014
8
Hey all,

I have been trying to get sine wave of different frequencies (For example from 60-110 Hz) from a micro-controller, what I have succeeded in doing is by using PWM and timers I am able to produce square waves in the said range, Now I understand that I must use a low pass RC filter to convert the square waves to sine waves but no matter what value of R and C i choose, am not able to get the sine waves at same frequencies as square waves. I am kinda stuck now having tried all possible combinations. Please help.
 

ScottWang

Joined Aug 23, 2012
7,409
You can using two stages of RC integrators to do and using op amp to amplifying the waveform, but using this method will cause the sine wave has a little delay to the square wave.
Try yourself to adjust the RC values first.

700Khz-Sqr2Sin-eng.gif
 

Sensacell

Joined Jun 19, 2012
3,453
You must create a PWM square wave with a frequency many times the final sine wave frequency, so your filter kills the PWM, but let's the sine wave pass through.
 

JDT

Joined Feb 12, 2009
657
You can generate a sine wave from a square wave but your low-pass filter needs to have a cut-off slope that can attenuate the third harmonic and above.

So for 60Hz it needs to block 18oHz. But to work at 110Hz, it needs to let 110Hz through. So you filter needs to have a steep cut-off between 110 and 180Hz. Your filter will have a number of stages and will use inductors!

Using PWM at a much higher frequency is the way to go. Still need a LPF but a much simpler one.
 

crutschow

Joined Mar 14, 2008
34,465
One problem with using a square-wave and a filter is that the filter cut-off frequency must vary with the square-wave frequency for proper filtering. As noted, a higher frequency PMW is what you want. Of course that requires some method (such as a look-up table) to generate the sine-wave modulation.
 

MrCarlos

Joined Jan 2, 2010
400
Hello sanketh
You have read the wise words from crutschow ?
You've tried to develop a circuit with a DAC ?.
I've seen this kind of circuits made, of course your Micro-controller, and a DAC (Digital Analog Converter).
The DAC is connected to the 8 BIT's in some port from the Micro-controller, the output of the DAC obtain a sine wave. This sine wave is composed of many, many, many steps.
With a potentiometer connected, for example the port RA0 vary frequency.
The code is attached in the ZIP file for you to study and better understand this idea.
 

Attachments

AnalogKid

Joined Aug 1, 2013
11,055
I agree with MrChips and Sensa - converting a square wave and converting a PWM signal are two very different things. Which is it?

ak
 
Top