Hello all,

How can I create a sine wave generator using PWM in NETMF?

# Sine using pwm

You need additional external circuitry to do that.

http://www.learningaboutelectronics.com/Articles/Square-to-sine-wave-converter-circuit.php

If you look at it from the standpoint of Fourier analysis, any periodic waveform is composed of a series of sinusoidal waves added together. A square wave is a series of sine waves that includes the fundamental frequency of the square wave and an infinite series of odd harmonics. To convert a square wave into a sine wave you can use a low pass filter to filter out the higher frequency harmonics and leave only the sine wave of the fundamental frequency.

The link Mr_John_Smith provided is exactly that. RC filters are not often the best choice of filter, but the quality of the filter you need depends on how clean a sine wave you require as well as how much signal loss you can live with. What are you trying to accomplish?

**Mike**#5

must it be a pure sine wave? Do you require a negative portion?

Would a square wave with a 50% duty cycle Work?

**jooos**#6

Yes, it be a pure sine wave. I am interested in the maximum possible frequency of the sine wave generator using PWM on G120.

I became interested in this topic after reading the tutorial http://www.ocfreaks.com/sine-wave-generator-using-pwm-lpc2148-microcontroller-tutorial/

The G120 is capable of a maximum PWM speed of 1.875 MHz with 6 bit resolution. Thatâ€™s not fast enough to approximate a 1 MHz sine wave. The only way to get a 1 MHz sine wave directly from PWM is to start with a 1 MHz square wave and filter it. To get a â€śpureâ€ť sine wave you would need a really good filter.

**jooos**#8

I do not understand - in the manual about PWM it is written â€śFrequencies can range from 1 Hz to 30 MHzâ€ť

What is the highest possible frequency with 16 bit resolution and 10 divisions? 187,5kHz?

Looked at the data sheet again and you are correct, the PWM can output 30 MHz, but with only 2 bits of resolution. This would give you four values you could use for the PWM duty cycle. To try to approximate a sine wave with four values you would have to write the PWM duty cycle 6 million times per second with a high degree of timing accuracy. Not possible with NETMF, and it wouldnâ€™t reduce the filter requirements by much.

The problem in trying to approximate such a high frequency sine wave with PWM is how often the PWM duty cycle would have to be updated. As NETMF is not real time, the only option is to use PWM to output a 1 MHz square wave and filter it heavily to turn it into a sine wave.

Not sure exactly what you mean by your last question, but with 16 bit resolution the PWM frequency would be about 1.83 kHz.

**jooos**#10

Yes, I know that NETMF is not real time. I wanted to explore the maximum capabilities of the G120 module for creating a sine generator using PWM modulation.

**Mr_John_Smith**#12

So itâ€™s exploratory, ok. If you donâ€™t want to use any other external components and you are ok with â€śslow speedsâ€ť then you should try using the DAC to generate the sine wave. If you need more then you could explore (ack, it used to be called RLP, sorry Gus I forgot the new name), as a method to increase the frequency and accuracy of the resulting sine wave, as that method would be more deterministic.

**jooos**#13

Now I understand more about the different ways to get a sine wave. Thank you all very much for your help.

**hwalker_MIWV**#14

Any suggestions on a fixed (non-programmable) 10 MHz square to sine converter solution? A 3rd order RC network canâ€™t perform at that high of frequency, the caps seem to attenuate all the voltage or only a phase shift occurs (maybe LTSpice unable to simulate?). So far I have seen some op amp networks and also RLC suggestions for 100 KHz up but no concrete info / ICs above 4 MHz. The above IC (AD9833) seems fantastic if there was to be room for a serial programming interface or micro controller.

**NoControl_Joel**#15

Thought these videos were interesting, but not sure how clean a sine wave youâ€™re looking for:

**NoControl_Joel**#16

If you do a search for â€ś10 MHz low pass filterâ€ť there are plenty of sites to keep you occupied for a minute or two. Hereâ€™s a report from Texas Instruments that details the design of a second order 10 MHz low pass active filter:

**Mike**#17

Might help if you provide a clue as to what you are trying to implement?

Would a sin wave generator with an on/off input work?

Does it need to be frequency agile?