Grid-tie inverter: lock to the grid and control the current
A grid-tie inverter feeds power into the mains. It must follow the grid's phase, push a current that is a clean sine in step with the voltage, and keep doing so when the power asked for changes or the grid voltage sags. You open the single-phase gridTieInverter example, read its phase-locked loop (PLL) and current controller, and measure the current against the voltage. Then Auto Design draws a three-phase grid-tie inverter with a dq current loop, and you read its loop, jump the grid's phase, step the active and the reactive power, and sag the grid. About 30 minutes.
Pictures: a numbered red box is what you click or read, ▶ Run is a button, File › Open Example a menu path, ⌘⇧Y a key (⌘ is Cmd on a Mac, Ctrl elsewhere).
1. Open the example
Step 1 of 14 · about 1 min2. Read the power stage
Step 2 of 14 · about 1 minA 400 V DC source feeds a full bridge. An LCL filter (an inductor, a capacitor with a damping resistor, and a second inductor) joins the bridge to a 230 V, 50 Hz grid. The nets oa and ob (the bridge outputs) and the gate signals are drawn as labels, so the picture shows the stage without long wires.
Vdc: the 400 V link.Qah: the upper switch of the first leg;Qalbelow it, andQbhandQblin the second leg. Both legs share one carrier and take mirrored duties, so the output has three levels and the ripple is at 40 kHz.L1: 2 mH on the bridge side.Rd: a 4 Ω damping resistor in series with the filter capacitor.Cf: 5 µF. WithL1andL2it resonates at 2.8 kHz;Rddamps that peak.L2: 1 mH on the grid side. It keeps the 20 kHz and 40 kHz ripple out of the grid current.Vg: the grid, 325 V peak (230 V rms) at 50 Hz. The ammeterAmGbesideL2gives the grid currentig, and the voltmeterVMggives the grid voltagevg.
3. Read the control
Step 3 of 14 · about 1 minThe control sits below the power stage and meets it through the labels vg, ig and the gate signals.
PLL: measures the angle of the grid fromvgand givesth.Ref: turnsthand the two constantsId(0) andIq(−10 A) into the referenceiref= 10 A · sin θ, a sine that is in phase with the grid because it uses the grid's own angle.PR: the current controller. A plain PI cannot follow a sine without error, so this is a proportional-resonant controller:Kp10 V/A, plus a resonance at 50 Hz with a gain of 1000 V/A. At 50 Hz the loop gain is so high that the current ends on the reference with almost no error in amplitude or phase.Vff: adds the measured grid voltage to the controller output, so the controller only supplies the drop across the filter.Da: the duty of the first leg,0.5 + v/(2·Vdc);Dbmakes the mirror image for the second leg. Each goes to a PWM block at 20 kHz and, through dead-time blocks, to the gates.
4. Run it and compare the current with the voltage
Step 4 of 14 · about 1 minClick ▶ Run, then Open in Separate Window at the top right of the scope, so the scope has a window of its own (the next steps use it). The scope shows the grid voltage vg on the top axis and the grid current ig below it, each on its own axis.
vg: the grid voltage, 325 V peak.ig: the grid current. It reaches its 10 A peak within the first cycle (the table says 10.17 A over the whole run, a little more than 10 A during the start) and is a sine in phase withvg.
5. Choose a window of whole cycles
Step 5 of 14 · about 1 minThe scope folds the table away while the plots would get less than half its width, so click Measurements in the toolbar to show it. Click Cursors (Shift+C) and place the two lines at 80 ms and 120 ms: two whole line cycles, after the start.
Cursors: shows two vertical lines and the values at each.- The line over the table now ends with
cursors 80ms – 120ms. Every figure below is taken over that window.
6. Read the distortion of the grid current
Step 6 of 14 · about 1 minClick Measurements to show and tick THD.
Measurements to show: the columns of the table.THD: the total harmonic distortion up to the 50th harmonic, as a share of the fundamental.
7. Read the power factor
Step 7 of 14 · about 1 minPress Esc to close the picker. On the scope panel's Power tab, choose vg in the first list and i(AmG) in the second (the ammeter's own current, the same as ig), then click Add power.
- The power row of
vgandi(AmG). TheTHDcolumn is on theSummaryandSignalstabs: 3.72 % forig(scope.measurewith the fundamental given as 50 Hz reads 3.60 %), 0.00 % forvg, as the grid source is a pure sine. PFof the pair: 0.999, fromP= 1.626 kW andS= 1.628 kVA. The distortion alone gives 1/√(1 + 0.0372²) = 0.9993, so the fundamental of the current is in phase with the voltage within a degree (about 0.6°, the current slightly leading).Q, the reactive power √(S² − P²) (tick it in the picker's Power group), is 62 var: nearly all of it is the distortion, and the figure has no sign. The expected power is 325 V · 10 A / 2 = 1.63 kW.
8. Let Auto Design draw a three-phase grid-tie inverter
Step 8 of 14 · about 1 minThe example is single phase. For three phases, Auto Design takes an inverter spec: a 700 V DC link, a 400 V line-to-line grid, 10 kW, and the current distortion limit of IEEE Std 1547. Its form has only DC converter rows, so give the spec on the console (⌘⇧Y; first close the scope window with Dock Back). A run replaces the open circuit, so save your work first.
design.auto {"spec":{"vdc":700,"grid":{"vll":400},"pout":10000,"thd":"ieee1547"}}
- The headline:
Three-phase two-level inverter, 10 kHz: all 2 checks pass. Total rated-current distortion: 0.63 % against at most 5 %. Below it: power factor 0.997 at the light 10 % load, DC-link ripple 2.65 V (14 V allowed), efficiency 98.8 %.
The reply holds the design. The bridge inductor L1 is 2.86 mH (20 % current ripple at 10 kHz), the grid-side inductor L2 154 µH, the filter capacitor 9.95 µF with a 1.28 Ω damper, resonating at 4.17 kHz, and the DC link 82 µF. The grid-side current loop is a dq PI: Kp 12.4 V/A and Ki 5118 V/(A·s). It crosses over at 677 Hz with 72° of phase margin and 6.5 dB of gain margin. The PLL has a natural frequency of 15 Hz and a damping of 0.71 (Kp 133, Ki 8883).
Design › Design Steps › Current Loop designs the current loops of a motor from its R and L, and of a grid-tie inverter from its LCL filter. On this design it sees L1 + L2 = 3.02 mH and proposes Kp 12.45 V/A and Ki 5131 V/(A·s), crossing over at 656 Hz with 72.7° of phase margin and 6.5 dB of gain margin: gains within 1 % of Auto Design's.
9. Read the three-phase circuit
Step 9 of 14 · about 1 minPress Esc to close the result. The controller is one module, Ctrl; entering it (circuit.enterSubsystem) shows its blocks.
Vdc: the 700 V source, behind a small model of its impedance and the DC-link capacitor.Qah: the upper switch of the first of three legs.L1a: the bridge-side inductor of phase a; phases b and c repeat the filter below it.Cfa: the filter capacitor, with its damping resistor above it.L2a: the grid-side inductor. The ammeterAmaand the voltmeterVMaafter it giveiaandva.Grid: the three-phase grid, 400 V line to line. It has the parameterssagDepth,sagStartandsagEndfor a voltage sag.Ctrl: the controller. Its pins on the left are the measured phase currents, the phase voltages and the DC voltage; on the right the six gate signals.
Inside Ctrl, the PLL gives the angle th; Park transforms turn the grid voltage into vd and vq and the current into idm and iqm; the references are Idref = Pref/(1.5·Vpk) and Iqref = −Qref/(1.5·Vpk), so P = 1.5·vd·id and Q = −1.5·vd·iq. Two PIs add the filter's drop to the measured grid voltage, and space-vector modulation drives the bridge. Two math signals, P and Q, are added to the scope for the next steps. They take P = 1.5(vd·id + vq·iq) and Q = 1.5(vq·id − vd·iq).
10. Run it and read the phase current
Step 10 of 14 · about 1 minClick ▶ Run. When the run ends, click Show results on its notice, then Open in Separate Window on the scope, and place the cursors at 80 ms and 120 ms again.
va: the phase voltage, 326.6 V peak.ia: the phase current, a sine in phase withva, 20.5 A peak (14.4 A rms), with a distortion of 0.63 %. The power row forvaandiareads 3.333 kW and a power factor of 1.000: three phases give 10 kW.
11. Jump the grid's phase and watch the PLL lock
Step 11 of 14 · about 1 minPress ⌘⇧Y to open the console (first click Dock Back on the scope). Type these two lines, each followed by Enter:
simulation.tune {"component":"Grid","key":"phase","value":120}
simulation.continue {"duration":0.12}
Console: every menu item is a command, and the console runs any of them.simulation.tunemoves the grid's phase from 90° to 120° at the end of the run, 0.12 s. The inverter's state is kept.simulation.continueruns another 0.12 s from there.
Click the Scope tab and Open in Separate Window.
Ctrl.vq: the q-axis grid voltage, which is the PLL's error: zero when the PLL is locked. The 30° jump puts it at 327 V · sin 30° = 163 V. It swings to −35 V and is within 2 V of zero 60 ms later, three line cycles, as a PLL with a 15 Hz natural frequency and 0.71 damping settles. A faster PLL would lock sooner and pass more of a distorted grid into the current.ia: the phase current. It has a spike of 46 A that lasts a few milliseconds, then goes on with the same 20.5 A peak: the current loop does not wait for the PLL, it follows the angle the PLL has at each moment.
12. Step the active power
Step 12 of 14 · about 1 minType these two lines on the console:
simulation.tune {"component":"Ctrl.IdRef","key":"value","value":10.2}
simulation.continue {"duration":0.08}
P: between the cursors, 280 ms to 320 ms, it is 4.997 kW. The step took the power from 10 kW down within about 5 ms: the d-axis current is controlled directly, so the active power follows at the speed of the current loop (677 Hz).Ctrl.idm: the measured d-axis current, 10.2 A. This is the new reference:Idref = P/(1.5·Vpk)= 5000 W / (1.5 · 326.6 V).IdRefis a constant block that held the expressionIdref, and the tune replaces it with 10.2 A.
13. Step the reactive power
Step 13 of 14 · about 1 minsimulation.tune {"component":"Ctrl.IqRef","key":"value","value":-10.2}
simulation.continue {"duration":0.08}
P: unchanged at 4.997 kW through the step.Q: from 0 to 4.997 kvar, a share of the apparent power of 7.07 kVA (a power factor of 0.71), within about 10 ms. A negativeIqrefgives a positiveQinQ = 1.5(vq·id − vd·iq). The phase current grows from 10.2 A to 14.4 A peak, the vector sum of the two axes.
The two axes do not disturb each other: Q moves, P does not.
14. Sag the grid
Step 14 of 14 · about 1 minA grid that drops to half its voltage for 40 ms, starting at 440 ms:
simulation.tune {"component":"Grid","key":"sagEnd","value":0.48}
simulation.tune {"component":"Grid","key":"sagStart","value":0.44}
simulation.tune {"component":"Grid","key":"sagDepth","value":0.5}
simulation.continue {"duration":0.12}
(The end is set first because a sag must end after it starts, and both start at 0.)
va: the phase voltage falls from 326.6 V to 163.3 V peak at 440 ms and comes back at 480 ms.ia: the grid is an ideal source, so the voltage step reaches the filter capacitors at once, and the phase current spikes to 111 A for a millisecond, five times the rated peak of 20.4 A. The d-axis current is back within 10 ms. Between the cursors, 450 ms to 470 ms, the current is still 14.4 A peak (10.2 A rms).P: with the same current and half the voltage, the power is half, 2.499 kW (andQ2.498 kvar). The controller keeps the current, not the power, and it has no current limit. The DC link holds above 695 V throughout.
Auto Design checks the same thing when the spec has "rideThrough":{"residualPu":0.5,"duration":0.15,"maxCurrentPu":1.5}: this design passes it, with a bridge-side current of 1.24 per unit against the 1.5 allowed. When a design fails the row, the report says what to try: a current limit in the controller, a higher switching frequency, or a grid impedance.
The same steps from a script
powercraft-cli run \
--cmd file.openExample --params '{"name":"gridTieInverter"}' \
--cmd simulation.run --params '{}' \
--cmd scope.measure --params '{"signals":["ig"],"t0":"0.08","t1":"0.12","thd":{"fundamental":50},"power":{"v":"vg","i":"ig"}}'
The reply gives power.powerFactor 0.9993, power.real 1626 and thd.ig.thdPercent about 3.6. The three-phase part needs Voltecx Cloud, because design.auto runs there:
powercraft-cli run --new '{}' \
--cmd design.auto --params '{"spec":{"vdc":700,"grid":{"vll":400},"pout":10000,"thd":"ieee1547"}}' \
--cmd scope.addMath --params '{"expr":"1.5*(Ctrl.vd*Ctrl.idm+Ctrl.vq*Ctrl.iqm)","name":"P"}' \
--cmd simulation.run --params '{}' \
--cmd simulation.tune --params '{"component":"Ctrl.IdRef","key":"value","value":10.2}' \
--cmd simulation.continue --params '{"duration":0.08}' \
--cmd scope.measure --params '{"signals":["P"],"t0":"0.14","t1":"0.2"}'
The last scope.measure gives a P of about 5 kW. Add the math signal before the run: a later scope.addMath changes the circuit, and simulation.tune refuses a circuit that changed since the run.
Back to the learning path.














