# How can I generate a sinusoidal voltage and current waveform using half-bridge or full bridge inverter?

I know how a half bridge and full bridge circuit looks like. What I don't understand (and I simulated it) is that whenever I drive the switches using a pulse generator I get a square wave as an output. I am not filtering it.

So my question is: Can I get a sinusoidal voltage waveform and a sinusoidal current waveform using sinusoidal PWM (so dutycycle of PWM varies constantly in order to change the average DC value to create a sinusoidal waveform)?

• first thing i would do is get a better input, PWM is digital, you need to low-pass filter it or use an OPAMP integrator or something Oct 13, 2014 at 14:49
• Can you make your question more clear? You start with bridge circuits, the next sentence is about some switches, then you talk about PWM. If the last question is really what you want to ask why the seemingly unrelated introduction? Oct 13, 2014 at 14:50
• The mark space (highh / low) ratio of the PWM isproportional to the sine wave analog value at that point. As the sine amplitude increases the high to low pwm ratio increases. Low pass filter that and you have sinewave out. Oct 13, 2014 at 16:05
• @WoutervanOoijen Well, because the switches (MOSFETS here) are related to the bridge circuits and the switches are driven with PWM I thought the relation was clear. But you're right, that was just an introduction to my question. Oct 13, 2014 at 17:02
• See added notes on my answer.And riddle :-) Oct 14, 2014 at 0:45

Start here to get a general idea - Many many ideas here

The high:low ratio of the PWM over 1 PWM cycle sets the analog value represented after filtering. The PWM ratio is adjusted accordingly. But how to do so ...

Here's how:

The comparator compares linear ramp & sine wave magnitudes - and toggles the output according to the result.

And the next one is like unto it ...

I expect you to now run from the room crying "Eureka".

YeeHa!!!

This

Yee Ha !!!

From Here

Makes this:

Notes:

Note that one diagram above uses a triangle wave and the other a sawtooth (ramp up, vertical down). Look at what they both do and how the method works. Once you understand what is being done you can "easily enough" convert it into software. The "ramp" in both cases starts at zero and progresses to Vmax over a period of time. With an analog comparator you continually compare the sine wave with the ramp and set the output high when the ramp is lower than the sinewave and low when the ramp is higher. In software the comparison is done at regular time steps

The overall ramp frequency needs to be higher than the sine wave frequency. The more ramps per sinewave cycle the more often the waveform will switch and the higher the PWM frequency and the more losses in MOSFETS or IGBTs etc. But, lower ramps per sinewave lead to a worse approximation of the sine wav when the PWM is filtered. Some systems change the number of samples per sinewave depending on the frequency to limit maximum PWM rate. As sinewave frequency gets higher they will occasionally reduce the ratio. When such systems drive a motor you can hear them "gear changing" a the motor accelerates. Starter from stationary the inverter PWM can be heard as a low frequency tone which rise towards a whistle as the motor speed rises, then suddenly drops by a factor of maybe 4 or 8 or ... and then rises again as the motor continue to accelerate. It may do this several times. This allows the purest possible sine wave at slow speeds and limits drive frequency components at high speeds.

Note that you need model this for only a quarter cycle in software. For the second quadrant you just run the comparison backwards to quadrant one, for Q3 you invert Q1 (highs and lows swapped) and for Q4 you invert Q2. The sinewave values may be calculated on the fly or stored in a table depending on what suits your system. If you have lots of ROM/memory room it may be easier to use a whole 360 degrees in memory but using 1/4 cycle 4 times is not much harder.
So, if using a table:

Q1 - Up table
Q2 - Down table
Q3 - Up table, output inverted
Q4 - Down table output inverted.

Which reminds me of an old old joke*.

What can go: Up a chimney down and Down a chimney down
but cannot go Down a chimney up or Up a Chimney up ?

(In some case, trying to go up a chimney up may work after a fashion if you try hard enough but may lead to disaster but down a chimney up always ends in disaster. )

• So does that mean that driving the switches, using the output of the comparison of the triangle waveform and the sine waveform as you explained above, mean that I will thus get a sine wave output at the bridge inverters ?? Is that it ?? :p If the answer is yes, then how can that be done using a microcontroller (do I have to use a for-loop and vary the duty cycle accordingly ) ? Thank you sooooo much ! Oct 13, 2014 at 17:08

Well what you are talking about with the duty cycle is similar to the way Class-D audio amplifiers work. But just to clarify, even though the amplified frequency might be only 60 Hz, the square wave (whose duty cycle is being modified) might be over 100Khz. As a result, a tiny amount of capacitance inductance (usually in the speaker itself, in the case of an amplifier) turns the output into a very nice sine wave. A similar strategy I've seen developed for power inverters involves a digital control system or MCU that over the span of a 60 hz cycle time, reads a series of 1's and 0s from a lookup table from memory. Again, the number of lookups must be much greater then the cycle time, but in this case maybe only 100 divisions will yield excellent results. The sequence stored in memory, in that case, are called "magic numbers", and I first saw this methodology developed by Don Lancaster, who used to write for some electronics magazines... wow.. I think like 4 decades ago? But he still runs a web site called http://www.tinaja.com, or you can look up Don Lancaster in a google search, with the string "magic numbers". He probably has all the magic number data available and pre-calculated, though I'm sure he will want some kind of fee.

The other option is to just "approximate" a sine wave. Many home "UPS" systems will switch between a few taps on the output transformer, to provide a few "steps" along what would otherwise be a square wave. Though the steps are still not as pretty as a sine wave on a scope, they still have a much lower harmonic content than a straight up square wave, and so are much kinder to equipment that is powered from the circuit.

Hope some of this helps.

An H-bridge can produce thee (useful) output states, call them high, low, and zero. Some calculus will show that the most sinusoidal wave with those three states is very close to this

 -----
-     --     -
-----


which is 14 periods with 5 high, 5 low, and 4 zero. Many inductive and capacitive loads, like a transformer, will make that waveform even more sinusoidal. Resistive loads like a heater or incandescent light won't care.

• A H-bridge can provide three states: high, low, and high impedance, but not zero. High impedance is different from zero: it means neither the high side or the low side supply is connected to the output, and the output is just floating. Zero means actively forcing the output to be at zero volt, e.g. by shorting it to ground. This requires more transistors than what a H bridge has, and is typically not very useful.
– dim
Feb 17, 2021 at 12:20
• Maybe you're thinking of a half-bridge. An H-bridge can drive both sides of the load low voltage, and current can flow in either direction by way of body/fly-back/protection diodes. Feb 25, 2021 at 13:59
• Right, I simply didn't realize what happened when both sides are actively driven to the same level. My bad.
– dim
Feb 25, 2021 at 14:04