Construct a 120 VAC “pure sine wave” inverter using an Arduino microcontroller and an H-bridge. This minimalist DIY design sets the stage for advanced applications such as Uninterruptible Power Supplies (UPS) and three-phase inverters for Battery Energy Storage Systems (BESS).
SAFETY WARNING: The featured device produces a high voltage AC signal. Use proper insulation techniques or controls to prevent exposure to high voltage. Perform this experiment under the direct supervision of a qualified mentor. Always follow local, state, and federal regulations.
Build and troubleshoot the circuit using the DC motor introduced in this previous article. Install the transformer only after the circuit is operating correctly. Troubleshooting with the motor is safer and relatively easy as the circuit may be reconfigured to test individual MOSFETs and associated drivers.
What is a pure sine wave inverter?
The pure sine wave inverter is an electronic device used to convert DC voltage to a sinusoidal voltage. The typical inverter is used for mobile or backup application to power 120 VAC 60 Hz (American) devices from a large battery. The contrasting technology is the square wave or modified square wave inverters. While the alternatives are simpler, they do not provide a sinusoid output. This is undesirable for motors and other sensitive electronics. The motors will buzz and possibly overheat. The EMI associated with the square wave inverter can also cause objectionable interference in sensitive electronics such as audio and radio equipment.
The design presented in this engineering brief is a solid demonstrator as it features an H-bridge capable of developing a 120 sinusoidal signal from a 15 VDC source. The simple design and nature of the breadboard limit the output to about 10 W with the stipulation that the load should be resistive such as the 7 W 120 V incandescent bulb shown in Figures 1 and 2. Without feedback the waveform will distort. This is especially apparent when driving a load such as a LED light bulb. Finally, the design has no protective circuitry other than that which is provided by the B&K Precision 1550 bench power supply shown in Figure 2.
Figure 1: Bench setup for the 120 VAC inverter. This is for demonstration purposes only as the transformer’s 120 VAC terminals are exposed. Use proper insulation techniques or controls to prevent exposure to high voltage.
SAFETY: Protect your PC by disconnecting the Computer’s USB port whenever 15 VDC supply is activated. This protects against an inadvertently connection between the 15 VDC supply and any Arduino pin.
Failure to heed this warning could result in the destruction of your PC’s USB port, processor, or motherboard.
Instead, power the Arduino from an independent source such as a low-cost cell phone charger. Additionally, you may also wish to purchase a USB port isolator to protect your PC.
This article is the fifth in a series. Please review the earlier articles as they present the foundation upon which the inverter is based. The last article is particularly important, as the inverter shares the same MOSFET driver. In fact, the only difference is that the DC motor is replaced with a transformer and incandescent light bulb as shown in Figures 1 and 2.
- Guide to Bootstrap Operation in a MOSFET Gate Drive Circuit
- Breadboard a Bootstrapped MOSFET Motor Driver with Arduino PWM Control
- H-Bridge Motor Drive Dynamics: Identification of Current Spikes
- Breadboard an Arduino-based H-bridge Motor Controller
Figure 2: Bench setup featuring a B&K power supply, Arduino microcontroller, and Digilent mixed signal analyzer.
Circuit design
The circuit is identical to the one presented in Breadboard an Arduino-based H-bridge Motor Controller. For convenience, the schematic is included as Figure 3. Note that the DC motor is replaced with a Signal Transformer A41-25-24 and a 7 W 120 V incandescent light bulb. As seen in Figure 1, one of the transformer’s 12 VAC windings is connected to the H-bridge output. The 115 VAC secondary windings are connected in series. The transformer is therefore wired in a 12:230 step-up configuration. Note that the 12 VAC winding could have been connected in parallel. This is not considered necessary as the breadboard is already operating near its 1 A limit.
Note that the potentiometer in Figure 3 was replaced by a signal generator. This simplifies the design as the sine wave generation is outsourced.
Tech Tip: The Arduino microcontroller can generate the sinusoid. A common method is known as Direct Digital Synthesis (DDS). It involves a look up table describing a sinusoid signal, an index variable, an adder, and a timer. The idea is elegant, as the index points to a location inside the sinusoid lookup table. The adder’s jump size (increment), plus timer determine the frequency.
Figure 3: Schematic of the H-bridge featuring two IR2110 drivers and the Arduino Nano Every. The Arduino is powered via its USB port (not shown).
Software design
The code is also related to the previously described DC motor controller. However, several changes were required as shown in this modified sketch. The most significant changes involve speed to prevent flickering of the light.
Recall that the setpoint is derived from an external signal generator. The first step is to read the analog value and then scale the results. This provides drive for the positive and the negative half cycles. The code is designed to operate as quickly as possible on the Microchip (Atmel) ATmega4809 within the constraints of the Arduino environment. This includes turning off the interrupts using the cli( ) statement.
/**** CAUTION **** **** CAUTION **** **** CAUTION **** **** CAUTION **** **** CAUTION ****
*
* This code is written specifically for an Arduino Nano Every. It will NOT work on other Arduino
* microcontrollers, as it depends on direct SFR manipulation to operate in a Fast PWM mode.
* For fast PWM technique refer to https://forum.digikey.com/t/fast-pwm-for-the-arduino-nano-every/40023
*
*/
#define LL_PIN 7
#define LH_PIN 6 // Fast PWM
#define RL_PIN 4
#define RH_PIN 3 // Fast PWM
#define VREF_PIN A7
#define MAX_PWM_VAL 250
enum Direction {
CW = true,
CCW = false
};
Direction direction;
void setup( ) {
pinMode(LL_PIN, OUTPUT);
pinMode(LH_PIN, OUTPUT);
pinMode(RL_PIN, OUTPUT);
pinMode(RH_PIN, OUTPUT);
TCB0_CTRLA = 0b00000011; // Fast PWM for pin D6
TCB1_CTRLA = 0b00000011; // Fast PWM for pin D3
}
void loop( ) {
bool last_direction;
cli( ); // Disable the Arduino ISRs for maximum speed e.g., disable millis( )
while (1) {
uint16_t setpoint = analogRead(VREF_PIN);
// Potentiometer set to middle turns off the motor. Middle and above yields CW, while below middle yields CCW.
// Recall that analogRead( ) return a value from 0 to 1023 while analogWrite( ) accepts a value between 0 and 255.
if (setpoint > 512) {
direction = CW;
setpoint = (setpoint - 512) >> 1;
} else {
direction = CCW;
setpoint = (512 - setpoint) >> 1;
}
if (setpoint > MAX_PWM_VAL) {
setpoint = MAX_PWM_VAL;
}
if (direction != last_direction) { //Stay out unless needed
last_direction = direction;
digitalWrite(LL_PIN, LOW); // Turn everything off
digitalWrite(RL_PIN, LOW);
analogWrite(RH_PIN, 0);
analogWrite(LH_PIN, 0);
if (direction == CW) {
digitalWrite(RL_PIN, HIGH); // Enable the appropriate low side driver
} else {
digitalWrite(LL_PIN, HIGH);
}
}
if (direction == CW) {
analogWrite(LH_PIN, setpoint); // Always set the appropriate PWM
} else {
analogWrite(RH_PIN, setpoint);
}
}
}
Tech Tip: Arduino code is a hardware abstraction designed to make the coding experience easy and consistent across Arduino microcontrollers. There are hidden background tasks that depend on Interrupt Service Routines (ISR) such as the millis( ) and associated routines. These can cause unexpected timing deviations in high performance circuits. In this application the ISRs are disabled by issuing the cli( ); statement. Also, a while(1) loop was implemented to prevent the Arduino from leaving the loop( ) function.
Use these techniques with care as they break some of the user-friendly Arduino functions.
Results
Figure 4 presents the waveform produced by the inverter while driving the 7 W incandescent light bulb. The simple circuit produces a recognizable sinusoid with a 170 volt peak amplitude (120 VRMS). There is observable distortion as the signal crosses through zero. You may recognize this as crossover distortion caused by the H-bridge shifting polarity. There are also high-frequency artifacts as there is zero filtering on the on the H-bridge or output transformer.
All things considered, this is a reasonable signal from such a simple circuit. It would certainly benefit from feedback and filtering. This gives us something to look forward to, as captured in the next steps section.
Figure 4: The rudimentary inverter produces a recognizable sinusoid. Crossover distortion is present as the H-bridge switches polarity.
Commutation sequence
The commutation sequence for the H-bridge is shown in Figures 5 and 6. Each MOSFET drive waveform is identified by its position including left or right, as well as upper and lower. As an example, the top (pink) waveform is for the Right High (RH) MOSFET. In Figure 5 we see the RH/LL and LH/RL drive pairs used to produce the positive and negative sinusoid half cycles.
Tech Tip: This project may be better understood by visualizing the Arduino as a modulator. It accepts a 0 to 2.5 to 5 VDC input. It then performs an approximate linear transfer, converting the input voltage into PWM drive signals which are then sent to the H-bridge. In theory, the output of the H-bridge is a linear reproduction of the input voltage. Feed the Arduino a triangle input voltage and get a triangle output waveform. Send a sinusoid, get a sinusoid.
Figure 6 presents a close-up image for the Left High (LH) MOSFET. This is the critical waveform used to develop the sinusoid. The waveform starts out with a minimal duty cycle. The duty cycle increases to its maximum value at about 4.17 ms corresponding to the peak voltage of the half cycle. Recall that a 60 Hz waveform has a period of 16.67 ms with peaks at approximately 4.17 and 12.5 ms.
Figure 5: Demonstration of the H-bridge commutation sequence. The high-side MOFETS (right high and left high) receive the PWM signal.
Figure 6: Close-up image showing the changes in PWM duty cycle for the Left High (LH) MOSFET.
Efficiency
The circuit is approximately 64% efficient. This input power is about 11 W based on a supply of 15 VDC drawing 0.73 A. The output is estimated as 7 W, assuming the bulb is a true 7 W when fed with a pure 120 VRMS waveform. This gross estimate suggests room for improvement. However, it is optimistic as the MOSFETs are cool to the touch.
Next steps
The featured design is a teaching tool. The performance is limited by the hardware and software. There are many ways to improve the circuit including:
-
Attend to EMI by adding filtering.
-
Improve the fluidity of the PWM generation using bare-metal programming, an FPGA, or a purpose-built “motor control” microcontroller with dedicated PWM drive peripherals.
-
Get good at failure analysis, and incorporate current monitoring and automatic shutdown.
-
Incorporate Direct Digital Synthesis (DDS) to generate the sinusoid waveform.
-
Design a PCB that can handle higher currents with a design centered around a modern MOSFET driver.
-
Go big with three-phase circuits and IGBTs (discrete or modular).
-
Incorporate feedback to monitor and control the output signal.
-
Add telemetry allowing the inverter to be monitored.
-
Reverse engineer COTS inverters to determine how reliable designs can be produced at low cost.
-
Have fun!
Parting thoughts
The H-bridge is a versatile circuit, equally useful for driving a DC motor or a pure sine wave inverter. The featured circuit shows that the two technologies share the same space. As you explore electronics you will recognize this familiar pattern in smaller power supplies as well as larger three-phase drives.
Remember to play safe, as this inverter is no toy. It’s every bit as dangerous as a line-powered device with a 340 Vp-p output signal. Find a mentor who can challenge and support your work.
As always, please leave your comments and suggestions below. There are brilliant people in this community ready to assist.
Please give a thumbs up if this note was useful.
Best wishes,
APDahlen
Related Information
Please follow these links to related and useful information:
- Digikey’s product selection guides
- DigiKey’s Arduino Education Materials
- IR2110 - Infineon Technologies
About this author
Aaron Dahlen, LCDR USCG (Ret.), serves as an application engineer at DigiKey. He has a unique electronics and automation foundation built over a 27-year military career as a technician and engineer which was further enhanced by 12 years of teaching (partially interwoven with military experience). With an MSEE degree from Minnesota State University, Mankato, Dahlen has taught in an ABET-accredited EE program, served as the program coordinator for an EET program, and taught component-level repair to military electronics technicians. Dahlen has returned to his Northern Minnesota home and thoroughly enjoys researching and writing educational articles about electronics and automation.
Highlighted experience
Dahlen is an active contributor to DigiKey’s Technical Forum. At the time of this writing, he has created over 200 unique posts and provided an additional 600 forum posts. Dahlen shares his insights on a wide variety of topics including microcontrollers, FPGA programming in Verilog, and a large body of work on industrial controls.