# how to calculate duty cycle for sine pwm?

Discussion in 'Power Electronics' started by kittoo, Aug 16, 2016.

1. ### kittoo Thread Starter New Member

Jul 11, 2016
26
1
If carrier signal frequency is 10khz and sine waveform frequency is 50hz then how to calculate duty cycle for sine pwm?

2. ### #12 Expert

Nov 30, 2010
16,665
7,310
You can't build a sine wave at 50KHz by using PWM at 10 KHz.
Either that or your question is difficult to understand.

3. ### kittoo Thread Starter New Member

Jul 11, 2016
26
1
i think you didn't read the question correctly its 50hz not 50khz

#12 likes this.
4. ### WBahn Moderator

Mar 31, 2012
18,085
4,917
I have no idea what a "sine pwm" would even mean.

Could you provide a sketch of what the waveform would look like for a low and a high duty cycle? Perhaps then we can make heads or tails of what you are trying to get at.

5. ### #12 Expert

Nov 30, 2010
16,665
7,310
You're right. I imagined an extra, "kilo".

The definition of PWM is that the duty cycle changes. To build a sinewave, you change the duty cycle of the PWM signal according to a sine function of the 50Hz frequency times amplitude. It would take me an hour to do the math because I've never done it before, but the concept seems simple enough.

6. ### wayneh Expert

Sep 9, 2010
12,374
3,226
Just a Google it for heaven's sake. There are gazillions of examples out there of how to get a sine wave out of PWM.

#12 likes this.
7. ### crutschow Expert

Mar 14, 2008
13,475
3,361
The PWM duty cycle follows the sine function, in this case sin(2πf) or sin(2π*50).
Since 50% (0.5) duty-cycle corresponds to 0V on the sinewave, the complete function would be [duty-cycle = 0.5 + 0.5*sin(2π*50)].

kittoo likes this.
8. ### avayan New Member

Oct 30, 2015
12
2
If I understand that what you want is to synthesize a sine wave with a microcontroller's PWM output, what I would do is write up an excel table with the number of values given by my timer resolution.

Say you have 8 bits worth of resolution, then you have 256 values. Divide the 360 degrees by 256 and you will get a 256 long table with 1.40625 degree increments. Take this table and make a constant array on your code and then program a timer ISR to grab one of these values and place it into the PWM duty cycle register at a fixed interval.

Since your sine wave is 50 Hz and you have 256 steps per electrical revolution, you need to call the timer ISR 50 * 256 = 12,800 times per second or every 78.125 us.

The more resolution you get, the faster you need to call the ISR and the less real time you have.

Also, your table should be normalized to 1, or in this case 0xFF. Do note that you can also have much more resolution in terms of number of bits (say 10 bits with normalized 1 being represented as 0x3FF) but less values on your table (128 as opposed to 256). You can play this game in all sorts of different ways. You can also have a table with 360 values, and a resolution of 9 bits. So many ways to skin the cat!

kittoo likes this.
9. ### MrAl Distinguished Member

Jun 17, 2014
2,551
514
Hi,

One of the ways that has been used for years is the triangle/sine intersection technique.

This is just the intersection of a triangle wave with the sine wave, where the sine wave has frequency of the line frequency like 50Hz, and the triangle has the frequency of the carrier frequency. The intersections of these two produce a PWM timing that produces a sine wave PWM.

Personally i like doing it other ways, but that has been used before in various schemes. You can even set this up electrically using a triangle wave and reference sine wave using a low power oscillator and that would generate the required PWM.

One thing i did a long time ago was compare this to some other methods but i cant remember the outcome now since it has been so many years. The main goal is to generate as little distortion as possible with as little switching transients as possible. We got down to less than 1 percent back then with a reasonable carrier frequency, but cant remember all the details now. That's when power MOSFETs first started becoming in vogue.

Another method is to use the Z transform of a sine wave.

The other more direct method is to just use the instantaneous average value of the sine at spaced intervals in time. A little experimentation or analytical investigation is advised here in order to get the most out of the pattern because the overall THD is affected more by times near the peaks than by times close to zero and 180 degrees, so it makes sense to think about shaping the pattern based on instantaneous RMS values.

Last edited: Aug 16, 2016
kittoo likes this.