Sine using pwm

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

You need additional external circuitry to do that.

I want create sine more 1000kHz

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?

1 Like

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

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

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

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.

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.

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.

you can use this mikroe click board

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.

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

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.

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

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:

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?