Tolerance and Monte Carlo: which part limits the flyback
Every part on a board differs from its nominal value. Here you take the flyback whose output is regulated by a TL431 and an optocoupler, let its divider resistors, its inductance and its output capacitor vary within their tolerances in a Monte Carlo analysis, read the output-voltage and peak-current distributions, and rank the parts by how much of the spread each one causes. Then you tighten the part that limits the output and check the yield again. About 20 minutes.
Pictures: a numbered red box is what you click or read, Run is a button, Analysis › Monte Carlo a menu path.
Every number on this page comes from a run of these steps, and a test runs them again and fails when a number here differs from the run (crates/engine/tests/tutorial_flyback_tolerance.rs).
1. Open the flyback with the TL431 loop
Step 1 of 7 · about 1 minChoose File › Open Example › Isolated › Flyback with TL431 and optocoupler.
File.Open Example.Isolated.Flyback with TL431 and optocoupler.
The circuit runs from 12 V to 12 V at 6 W. The TL431 compares the output, divided by Rup and Rlow, with its reference, and the optocoupler carries the error to the primary-side PWM.
2. Prepare the parts that vary
Step 2 of 7 · about 1 minMake three changes before the analysis:
- Keep the full load. The example halves its load at 4 ms. Select the block
load_onand set itsafterto1in the Properties panel, so the load stays and the whole run is one operating point. - One inductance for both windings. Choose
Circuit › Variables, addLm=20u, then selectT1and set bothl1andl2toLm. A core's inductance tolerance moves both windings together, and the analysis can now vary them as one value. - Measure after the loop has settled. Every measurement below reads 5 ms to 6 ms of the 6 ms run. With
C1at the top of its tolerance the output is still recovering at 3 ms; by 5 ms it has settled.
Rup(9.53 kΩ): the upper divider resistor, ±1 %.Rlow(2.49 kΩ): the lower divider resistor, ±1 %.T1: the coupled inductor, both windingsLm= 20 µH, ±10 %.C1: the 100 µF output capacitor, ±20 %.
The tolerances are the ones an engineer picks for this exercise: the grades IEC 60062 codes F (±1 %), K (±10 %) and M (±20 %). Each part is drawn uniformly within its tolerance.
3. Monte Carlo of the output voltage
Step 3 of 7 · about 1 minChoose Analysis › Monte Carlo and fill in the form.
Variables:[{"name":"Rup.r","tol":0.01},{"name":"Rlow.r","tol":0.01},{"name":"Lm","tol":0.1},{"name":"C1.c","tol":0.2}].Number of runs:50.Seed:1. The same seed draws the same 50 sets of parts every time, so the next steps vary exactly the same circuits.Measure: signalv(out), statisticmean, window start5m, window end6m.- Under
More options,Lower limit11.88andUpper limit12.12: the output must stay within 12 V ± 1 %.
Press Run. The 50 simulations take a few seconds.
4. Read the histogram
Step 4 of 7 · about 1 min- The result: the statistics, the yield against the limits and the histogram, with the limits as red lines.
The mean output is 12.065 V with a standard deviation of 86.2 mV; the 50 runs lie between 11.916 V and 12.234 V. Only 39 of the 50 runs stay within 12 V ± 1 %: a yield of 78 %. The window also gives the 95 % confidence interval of the yield, since 50 runs only estimate it.
5. The peak current
Step 5 of 7 · about 1 minOpen Analysis › Monte Carlo again. Keep the variables, runs and seed, set Measure to signal i(S1) with statistic max (same window), clear both limits and press Run.
- The peak current of the switch over the same 50 circuits.
The peak current averages 2.51 A with a standard deviation of 71 mA, from 2.36 A to 2.64 A. Size the switch, the current sense and the core for the top of that range, not for the mean.
6. Which part drives the spread
Step 6 of 7 · about 2 minThe histogram says how wide the spread is, not where it comes from. Press ⌘K to open the command palette, type sensitivity and choose Sensitivity. Fill in Variables Rup.r, Rlow.r, Lm, C1.c, and Metrics {"vout":{"signal":"v(out)","stat":"mean","t0":"5m","t1":"6m"},"ipk":{"signal":"i(S1)","stat":"max","t0":"5m","t1":"6m"}}. Press Run.
- The table, largest first.
Normalizedis the relative change of the metric per relative change of the part: 0.8 means a 1 % larger part moves the metric by 0.8 %.
At the nominal parts the output is 12.067 V and the peak current 2.50 A. A sensitivity alone does not rank the parts: a sensitive part with a tight tolerance can matter less than a dull part with a loose one. Multiply each sensitivity by the part's own spread (a part drawn uniformly within ±tol has a standard deviation of tol/√3) and you get the spread it adds to the metric. The last column checks the ranking against the Monte Carlo itself: the correlation between each part's value and the metric over the 50 runs of steps 4 and 5 (Copy CSV in their windows gives the samples).
The output voltage:
| Part | Tolerance | Sensitivity | Spread it adds (1σ) | Correlation in the 50 runs |
|---|---|---|---|---|
Rup |
±1 % | +0.79 | 0.46 % | +0.70 |
Rlow |
±1 % | −0.79 | 0.46 % | −0.74 |
C1 |
±20 % | 0.00 | 0.00 % | +0.09 |
Lm |
±10 % | 0.00 | 0.00 % | −0.02 |
The peak current:
| Part | Tolerance | Sensitivity | Spread it adds (1σ) | Correlation in the 50 runs |
|---|---|---|---|---|
Lm |
±10 % | −0.50 | 2.89 % | −0.97 |
Rup |
±1 % | +0.79 | 0.46 % | +0.27 |
Rlow |
±1 % | −0.79 | 0.45 % | −0.11 |
C1 |
±20 % | 0.00 | 0.00 % | +0.34 |
Both methods agree. The two divider resistors set the output's spread; the inductance and the output capacitor add nothing to it, because the loop corrects whatever they change. The peak current follows the inductance: in discontinuous conduction the core stores the same energy each period, so a smaller Lm needs a higher current (Ipk = √(2P/(Lm·f)), a sensitivity of −0.5). A correlation of a few tenths for a part whose sensitivity is zero is chance: 50 runs cannot tell it from nothing.
7. Tighten the part that limits the output
Step 7 of 7 · about 1 minThe divider limits the output, so buy better resistors. Open Analysis › Monte Carlo once more, set the measurement back to v(out) mean with the limits 11.88 and 12.12, change the tolerance of Rup.r and Rlow.r to 0.001 (±0.1 %) and press Run.
- The narrower histogram, well inside the limits.
The standard deviation falls from 86.2 mV to 8.6 mV; the runs lie between 12.051 V and 12.083 V, and 50 of 50 pass: a yield of 100 %. What is left is the offset of the mean, 12.066 V: the divider was chosen for 12.06 V, including the TL431's REF current through Rup. From now on the nominal values, not the tolerances, are the largest error of the output.
What you learned
- A Monte Carlo analysis varies every part at once within its tolerance and gives the distribution, the yield against limits and the worst run.
- The same seed draws the same parts, so several measurements can be read from the same set of circuits.
- To find the part that limits a specification, weigh each part's sensitivity by its own tolerance, and check the ranking against the correlation in the Monte Carlo samples.
- In a regulated converter the feedback divider sets the output's accuracy; the power parts set the stresses, such as the peak current.
Next: Python scripting runs the same analyses from a script, or go back to the tutorial list.






