Pic sine wave inverter H-bridge

wingnut

Aug 9, 2012
255
Joined
Aug 9, 2012
Messages
255
Hi all

I have installed PV panels but now am trying to build a modified sine wave inverter - which, surprise, surprise, is acting up.
I keep getting a varying voltage out - which ranges from 60V ac to 180V ac.

A PIC16F690 outputs pulses of increasing and decreasing duty cycle (but not using PWM) to simulate a modified sine wave. This wave is generated on alternating pins, while the other pin sits at 0V.

This "sine wave" is then sent to a L293D motor driver which uses an H-bridge to create an AC which is sent through a transformer which generates my varying output. The PIC runs on 6V batteries and the L293D on a 12V car battery with a common ground.

I replaced the motor with the primary windings of the transformer but otherwise keeping everything the same as the circuit on page 2 of the L293 data sheet at...
http://www.ti.com/lit/ds/symlink/l293d.pdf

Any ideas as to why the voltage coming out of the secondary windings varies so much would be greatly appreciated.
 

Arouse1973

Adam
Dec 18, 2013
5,178
Joined
Dec 18, 2013
Messages
5,178
Hi Wingnut

You don't have a brother called washer by any chance do you :)

Can we see a circuit diagram? What pulse timings are you using?

Thanks
Adam
 

Colin Mitchell

Aug 31, 2014
1,416
Joined
Aug 31, 2014
Messages
1,416
To get a sinewave you simply output a square wave to a capacitor via a resistor and then buffer the output to drive a sinewave circuit.
Once you have a smooth sinewave you can do something with it.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Excellent reply Colin. This works really well until you want to use it in a power application.

The sine wave so produced could control the pulse width of some PWM circuit which produces an output with an average voltage approximating the square wave.
 

Colin Mitchell

Aug 31, 2014
1,416
Joined
Aug 31, 2014
Messages
1,416
Let me put it this way.
I was explaining how to start with sorting out the problem.
The first thing to do is convert the square wave to a fairly accurate sine wave and deliver this through the output to see the result.
If you don't have a smooth wave you can get a lot of "fighting" in the system and you can get harmonics generated that produce a lot of heating or high voltage spikes that can damage output transistors.
I remember one 4kw inverter had this problem 25 years ago that destroyed the output MOSFETS. The answer was to put "p" capacitors across them to "snub" the high voltages. This was all due to the "modified sinewave circuit."
 

wingnut

Aug 9, 2012
255
Joined
Aug 9, 2012
Messages
255
Let me put it this way.
I was explaining how to start with sorting out the problem.
The first thing to do is convert the square wave to a fairly accurate sine wave and deliver this through the output to see the result.
If you don't have a smooth wave you can get a lot of "fighting" in the system and you can get harmonics generated that produce a lot of heating or high voltage spikes that can damage output transistors.
I remember one 4kw inverter had this problem 25 years ago that destroyed the output MOSFETS. The answer was to put "p" capacitors across them to "snub" the high voltages. This was all due to the "modified sinewave circuit."

Arouse1973 I am the only nut on my family tree that I know of - but wingnut means that my favoured mode of transport is flying. You asked the frequency. I do not know what it was but it is now 50Hz. I also changed the waveform from a PWM fairly pretty sine wave to an uglier square wave. The voltage is more stable now so I presume that the sine wave (made up of 16 separate spikes per wavelength) may have been messing up the voltage. The voltage would sometimes randomly double.

Colin, I would like to graduate to mosfets but they seem quite tricky, possibly requiring a driver to supply enough current. Would this H-bridge maybe do as a mosfet driver? As I understand it, the mosfets would not affect the transformers output voltage, only increase the current. So if I get the waveform and voltage right, the last thing to add would be the mosfets.

I changed to a square wave (actually pin A on, both off, pin B on, both off) so that I could measure the frequency on my frequency meter. I later plan to return to pulses which will smooth the square wave into a sine wave, but pulses confuse my frequency meter. Tomorrow I will return to pulses and a sine wave and see if this causes the transformer voltage to swing wildly. From researching inverters, it seems that pulses can be created by oscillators (4046) or decimal counters for a modified wave (4017) but a PIC seems easiest to control both the waveform and the frequency.

It also seems best not to use a centre-taped transformer for the primary. Center-taped circuits only require two mosfets. But I only have non-center taped transformers lying around. These require 4 mosfets since two push and two pull current through the same primary winding when in a H-bridge configuration. Transformers are more expensive than mosfets, so adding two mosfets will not add greatly to the cost. The transformers lying around seem to be 10V to 220V step up.

Am I going down the right path using PWM?

Steve, if I fed a pure sine wave into mosfets, surely it would only confuse them since they like to be either on or off? Surely it would be very hard to get a sine wave out of mosfets since if I fed a sine wave in, I would get a square wave out? Normal transistors (say TIP's) would just amplify or buffer the sine wave input and give a sine wave output surely?
Mosfets should have no trouble with a PWM sine wave though.

Also using a PIC it should be easy enough to go from square wave to sine wave later. Its the rest of the circuit I would like to get right first.

One last thing. I found a cute way to get very close to a sine wave using either a PIC or a decimal counter (Johnson). Attach varying numbers of diodes to consecutive pins, and each drops the voltage by say 0.7V, 1.4V... etc. . Attach all the outputs to one resistor, and one gets a nice steppy sine wave. Again, this may be fine for a normal BJ-transistor, but again I think mosfets would not be able to properly use a pure sine wave input. Is this so?

Anyway, thank you for the responses so far.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Arouse1973 I am the only nut on my family tree that I know of - but wingnut means that my favoured mode of transport is flying.

Aaaah, now we understand.

You asked the frequency. I do not know what it was but it is now 50Hz. I also changed the waveform from a PWM fairly pretty sine wave to an uglier square wave. The voltage is more stable now so I presume that the sine wave (made up of 16 separate spikes per wavelength) may have been messing up the voltage. The voltage would sometimes randomly double.

Breaking up the sine wave into only 16 parts will probably produce something that isn't too smooth, however a lot depends on your transformer.

However the larger problem is that it does become difficult to regulate the output. (Difficult, not impossible).

An alternate method that is more typically applied is to generate a high DC voltage (say 400V DC) and then use an H-bridge to produce a PWM equivalent of 240V AC.

Colin, I would like to graduate to mosfets but they seem quite tricky, possibly requiring a driver to supply enough current. Would this H-bridge maybe do as a mosfet driver? As I understand it, the mosfets would not affect the transformers output voltage, only increase the current. So if I get the waveform and voltage right, the last thing to add would be the mosfets.

Mosfets and transistors have differing drive requirements, The decision as to whether to use a mosfet or a BJT needs to be made fairly early on. I wouldn't regard it as something to add on later.

I changed to a square wave (actually pin A on, both off, pin B on, both off) so that I could measure the frequency on my frequency meter. I later plan to return to pulses which will smooth the square wave into a sine wave, but pulses confuse my frequency meter. Tomorrow I will return to pulses and a sine wave and see if this causes the transformer voltage to swing wildly. From researching inverters, it seems that pulses can be created by oscillators (4046) or decimal counters for a modified wave (4017) but a PIC seems easiest to control both the waveform and the frequency.

A microcontroller is probably the most flexible way to do it. Using discrete logic can make things hard for you if you need to make a subtle change. On the other hand, with discrete logic you can define logic so that you can't accidentally turn both sides of an H Bridge on together.

It also seems best not to use a centre-taped transformer for the primary. Center-taped circuits only require two mosfets. But I only have non-center taped transformers lying around. These require 4 mosfets since two push and two pull current through the same primary winding when in a H-bridge configuration. Transformers are more expensive than mosfets, so adding two mosfets will not add greatly to the cost. The transformers lying around seem to be 10V to 220V step up.

I guess this comes down to what you have. If you have a transformer without a centre tap and you don't want to go out and get one that is centre tapped, then yes, you need to use an appropriate design.

Am I going down the right path using PWM?

A lot depends on the characteristics of the transformer. A modified square wave may produce an output that is sufficiently similar to a sine wave for your use. But let's assume you want a sine wave. For efficiency, the use of PWM is pretty much a given.

Steve, if I fed a pure sine wave into mosfets, surely it would only confuse them since they like to be either on or off? Surely it would be very hard to get a sine wave out of mosfets since if I fed a sine wave in, I would get a square wave out? Normal transistors (say TIP's) would just amplify or buffer the sine wave input and give a sine wave output surely?
Mosfets should have no trouble with a PWM sine wave though.

It wouldn't confuse them, and with appropriate control would produce a lovely sine wave. However the efficiency would be very low.

Also using a PIC it should be easy enough to go from square wave to sine wave later. Its the rest of the circuit I would like to get right first.

In theory, yes. However as you go to PWM, your switching speed will increase and you will have to handle more losses in switching, and potentially the suppression of more total energy in inductive spikes.

One last thing. I found a cute way to get very close to a sine wave using either a PIC or a decimal counter (Johnson). Attach varying numbers of diodes to consecutive pins, and each drops the voltage by say 0.7V, 1.4V... etc. . Attach all the outputs to one resistor, and one gets a nice steppy sine wave. Again, this may be fine for a normal BJ-transistor, but again I think mosfets would not be able to properly use a pure sine wave input. Is this so?

I think you're probably going the right way with a microcontroller and some sort of table lookup. The alternative would be the source of a nice clean sine wave (and Colin suggested how to get one) and then to compare the output voltage (or current) to this and use the result of that comparison to change the pulse width. This is similar to any switchmode supply which compares the output to a fixed voltage reference, but it switches the reference to one that varies according to the shape of the desired waveform. Don't let me make this sound simple though.
 

Colin Mitchell

Aug 31, 2014
1,416
Joined
Aug 31, 2014
Messages
1,416
Using push-pull makes more use of the transformer and you effectively get twice the output wattage. But for this it's best and cheapest to use a centre-tapped transformer. The choice of transistor or MOSFET depends on the wattage. For 50 watt I wouldn't bother to go MOSFET.
 

wingnut

Aug 9, 2012
255
Joined
Aug 9, 2012
Messages
255
Thank you Steve and Colin for the great advice.

My inverter seems to be performing consistently now giving a constant 115V from a 12 V car battery and a 6V battery driving the PIC. Even though I cannot use 115V as it is exactly half of the 230V I need, at least I know that all I have to do is change the transformer.

For the fun of it, I took the output of my first transformer and fed it into a second transformer and got 162V out. The output sounded so rough that the voltmeter produced a vibrating sound like a small speaker. Never knew a voltmeter could produce that sound.

To be totally honest, I could go out and buy the right transformer - but I don't think I am going to be up to making an inverter which could drive my deep freeze. So I am putting my money into buying a 1000W pure sine wave inverter which I have ordered. I will continue to experiment as a hobby with making inverters. After all, one is burning daylight for every day that I cannot get that fridge off the grid.

Just as an aside. I know that folks invest in batteries to store energy. But for my needs, the cheapest way to store daylight is in the form of ice. Let the inverter drive the fridge in the day, and leave the fridge off at night. No expensive batteries. When the fridge is not running, use sunlight to run the TV or boil water. Of course this must sound very primitive to those who have panels tied to the grid. Being grid tied is first prize and may come later.

Thanks again.
 
Top