Pure sine inverter control methods? - Page 1
Forum section: electronics / projects

author: ifonlyeverything
author_rank: Regular Contributor
timestamp: January 07, 2025, 09:23:15 pm
content: I'm interested in DIYing a low power pure sine inverter. The goal is to learn something, more so than creating a "good" inverter.It looks like the usual way to do this is isolated DC-DC step-up followed by SPWM inverter. I've seen some amateur projects put a control loop on the DC-DC step-up and run the SPWM inverter open loop at some fixed duty cycle. I've inferred that commercial products have a control loop on both the DC-DC step up and the inverter.What does the latter option typically look like? Many commercial products use MCUs for the inverter -- so is this like PID? Are there any alternative schemes that avoid PIDs and having to tune them? What would it look like if someone were inclined to do this with analog building blocks?

author: PCB.Wiz
author_rank: Super Contributor
timestamp: January 07, 2025, 10:15:06 pm
content: Quote from: ifonlyeverything on January 07, 2025, 09:23:15 pmWhat voltage, frequency and power do you target, and what load variances ?

author: jbb
author_rank: Super Contributor
timestamp: January 07, 2025, 10:18:56 pm
content: Hi thereMaking a pure sine wave inverter will definitely teach you a lot.Are you interested in single or three phase? Are you interested in a standalone inverter or grid connected?If you’re mostly interested in learning about the methods, I suggest you build a scale model with a step down transformer (maybe 24V AC?) - that will mitigate a lot of safety risks.It’s very common to build an inverter using a DC-DC converter, a constant voltage DC bus and then a DC-AC inverter stage.On the control front, I’d recommend a 32 bit processor with floating point support (you can do it all in fixed point but that’s a whole extra layer of learning) eg an Arm Cortex M. I would advise against analog implementations because you need operations like sine and cosine.As it comes to implementation, I suggest you have a look onwww.ti.comor other manufacturer’s websites for reference designs.Here’s a potential path forward:- Arm Cortex M microcontroller - maybe STM32G something??- H bridge inverter- measure inverter phase current(s) with isolated LEM current sensor(s)- measure AC line voltage(s) and DC link voltage(s) with isolated ADCs- use symmetrical triangular PWM- synchronise ADC sampling to PWM unit so it samples at twice per PWM cycleSoftware blocks:- ADC sampling engine- if grid connected: software Phase Locked Loop (PLL) to extract clean reference sine and coding waves form the noisy mains AC signal- emergency stop for excessive current or DC link voltage (test this before proceeding to PWM control)- current control loop using Park’s Transformation and PI controllers (note the Differential terms in PID tend to be too noise sensitive). If grid connected, include line voltage feedforward- reference generation for real power current ID and reactive power current IQ. Depends heavily on standalone / grid connected- PWM output engine (should be simple for an H bridge inverter)

author: ifonlyeverything
author_rank: Regular Contributor
timestamp: January 07, 2025, 11:02:06 pm
content: Quote from: PCB.Wiz on January 07, 2025, 10:15:06 pmSingle phase 120V AC RMS, 60 hz, 100W. Being able to power a laptop power adapter would be cool but I would be happy with lighting up an incandescent light bulb.Quote from: jbb on January 07, 2025, 10:18:56 pmSee above response + standalone, I do not trust myself interfacing with the grid.I do have an STM32G474 board (https://github.com/WeActStudio/WeActStudio.STM32G474CoreBoard) so I was hoping to use that. Thanks for the overview!

author: jbb
author_rank: Super Contributor
timestamp: January 08, 2025, 01:05:39 am
content: If you're going for 120V output, Ithoroughlyrecommend using isolated communications and programming (JTAG) cables.I haven't done a standalone inverter before (have done grid connected solar inverter), so I'm not sure about good approaches for waveform control.A basic overview would be:generate a voltage reference v_ref using a sine function. This can be a fixed 60 Hz sine wavemeasure the AC output voltage (practically, the voltage across the AC filter cap) v_acfeed voltage error v_ref - v_ac into a voltage controller, which outputs a current reference i_ref. This is known as the outer loop controllermeasure the inverter output current (i.e. inductor current) i_invfeed current error i_ref - i_inv into a current controller, which outputs an inverter voltage reference e_inv. This is known as the inner loop controllermeasure the DC link voltage v_dcgenerate inverter duty command d = e_inv / v_dc; this reduces the impact of changes in the DC link voltageapply inverter duty command to the PWM stage and thence the output stageProportional-Resonantcontrollers may be useful here. They are like a Proportional-Integral (PI) controller except the integral part is transformed from "at DC" to "at a specified frequency". I have previously used them to great effect in a 3 phase design.Please note that lighting up a light bulb will be much easier than providing nice sine wave power to a power brick, because light bulbs are (largely) linear (i.e. draw nice sinusoidal currents) while power bricks are nonlinear (i.e. draw lumpy non-sinusoidal currents).

author: BrianHG
author_rank: Super Contributor
timestamp: January 08, 2025, 01:49:30 am
content: You could cheat.Use a MCU with an ADC and DAC to align with the grid reference and then generate and feed a 60hz sine wave out into this class D amp:https://www.ti.com/product/TPA3255Drive the Class D amp IC in mono parallel mode for the best current output with a theoretical peak above 400 watts.With a 48v supply, you will want a 120v to ~28-32v AC transformer, preferably a toroid, used in reverse.You should get a fairly fine efficiency and with a toroid, a minuscule idle current.

author: Someone
author_rank: Super Contributor
timestamp: January 08, 2025, 02:20:26 am
content: Quote from: ifonlyeverything on January 07, 2025, 11:02:06 pmYou can do both of those with DC (there may be some laptop bricks that won't, but I've not come across one yet).

author: mtwieg
author_rank: Frequent Contributor
timestamp: January 08, 2025, 02:00:12 pm
content: I don't think inverters typically use any feedback on the inverter stage. At most they will use some feedforward to compensate for ripple and droop on the regulated DC bus voltage.So basically duty cycle on the inverter is modulated as d(t) = Vac*sin(2*pi*fac*t)/Vbus(t), where Vbus(t) is the measured bus voltage, Vac is the desired output amplitude, and fac is the desired output line frequency.Actual output feedback is definitely needed in the case of a grid tie inverter, though.

author: David Hess
author_rank: Super Contributor
timestamp: January 08, 2025, 02:58:39 pm
content: Quote from: ifonlyeverything on January 07, 2025, 09:23:15 pmThe digital method uses DDS (direct digital synthesis) to adjust the duty cycle of the switching output to produce a sine wave. A PID might or might not be used to adjust the amplitude for load.The analog method does the same thing but with a sine oscillator replacing the DDS.In a UPS, the DDS or analog oscillator is likely phase locked to the AC line.

author: peter-h
author_rank: Super Contributor
timestamp: January 09, 2025, 10:59:01 pm
content: Generating a sinewave for a DAC is easy. You can use a lookup table, or for more smoothness, more samples per cycle, just generate it e.g.Code:// Compact sin(x) function which doesn't need math.h// Uses Horner's method// i is from 0 to SPC-1#define PI 3.14159265358979323846#define SCALE 13107int sin2(int i){double rad = 2*PI*i/SPC, term=rad, sin=rad, old_sin=0;//for (int n=3; sin != old_sin; n+=2)for (int n=3; (sin != old_sin) && (n < 30); n+=2){old_sin = sin;term *= (rad*rad) / (-n * (n-1));sin += term;}return (sin * SCALE) + (sin >= 0 ? 0.5 : -0.5);}I did two 400Hz outputs on a 32F417 for LVDT emulation for aircraft pitch/roll.Then you sync it to the zero crossings of the mains waveform, doing a slow adjustment (PID may be an overkill but you do want the outputfrequencyto be right) on the sample rate - e.g. like hereI posted various threads here on this topic, years ago.Then how you do the output depends on the desired efficiency. If you are not too bothered, and don't mind having a fan, just do a Class B "audio" amplifier coming out via a transformer. To do it efficiently you need to synthesize the output sinewave using PWM.Or you can do it all in analog hardware (loads of ways of generating a sinewave) but it's a nice project to learn about programming.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: January 10, 2025, 01:23:37 am
content: Quote from: ifonlyeverything on January 07, 2025, 09:23:15 pmDepends how 'analog' you mean.For 100% Analog, you could use a Quad OpAmp to generate a sine wave, and an Audio Amplifier to drive a transformer.That's analog, but not very efficient.To use more readily available parts, and slash power losses, you might choose to use a Class-D Audio Amp to drive a transformer.Sine wave does not need to be super pure, so you may choose precision over THD.A very simple, 'least variables' sine gen, is to generate a triangle first using single RC timing elements, then clip that slightly to flatten the tops. (~1.629ms flats at 50Hz gives nearest to sine)Then feed that into a low pass.With a good voltage regulator, that gives precise amplitude, and timing is as precise as your RC.If you want more precise timing, you can generate 50Hz from a crystal oscillator + divider.

author: Analog Kid
author_rank: Super Contributor
timestamp: January 10, 2025, 01:43:50 am
content: Here's a sine-wave inverter project I've been working on:I simulated the resistor ladder, both in LTspice and on a breadboard, and it should yield a pretty accurate rendition of a sine wave.Still not sure about the PWM part, but in theory, this should work.

author: Conrad Hoffman
author_rank: Super Contributor
timestamp: January 10, 2025, 04:37:43 am
content: Invertrons and such used a sine oscillator, high current audio amp and a step-up transformer. I've strung together the same things for very low power loads like a synchronous motor turntable, but higher power needs bigger parts!

author: uer166
author_rank: Super Contributor
timestamp: January 10, 2025, 04:47:38 am
content: I made this exact thing with a STM32G474, had lots of fun!:https://www.eevblog.com/forum/projects/experimental-48v-gt120vac-60hz-inverter

author: peter-h
author_rank: Super Contributor
timestamp: January 10, 2025, 07:28:50 am
content: Arguably the output should be synced to the mains input (if you are building a UPS) to keep things like clocks running right.