A small inverter to drive 3-phase motors - DIY project

You can download project resources from here (73kB):

  • DipTrace schematic
  • DipTrace PCB layout
  • Inverter demo application software (AVR Studio)

I wanted to make a simple inverter to drive small induction motors and also some scavenged servo motors (PMM). My motivation was to ‘play’ with the sacary 300V electronics: it gives shocks; to connect the oscilloscope you must took care about galvanic isolation; instead of slow burn it explodes.

To help myself I obtained a large 230/230V transformer for galvanic isolation. I also found a large-enough (200VA) adjustable autotransformer so I was able to adjust the AC voltage from 0 to 230V. This was very helpful.

At minimum I wanted to drive 100W induction motors, but I hoped that with some luck it could go higher. Because the power supply is limited to 230VAC, a common induction motor should be used in delta configuration... I opted for simplest V-F control and, for simplicity, I didn’t even design any current measurement capabilities. The inverter works ‘blindly’ and if you overload it, something will just burn after some time (proper fuses are important to prevent wider damage).

Power supply

The power supply circuit is far from perfect. The high-voltage power supply (Vdd) only consists of a diode bridge and some high-voltage capacitors. You can see that capacitors have small capacity (300uF combined) limiting the motor current to less than 1A RMS (say 180W motor). Higher capacity is needed to drive stronger motors, but I only had so much space on my PCB… Resistors R2 and R2B slowly discharge capacitors after power off.

The low-voltage part is powered by transformer T1. As you can see, I only had 6VAC transformer and this, in my opinion, was not enough to generate some 12VDC needed to drive MOSFET gates. I was forced to make a voltage-doubler circuit (D9 and C13) and use large capacitance 2x1500uF to smoothen the voltage… Much better would be to use 9VAC transformer without the voltage-doubler.

In my circuit, the +12V power supply is not regulated and this created serious problem that I will explain later. So, if you have a 12V (or even 15V) voltage regulator, it will be beneficial to use it… Btw, the +5V supply should be regulated anyway because it supplies the microcontroller.

The microcontroller can use transistors Q7 (>150mA) and Q8 to enable/disable +12V and thus enable/disable MOSFET bridges (when disabled, bridges are put into high-impedance state). For reasons that will become evident later, it is utterly important that +5V is always present when +12V is enabled. If +5V drops down, but +12V is still present, then MOSFET bridges will short-circuit! This is a serious risk.

At power-up there is no problem, because the microcontroller will power +12V only after +5V is already there. At power-down, the +12V will already decrease to about 6.5V before +5V line starts dropping and this hopefully provides sufficient protection. If 7805 fails, I hope that C12 can slow-down the fall of the +5V line, because once the +5V (and thus also ‘enable’ signal) falls below 3.5V the transistor Q7 will close causing also +12V line to start falling – hopefully faster than +5V line… If, however, something short-circuits the +5V line then I am afraid there will be smoke and fire.

One more thing can be noted on the above circuit – there are two GNDs: the GND and the GND_L. There is a 13-pin jumper (not shown on the above part of schematics) where you can connect GND and GND_L together or disconnect them to make galvanic isolation. In fact, the +12V, as it will be seen later, also goes through the same jumper so that you can completely isolate the low-voltage part of the circuit from the high-voltage part of the circuit.

Improved low-voltage power supply

The picture below shows suggested improvements to the low-voltage power supply. I didn’t try it but I hope it can work. Here, the 9VAC transformer (about 3VA should be enough) and 7812 voltage regulator are used.

The Q7 and Q8 are again used to enable +12V when ‘enable’ signal is above 4.5V. The optional Q9 is used to discharge +12V line as quickly as possible when the ‘enable’ signal falls below some 4V. (Q7, Q8 and Q9 should have gain of at least 100.) This decreases fear of the +5V line loss, but still I think that a clean short-circuit on +5V line will probably cause MOSFET destruction if it happens while +12V is enabled.

MOSFET bridges

To generate 3-phase PWM voltage, one needs three half-bridges. The schematics of one half-bridge is depicted below (all three half-bridges are largely identical). Here, the +L12V supply is the same thing as +12V supply from the power-supply schematics except that, as mentioned, there is the jumper for galvanic isolation between them.

I used IRF840 MOSFETs. (Although I suspect IRF830 could be a better choice for currents below 2A because it has lower gate capacitance thus enabling faster switching time.) Both, IRF840 and IRF830, have usable internal anti-parallel diode so there is no need to add one externally.

Both MOSFETs in the half-bridge are driven by optocouplers - I used 6N139 optocouplers. Because they have high current transfer ratio I was able to drive them directly by microcontroller without amplifying transistors. The 6N139 is also a bit faster than, say, PC817 optocoupler (but more expensive).

The upper MOSFET gate is powered by a bootstrap capacitor C2. The diode D1 will charge the bootstrap capacitor while the lower MOSFET is switched on.

As you can see, both MOSFET gates are driven actively low (by optocouplers) and passively high (by resistors R5 / R19). I intentionally used this scary layout because I wanted that MOSFETs are faster to switch off than to switch on. The major drawback is that if an optocoupler burns out (disconnects), or +5V voltage is lost at optocoupler input, then MOSFETs will automatically turn on and this will probably lead to massive short-circuit (shot-through). It is therefore important to have considerable safety margin regarding optocoupler maximum ratings in order to make them last ‘forever’. 6N139 are voltage limited and you should not put over 15V on them.

The circuit is calculated so that if the PWM_R signal is ‘disconnected’, both optocouplers are switched on (the optocoupler LED current is about 4 mA, allowing at least 20mA current on optocoupler output) and thus both MOSFETs are switched off. When PWM_R signal is low (0V), the lower MOSFET is turned on. When PWM_R signal is high (5V), the upper MOSFET is turned on.

To make a controlled delay between the moment one MOSFET switches off, and the other MOSFET switches on, there is RC combination consisting resistor R1 and capacitor C1. You can finely tune the delay by changing the C1 capacitance – there are two capacitors C1 and C1B in parallel so that various combinations are possible… The perfect delay is only as long that no unwanted spike is generated during transitions of the PWM_R signal. Longer-than-needed delays will decrease available motor current. Very long delays (high C1 capacitance) might, I guess, even increase transistor heating because MOSFET transition from on-to-off or off-to-on will not be sharp enough due to limited optocoupler ‘gain’.

Problems with the non-regulated +12V supply

As already mentioned, the non-regulated +12V supply for MOSFET gates generated problems. Depending on the actually achieved voltage (which depends on the transformer - in my case it goes up to +15V) the MOSFET gate timing will differ significantly. Higher the actual +12V voltage, the MOSFETs will turn on faster… I burned few MOSFETs because I didn’t realize this on time.

The problem is that when you work on the circuit, you generally test it on lower-than-nominal voltage. Once you put it on the nominal voltage, the non-regulated +12V supply line will also rise and MOSFETs will turn on faster – possibly too fast.

If the actual +12V line voltage goes higher than 12V, you might need to increase resistors R5 and R19. By increasing their resistance, you slow down the turn-on time of corresponding MOSFET. (For fine tuning you can then use C1 and C1B capacitors). Because +12V line is not regulated, I had to set higher delay than optimal to include a larger safety margin.

Alternative solutions

I believe, a better (but more complex) solution would be to switch MOSFET gates using push-pull method. This way both, turn-on and turn-off times can be fast… One possible solution is depicted below (I didn’t try it). The circuit has some positive feedback to the base of the optocoupler output transistor. I hope that this positive feedback could achieve faster switching times (I wonder…).

The above circuit draws current current while the optocoupler is on because current flows through 680-ohm resistor. This means that the bootstrap-capacitor supplied MOSFET cannot stay turned on for very long… The above circuit has inverted logic in comparison to my original solution, so if the optocoupler input signal gets lost, the MOSFET will safely switch off… But if the optocoupler transistor shorts (or the PNP transistor shorts) the MOSFET will unsafely turn on.

On the other hand, if you look for a simpler/cheaper solution then note that in my original circuit you can replace the lower optocoupler by a simple transistor. However, I decided to use optocouplers for both, upper and lower MOSFET in order to achieve approx. same switching delays and, more importantly, to isolate the microcontroller from high voltage as much as possible.

Microcontroller circuit

For the microcontroller I typically use the all-mighty 8-bit ATmega8 chip in DIP28 package. This little marvel has 3 PWM outputs and this is exactly what I need – each PWM output drives one half-bridge. Most of other pins are not used: there is one pin to drive signaling LED, one to drive the ‘enable’ signal, and several to receive programmable external signals (analog or digital).


External input signals are connected (through resistors) to PC0, PC1, PC2 and PC3 microcontroller pins. You might need to enable internal pull-up resistors on these pins to have them at some defined state when nothing is connected to external inputs.

The C15 and R3 on the schematics are here to stabilize +12V line. For the reasons discussed earlier, both should be as small as possible so that the +12V line discharge fast.

I need to explain the jumper connector J3 that has dual function. First this jumper is used to achieve galvanic isolation between low-voltage and high-voltage part of the circuit. When J3B jumper is removed, the low-voltage part is isolated from high-voltage part. When J3B is inserted, the circuit can operate normally. I made jumper J3 and J3B from a 13-pin strip (J3 – male, J3B female). The galvanic isolation may come good for some oscilloscope measurements, but the main intention was to enable easier in-system programming.

The second function of the J3 jumper connector is in-system programming (the middle 5 pins of the J3 connector are SPI interface for programming). I can only connect programming cable to the jumper connector J3 if I removed the jumper J3B. This way it is not possible to connect programming equipment before galvanic isolation is achieved – not even by accident. I made this because I was afraid to electrocute my laptop computer.

(Note that the pin configuration for in-system programming is specific to my home-made programmer device. You will have to reconfigure the SPI connector to match your programmer.)

PCB making

I created a 160x100mm, single-layer PCB in the DipTrace tool. I took care that the board can be made at home. If you want to use it, you will have to reexamine and modify the PCB layout according to components you actually have.


The GND and GND_L lines are very long and connected at the jumper J3. This long path generated unwanted oscillations. To prevent it, I had to put two 0.47nF, 200V capacitors between GND and GND_L. I also put one 0.47nF, 200V capacitor between GND and +L12V. To be honest, I didn’t have 200V capacitors so I used 100V which mostly negated my efforts to implement galvanic isolation. As a result, I never even tried to program the microcontroller while powered by 230VAC – I always disconnected the 230VAC and externally connected the 12VDC to power-up the microcontroller in order to program it… Felt defeated every time.

I usually mill my prototype PCBs. This time I milled a bit deeper than usually because I hoped that this will give me higher insulation strength between tracks. After milling I manually covered the copper with solder to protect it from oxidation. The resulting PCB shown in counter-light is displayed below

As you see, I only mill insulation between tracks because I am saving my mill bits. This prototype PCB contains several mistakes that I found later and is therefore not identical to the image of PCB route layout shown in previous image.

For easier trace routing I connected pin 9 to +5VDC. This means that pin 9 should always be programmed as input pin. I also connected pins 1 and 2 to each other.


The above picture shows the finished prototype (including some mistakes already corrected in schematics and PCB routing). MOSFETs are mounted to a big chunk of aluminum. An additional heatsink is to be mounted on the aluminum chunk (the ‘temporary’ one can be seen on pictures). All MOSFETs must be insulated from the heatsink. The 7805 might also require a small heatsink if its input voltage is higher that 12V.


The first problem is to tune the MOSFET switching delay time in order to avoid both MOSFETs in a half-bridge to turn on simultaneously. As said, the turn-on delay can be roughly adjusted by changing resistor values that supply MOSFET gates (R5 and R19) and finely by changing capacitor value (C1).

To adjust the delay I used the following method… No load should be connected to the board (no motor). The 12V is supplied externally, from a separate galvanically isolated power supply. The input voltage is increased from some low value (like 20VAC) to, as the work progressed, the nominal 230VAC. Moreover, the input voltage was connected through a protection resistor of about 500 ohm. If MOSFET timing is properly adjusted the input current is minimal and the voltage drop on the 500ohm resistor is not significant. However if there is a slight overlap and two MOSFETs within a single half-bridge are simultaneously on for a short time, the current consumption will be relatively high and the resistor will start heating.

The second problem is to dissipate all the heat generated by MOSFETs. I was negatively surprised about dissipation – at 0.5A the overall dissipation was about 6W. I think that the dissipation would decrease a bit if 7.5kHz instead of 15kHz PWM frequency was used, but decreasing the switching frequency is against my religion.

It seems to me that the most useful addition to the circuit could be to implement the ability to measure heatsink temperature for self-protection. I am thinking to reprogram one of external inputs to be used as temperature measurement input.

Anyway, I was surprised how smoothly the inverter drives a small (150W) induction motor. Less so with a servo motor (200V, 200W) that drives coarsely, especially at low speeds. (It becomes much smoother if I use lower voltage with higher PWM swing, so I suppose a part of the problem is in low-resolution PWM and long bridge off-to-on delays.)

Switching dead-time problem

Because of the protective time-delay needed when switching MOSFETs on and off, somewhat distorted ‘sine’ signal will be generated, like on the picture below. The distortions are relatively large in the case of a small-amplitude sine signal.

One way to solve the problem is to generate PWM with phase difference as depicted below, for three half-bridges A, B, and C. This would, I guess, eliminate distortions at least for small-amplitude signal. This however cannot be done on ATmega8.

So I tried to solve the problem by counter-distorting the sine-wave generation, but with limited success. Not sure why.


The software is very simple (2kB) and I will not spend much time describing it. After all, it is expected that you experiment and make a solution that best fits your needs.

All three PWM outputs are used simultaneously to generate 3 ‘sine waves’ with 120 degrees phase shift. The PWM outputs work at 15kHz to reduce noise and with 8-bit resolution… When a small amplitude sine wave is generated, the PWM is not changed much above or below 50% duty cycle. When generating maximum amplitude signal, the PWM is changed from 2% to 98% duty cycle in sinusoidal fashion.

To modify the PWM duty cycle in sinusoidal fashion, I programmed timer that generates timer interrupt at fixed intervals (every 0.25 millisecond). Each time the interrupt happens I increase the phase of the sine waves (for a small amount proportional to wanted motor speed) and adjust the PWM duty cycles accordingly.

Of course, with F-V control you need to linearly increase sine wave amplitude as you increase frequency (motor speed). Because there is no current measurement, you should be careful that your programming matches the motor.

Finally, because I had no space on PCB to put pull-down resistors on external inputs, the software enables microcontroller internal pull-up resistors. This means that all digital signals are used as inactive-high / active-low. And, oddly, analog inputs are used in 'inverted way' (+5V is minimum, 0V is maximum).

The ATmega8 pin usage is as follows:

  • D0 – connected to RESET pin
  • D1 – not used
  • D2 - not used
  • D3 - not used
  • D4 - not used
  • D5 - not used
  • D6 - not used
  • D7 - not used
  • B0 - not used
  • B1 - PWM_R
  • B2 - PWM_S
  • B3 - PWM_T (MOSI SPI for in-system programming)
  • B4 - not used (MISO SPI for in-system programming)
  • B5 - not used (SCK SPI for in-system programming)
  • B6 - not used (connected to +5V)
  • B7 - not used
  • C0 - programable input 1 (motor speed - analog input)
  • C1 - programable input 2 (jog)
  • C2 - programable input 3 (run)
  • C3 - programable input 4 (forward/reverse)
  • C4 - LED output
  • C5 – ENABLE bridges output
  • C6 – RESET

If you have questions, suggestions or error reports, just e-mail me... And as you work on your projects you might want to try the Math-o-mir, math notepad software.

Danijel Gorupec, 2015