# Sine wave from microcontroller

Discussion in 'General Electronics Chat' started by sanketh, Oct 14, 2014.

1. ### sanketh Thread Starter New Member

Jul 11, 2014
8
0
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.

2. ### wayneh Expert

Sep 9, 2010
12,402
3,249
All possible combinations? My, you've been busy. And what could be left for us to suggest?

How did your integrator experiments work out?

3. ### MrChips Moderator

Oct 2, 2009
12,651
3,460
You are using the wrong PWM approach.

Did you google sinewave from PWM?

4. ### ScottWang Moderator

Aug 23, 2012
4,933
777
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.

5. ### Sensacell Well-Known Member

Jun 19, 2012
1,184
277
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.

6. ### JDT Well-Known Member

Feb 12, 2009
658
85
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.

7. ### crutschow Expert

Mar 14, 2008
13,509
3,385
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.

Brian Griffin likes this.
8. ### shteii01 AAC Fanatic!

Feb 19, 2010
3,516
515
Does your uC have a DAC?

9. ### MrCarlos Active Member

Jan 2, 2010
400
134
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.

File size:
823 bytes
Views:
26
10. ### AnalogKid Distinguished Member

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

ak