# 00 | Course architecture and safety boundaries

**AI disclosure:** This course was fully AI-generated. It was reviewed against manufacturer documents cited in each chapter, but it is not a safety approval.

This course explains how a small electronic product switches a 230 V lamp: AC power and energy, rectifiers and offline supplies, insulation, protective components, thyristors and triacs, LED-lamp behaviour, firmware fault behaviour, layout, enclosure and test planning. It grew out of a shorter lesson written for the Lambka project and keeps Lambka as its worked case study. The theory, numerical tools and review methods apply to any mains-connected switch, relay controller or dimmer.

The course is for an electronics graduate or an experienced hobbyist who has not yet designed a mains product. It uses phasors, simple differential equations and datasheet reading, and derives the mains-specific results. Allow roughly **35–50 hours**, including calculations and the optional low-voltage experiments. **No exercise requires working on a live mains circuit.**

## The Lambka case study

Lambka is a Wi-Fi controlled lamp switch for one 230 V LED lamp. The loose prototype used a 5 V AC/DC module, a cheap solid-state relay board and a resistor–capacitor branch across the lamp to stop the bulb glowing when off. The pilot PCB **p1** (22 October 2026) replaces it with an ESP-12F module, an MOC3063 zero-cross opto-triac driving a BT136-600E triac, an HLK-5M05 isolated 5 V module and an AMS1117 3.3 V regulator. Its schematic and two-layer layout passed the project's CAD checks, including a 6 mm mains-to-low-voltage rule. As of 2 November 2026 the board has not been ordered, built or tested. The board record `hw/pilot/README.md` in the Lambka repository is the source of truth for the circuit; this course summarises it and does not change it.

<figure><img src="figures/p1-blocks.svg" alt="Block diagram of the Lambka p1 board. On the mains side: terminal, fuse and MOV, triac and lamp. Across the barrier: the HLK-5M05 module and the MOC3063 optocoupler. On the low-voltage side: AMS1117 regulator, ESP-12F and the LED driver transistor."><figcaption>Figure 1. Lambka p1 as energy and control paths. Only the supply module and the optocoupler are intended to cross the barrier; wiring, screws and the enclosure can still bridge it.</figcaption></figure>

Keep three kinds of evidence separate throughout the course:

| Evidence | What exists | What it can establish |
|---|---|---|
| Teaching model | Calculations and idealised tools in this course | Mechanisms, orders of magnitude and predictions under stated assumptions |
| p1 design | Schematic, layout, CAD rule checks, BOM | That a specific circuit and geometry exist and satisfy the configured rules |
| Measured product | Nothing yet for p1 | Behaviour with real parts, real lamps, temperature, faults and insulation tests |

A passing DRC belongs in the second row. A safe, compliant product needs the third row plus a documented assessment against the applicable standard.

## Safety boundaries of this course

Mains voltage can kill through a single contact, and a fault in a mains product can start a fire long after the designer has left. The course therefore draws firm lines:

- Calculations, simulations, CAD review and isolated, current-limited **low-voltage** experiments are in scope.
- Building, opening, probing or energising a mains assembly is **not** a course exercise. It requires a reviewed procedure, appropriate instruments and a competent person under the rules that apply where you work.
- A tool result, a worked answer or a passing check is never permission to energise anything.

## How to study

Each chapter gives theory, a worked example and an exercise with a worked answer or review criteria. Predict before you calculate, and calculate before you open a tool. Record your reasoning in the chapter notebook; it stays in your browser and can be exported.

| Study block | Produce before moving on | Self-check |
|---|---|---|
| Chapters 0–4 | Power, energy and supply-topology notes with numbers | Can you explain why a 7 W lamp draws a 0.2 A peak? |
| Chapters 5–8 | A barrier map and a protection-coordination table | Does every safety number cite a standard, edition or datasheet? |
| Chapters 9–12 | Gate-drive and lamp-compatibility calculations | Which lamp behaviours can only be settled by measurement? |
| Chapters 13–18 | Fault table, layout/enclosure review and a test plan | What happens if the firmware hangs with the output on? |

## A rule for using AI during the project

Ask an assistant for derivations, counterexamples and datasheet cross-checks, then check its claims against the primary source. Never accept a creepage distance, fuse rating or component substitution from a model or a forum without the standard clause or datasheet line behind it. Keep three columns in your notes: **known**, **assumed** and **measured**.

**Deliverable 0:** write a notebook entry listing your instruments (with their measurement category ratings), the lamp you intend to switch, how the device will be connected to the installation (plug-in or fixed wiring), and the three topics in this course you least trust yourself to judge.

# 01 | Energy, power and RMS

Voltage pushes charge, current is the flow of charge, and power is the rate of energy transfer. For any waveform the instantaneous power is \(p(t)=v(t)i(t)\), and the real power is its average over a period:

\[
P=\frac1T\int_0^Tv(t)i(t)\,dt.
\]

Energy is power integrated over time. A 10 W lamp running for 2 hours uses 20 Wh, which is 72 kJ. A device that idles at 0.5 W uses \(0.5\times8760=4.4\) kWh per year: small for one switch, but standby power is a design specification, not an afterthought.

## RMS values describe heating

The root-mean-square value of a current is the DC current that would heat a resistor equally:

\[
I_{rms}=\sqrt{\frac1T\int_0^Ti^2(t)\,dt},\qquad P_R=I_{rms}^2R.
\]

For a sinusoid only, \(V_{pk}=\sqrt2V_{rms}\). A 230 V supply peaks at 325 V; at the +10% limit of 253 V it peaks at 358 V. Every component across the line must withstand the peak, and transients well above it.

## Total power factor

Apparent power is \(S=V_{rms}I_{rms}\). The ratio \(PF=P/S\) is the **total power factor**. For a sinusoidal voltage it factors into two parts:

\[
PF=\frac{I_{1,rms}}{I_{rms}}\cos\varphi_1,
\]

where \(I_1\) is the fundamental component of the current and \(\varphi_1\) its phase shift. The first factor measures distortion; the second, displacement. A resistive heater has PF = 1. A motor has displacement. An LED lamp with a capacitor-input rectifier draws narrow pulses at the voltage crests: almost no phase shift, but a large distortion factor, so its PF is often 0.4–0.6. Writing \(PF=\cos\varphi\) for such a lamp is simply wrong.

**Worked example.** A 10 W lamp at 230 V with PF = 0.5 draws \(10/(230\times0.5)=87\) mA RMS, not the 43 mA a resistive estimate suggests. Neither number gives the startup peak or the current at the instant a triac must stay latched. Those need the waveform, which chapter 3 computes.

## Why RMS matters for the switch

Conduction loss in wiring, fuses and the switch scales with \(I_{rms}^2\) or, for a device with a threshold voltage, with a mix of average and RMS current (chapter 9). Fuse heating depends on \(I^2t\). Insulation, in contrast, cares about peak and transient voltage. Keep the three quantities separate: RMS for heat, peak for stress, energy for faults.

### Exercise 1 · Measure what the meter means

A plug-in power meter reports 7.16 W and 57.9 mA at 230 V for an LED lamp. Compute the apparent power and the total power factor. A cheap average-responding (not true-RMS) multimeter reads a much lower current. Predict roughly what it shows, given that the average of the absolute current is about 23 mA, and explain the discrepancy.

<details><summary>Worked solution</summary>
<p>S = 230 × 0.0579 = 13.3 VA, so PF = 7.16 / 13.3 = 0.54. An average-responding meter rectifies, averages and multiplies by 1.11, the sine-wave form factor. For a pulsed current whose average absolute value is about 23 mA the reading is 1.11 × 23 ≈ 25 mA, less than half the true value. Meters differ in their front ends, so treat any non-true-RMS reading of a distorted current as unknown. Only a true-RMS instrument with enough bandwidth and crest-factor capability reports 57.9 mA. Record the instrument and its crest-factor rating with every current measurement.</p>
</details>

<div class="tool-slot" data-tool="acpower"></div>

# 02 | Stored energy and discharge

Circuits store energy in electric and magnetic fields. That energy is what makes faults violent and what keeps a disconnected circuit dangerous.

## Capacitors

A capacitor resists rapid voltage change: \(i=C\,dv/dt\), and stores \(E=\tfrac12CV^2\). A 100 µF capacitor at 5 V holds 1.25 mJ; at 325 V the same capacitor holds 5.28 J. Discharged through a screwdriver, a few joules vaporise metal; through a person, a charged bulk capacitor can deliver a shock long after the plug is pulled.

An ideal RC discharge follows \(v(t)=V_0e^{-t/RC}\). The time to fall to a target \(V_t\) is

\[
t=RC\ln\frac{V_0}{V_t}.
\]

A capacitor across the line inside a plug-in product (an X capacitor or the input of a module) can be left charged to the crest voltage when the plug is pulled at the wrong instant. Product standards therefore specify a voltage that the plug pins must reach within a time after disconnection. Take both numbers from the standard that applies to your product, not from this course.

**Worked example.** Suppose a requirement read “below 60 V within 1 s” for 100 nF across the pins at a 253 V maximum supply (358 V crest). The largest permissible resistance is \(1/(100\,\text{nF}\times\ln(358/60))=5.6\) MΩ. It dissipates \(253^2/5.6\,\text{M}\Omega=11\) mW continuously. Check both the AC operating voltage and the charged-capacitor discharge stress against the exact resistor ratings; chapter 21 distinguishes RMS, peak and pulse limits and includes component tolerances. Ask also what happens when one of them fails open.

Calculation alone does not establish that a real circuit is discharged. Before touching a circuit that has held mains, verify it with a rated meter, using a procedure that does not depend on the bleeder having worked.

## Inductors

An inductor resists rapid current change: \(v=L\,di/dt\), and stores \(E=\tfrac12LI^2\). Interrupting its current produces whatever voltage is needed to keep the current flowing for a moment. Relay coils need a freewheel diode; buck converters need a freewheel path; long mains cables have inductance that rings with input capacitors. Triacs, which turn off only at a current zero, avoid interrupting load current, one of their quiet advantages in AC switching.

## Energy in faults

The energy a fault can release is set by the source and the stored energy, not by the size of the normal load. A 5 W lamp switch is still connected to an installation that can deliver hundreds of amperes into a short until the upstream protection opens. Chapter 7 returns to this through fuse breaking capacity.

### Exercise 2 · Size a discharge resistor

For 100 nF across the pins, a 253 V maximum supply and the illustrative 60 V / 1 s target, find the largest resistance, its continuous dissipation and the voltage on each resistor if two are used in series. Then repeat for 470 nF and comment on standby power.

<details><summary>Worked solution</summary>
<p>For 100 nF: R ≤ 5.6 MΩ, 11 mW, about 179 V peak per resistor with two in series. For 470 nF: R ≤ 1/(470 nF × 1.786) = 1.19 MΩ, dissipating 54 mW. Larger X capacitors (for EMI filtering) force smaller discharge resistors and more standby loss; that is why some products use active X-capacitor discharge circuits. Check the resistors' working-voltage and pulse ratings, and whether one failed-open resistor defeats the requirement.</p>
</details>

<div class="tool-slot" data-tool="discharge"></div>

# 03 | Rectifiers, power factor and LED lamp input current

Most LED lamps for 230 V contain a bridge rectifier, a bulk capacitor and a driver. The rectifier conducts only when the instantaneous mains voltage exceeds the capacitor voltage, so the lamp draws narrow current pulses near each crest. This waveform decides the switch's holding-current problem, its inrush stress and the lamp's power factor.

<figure><img src="figures/bulb-input.svg" alt="AC source with series input resistance feeding a four-diode bridge, a bulk capacitor and a driver with LEDs."><figcaption>Figure 2. A simple capacitor-input lamp model. Real lamps add fuses, filter capacitors, inductors and sometimes valley-fill or active power-factor circuits.</figcaption></figure>

## The conduction interval

Model the driver as a constant-power load P drawing from the bulk capacitor C. Between pulses the capacitor discharges; near the crest the rectifier recharges it through the lamp's series resistance \(R_{in}\) (a fusible resistor or NTC). If the capacitor droops by \(\Delta V\) from a crest \(V_{pk}\), the energy balance for one half-cycle of length \(T/2\) is roughly

\[
\tfrac12C\left[V_{pk}^2-(V_{pk}-\Delta V)^2\right]\approx P\frac{T}{2}.
\]

For 7 W, 4.7 µF and 50 Hz this bound gives \(\Delta V\approx50\) V. Because the rectifier itself feeds the load for part of each half-cycle, the actual droop is nearer 40 V. The capacitor recharges only while \(|v|\) is above the drooped capacitor voltage: from about 60° until just after each crest, roughly 2 ms of every 10 ms.

## A worked lamp

Laboratory 2 integrates the model for a 7 W driver, 4.7 µF and 47 Ω at 230 V. In steady state:

| Quantity | Value |
|---|---|
| Bulk voltage | 284–323 V (40 V ripple) |
| Line current | 191 mA peak, 57.9 mA RMS, crest factor 3.3 |
| Total power factor | 0.54 |
| Conducting | 20% of the time |
| Below a 15 mA holding current | 81% of the time |

The last row matters most for this course. A triac in series with this lamp carries current only during the pulses. For four-fifths of every half-cycle its current is below a typical holding current, so it turns off and must be triggered again before the next pulse. Chapters 9–11 build on that fact.

## Harmonics and why grids care

A pulsed current has strong odd harmonics. Individually small lamps are allowed relaxed harmonic limits, but many of them on one phase distort the voltage and load neutral conductors with triplen harmonics. Products above certain power levels must meet harmonic-current limits; check whether any apply to your load. For a lamp switch, the practical lesson is that the load you switch is not a resistor.

## Inrush

At first switch-on the bulk capacitor is empty. If the switch closes at the voltage crest, the current is limited only by \(R_{in}\) and wiring: \(358/47=7.6\) A at the 253 V maximum, or 6.9 A at 230 V. If it closes at a voltage zero, current initially starts at zero through the finite input resistance. For a small RC time constant it then approaches the rising-sine charging estimate \(C\omega V_{pk}=0.48\) A. This estimate neglects the driver during startup and assumes RC is small compared with a half-cycle. Zero-cross switching can reduce the first-cycle charging current for this model. It does not eliminate inrush, because the lamp's own driver and filter may still draw a surge as they start.

### Exercise 3 · Change the bulk capacitor

Using Laboratory 2, compare 4.7 µF and 10 µF at 7 W. Report peak current, RMS current, power factor, conducting fraction and zero-cross inrush. Which way does each change go, and why?

<details><summary>Worked solution</summary>
<p>With 10 µF the ripple falls to about 19 V, so the conduction interval shrinks (about 17% of the time). The same charge in a shorter pulse raises the peak to about 206 mA and the RMS current to about 60 mA. Power factor drops to about 0.52 and the time below 15 mA rises to about 84%. Zero-cross inrush doubles to about 1.0 A because it is proportional to C. A bigger capacitor makes the lamp smoother and the line current worse.</p>
</details>

<div class="tool-slot" data-tool="bulb"></div>

# 04 | Supplies at a glance: LDO, dropper, buck and flyback

A mains product needs a low-voltage rail for its electronics. The choice of conversion method decides whether that rail is isolated from the mains, how much power is wasted and what can fail.

| Method | How it works | Isolated? | Typical role |
|---|---|---|---|
| Linear regulator (LDO) | Drops the excess voltage across a pass transistor | No | Cleaning up an already-low rail, e.g. 5 V → 3.3 V |
| Capacitive dropper | Uses an X capacitor's reactance to limit current from the mains | **No**: every node is live | Very low-cost appliances with no touchable parts |
| Non-isolated buck | Switches the rectified 325 V bus down | No | Appliances whose electronics are fully enclosed |
| Flyback | Stores energy in a coupled inductor, releases it on the secondary | Yes, if the transformer, feedback and construction provide the barrier | Chargers, modules such as the HLK-5M05 |

## Rectification is not isolation

A bridge connected to 230 V makes a 325 V DC bus with no protective separation. Labelling its negative terminal “GND” does not make it earth or touch-safe: it swings relative to earth by the full mains voltage every half-cycle. A capacitive dropper or a non-isolated buck inherits that property. Connecting a USB programmer or an oscilloscope ground to such a circuit can bridge mains to earth through the instrument.

## Linear regulator loss

A linear regulator dissipates approximately \((V_{in}-V_{out})I\) plus its quiescent current times \(V_{in}\). At 5 V → 3.3 V and 0.3 A that is 0.51 W, and the efficiency cannot exceed \(3.3/5=66\%\). From 12 V at 0.2 A it is 1.74 W at 27.5% efficiency, which already needs thermal design in a small package. An LDO is attractive after an isolated module because the input is already low.

## The capacitive dropper

The current available from a dropper capacitor C is about \(V_{rms}\cdot2\pi fC\). For 330 nF at 230 V that is 24 mA RMS. The supply is cheap and small, but the whole low-voltage circuit floats at mains potential. It also delivers nearly the same current whether or not the load needs it, so the excess must be shunted by a zener. It is unsuitable for anything with a touchable connector, a programming header or a radio module that might be serviced.

## Buck and flyback in one paragraph each

A **buck** converter connects an inductor alternately to the input and a freewheel path. In steady state the inductor's volt-seconds balance, giving \(D=V_{out}/V_{in}\) in continuous conduction. The ripple is \(\Delta I=(V_{in}-V_{out})D/(Lf)\): for 12 V → 5 V, 100 µH and 100 kHz, D = 41.7% and ΔI = 0.29 A. The [buck converter course](https://psym.pl/buck-course/) covers this in depth.

A **flyback** stores energy in the magnetising inductance of a coupled inductor while its primary switch is on, then releases it to the secondary while the switch is off. The secondary can be isolated from the primary. The barrier is made by the transformer's insulation system, the feedback optocoupler, the PCB spacing and a Y capacitor that bridges the barrier deliberately for EMI. That Y capacitor passes a small leakage current to the secondary, which is why touch-current limits constrain it and why only appropriately rated Y-class parts may be used there.

## What the module datasheet must give you

For an off-the-shelf module such as the HLK-5M05, the barrier is only as good as the module's construction. Look for the insulation class claimed, the test voltage, creepage inside the module, the applicable standard and certificates traceable to the specific manufacturer and model. Many visually identical modules are sold under the same name. A module with no traceable approval is a component to characterise, not a certified barrier.

### Exercise 4 · Choose a supply

A controller needs 3.3 V at 80 mA average with 400 mA bursts, has a programming header and lives in a plastic box. Compare a capacitive dropper, a non-isolated buck and an isolated module followed by an LDO. For the LDO path, compute the average loss from 5 V.

<details><summary>Worked solution</summary>
<p>A dropper cannot supply 400 mA bursts without a large capacitor and leaves the header at mains potential: reject. A non-isolated buck can supply the power but also makes the header live; it would need the header and every touchable part to be inside the mains barrier, which defeats programming and debugging. An isolated module plus an LDO keeps the header on a SELV side if the module and layout provide the barrier. LDO loss from 5 V at 80 mA is (5 − 3.3) × 0.08 = 0.14 W average, and about 0.7 W during a 400 mA burst. Chapter 8 checks its dropout margin.</p>
</details>

# 05 | The mains installation

A product does not meet the mains in a laboratory; it meets an installation with its own conductors, protective devices and failure modes. Designing a switch means knowing what those parts do and what they do not do.

## Line, neutral and protective earth

In the common TN systems, the supply transformer's star point is earthed. The **line** conductor carries the 230 V potential relative to earth. The **neutral** returns working current and is near earth potential at the origin, but not necessarily at the far end of a loaded circuit or after a wiring fault. The **protective earth (PE)** conductor connects exposed metal to earth; it is not a working-current return. In TN-C-S arrangements, neutral and PE are combined upstream and split at the installation, so a broken combined conductor can raise “neutral” and connected metal toward line potential.

Treat both line and neutral as hazardous. Single-pole switches are installed in the line conductor, but plugs that can be reversed, wiring errors and old installations all put the switch in the neutral at times. With the switch in the neutral, the lamp socket is live while the lamp is off.

## What the protective devices do

| Device | Responds to | Does not protect against |
|---|---|---|
| Circuit breaker / branch fuse | Overcurrent: overload and short circuit | A person touching line and neutral; small persistent leakage; fire from a few watts of local heating |
| Residual-current device (RCD) | Imbalance between line and neutral currents, typically 30 mA for personal protection | Contact between line and neutral; overcurrent |
| Product fuse | Overcurrent inside the product | Shock; overheating at currents below its rating |
| Insulation and protective separation | Prevents contact in the first place | Nothing, if it is bridged by wiring, screws or contamination |

An RCD is supplementary protection. A person holding line in one hand and neutral in the other carries the same current out and back, which the RCD does not detect.

## A semiconductor switch is not an isolator

A triac or SSR in its off state still has leakage, can be triggered by transients, and can fail short. It provides **functional** switching, not **isolation**. Servicing the lamp requires switching off the circuit at a device intended for isolation, then verifying it is dead. Product documentation must say so.

## Overvoltage categories

The installation is exposed to switching and lightning transients. Insulation coordination (IEC 60664-1) groups equipment by where it sits:

| Category | Typical location | Rated impulse for a 230/400 V system |
|---|---|---|
| OVC IV | Origin of the installation, meters | 6 kV |
| OVC III | Fixed installation: distribution boards, wall switches, fixed wiring | 4 kV |
| OVC II | Equipment energised from the fixed installation, e.g. plug-in appliances | 2.5 kV |
| OVC I | Equipment with transient overvoltages limited by external means | 1.5 kV |

The category is a design input, not a label you choose for convenience. A box that plugs into a socket is in a different position from a module screwed into ceiling wiring. Lambka's p1 has screw terminals in an ABS box, so its intended installation has to be decided before its insulation can be specified (chapter 6).

### Exercise 5 · The lamp is dark

The Lambka lamp is off. List every reason the lamp socket may still be hazardous. Then state which installation device, if any, protects a person who touches the socket contact in each case.

<details><summary>Worked solution</summary>
<p>Reasons: off-state leakage through the switch or a snubber; reversed polarity putting the switch in the neutral; a triac triggered by a transient or failed short; firmware or a hardware fault leaving the output commanded on; a bleeder or filter capacitor across the lamp still charged; a broken neutral elsewhere. An RCD may detect current flowing from the socket through a person to earth. It does not detect a hand-to-hand path between line and neutral. The breaker does not respond to body currents. The only reliable protection is isolation at the installation, followed by verification.</p>
</details>

# 06 | Insulation coordination: clearance, creepage and barriers

Insulation keeps hazardous voltage away from people and from circuits designed to be touched. It is specified as a system: the barrier must survive the working voltage for years, transient overvoltages, contamination, humidity and the faults the standard requires you to consider.

## Grades of insulation

- **Functional** insulation lets the circuit work, for example between two mains nets.
- **Basic** insulation provides one level of protection against shock.
- **Supplementary** insulation is an independent second level, applied in addition to basic insulation.
- **Double** insulation is basic plus supplementary; **reinforced** insulation is a single system with equivalent protection.

A low-voltage circuit that people can touch, separated from the mains by double or reinforced insulation and meeting the voltage limits under normal and single-fault conditions, is a **SELV** circuit. A 5 V label alone does not make a circuit SELV; the separation and the fault analysis do.

## Clearance and creepage

<figure><img src="figures/barrier.svg" alt="Cross-section of a PCB with a mains pad and a SELV pad separated by a milled slot. Clearance is the straight line through air; creepage follows the board surface down and around the slot."><figcaption>Figure 3. Clearance is the shortest path through air; creepage follows the insulating surface. A slot can lengthen creepage only if it is wide enough under the applicable rules.</figcaption></figure>

**Clearance** is the shortest distance through air. It must withstand transient overvoltages, so it is sized from the **rated impulse voltage** (chapter 5's overvoltage category), the field geometry and altitude. **Creepage** is the shortest distance along an insulating surface. Contamination and moisture make surfaces conductive over time, so creepage is sized from the **working voltage**, the **pollution degree** and the insulating material's **comparative tracking index (CTI)**, grouped into material groups I (CTI ≥ 600), II (400–600), IIIa (175–400) and IIIb (100–175). Do not assume a CTI for “FR-4”; obtain the laminate maker's figure. Creepage can never be smaller than the required clearance.

## A worked lookup, for orientation only

The values below come from the tables of IEC 60664-1 for one set of assumptions: a 230 V system, inhomogeneous field, altitude up to 2000 m, pollution degree 2 and material group III. They illustrate the procedure. Your product standard (for example one covering electronic switches for fixed installations, or a household appliance standard) may impose different or additional requirements. Use the edition you hold, not these numbers.

| Step | Basic insulation | Reinforced insulation |
|---|---|---|
| Rated impulse, OVC II | 2.5 kV | one step higher: 4 kV |
| Clearance, OVC II | 1.5 mm | 3.0 mm |
| Rated impulse, OVC III | 4 kV | one step higher: 6 kV |
| Clearance, OVC III | 3.0 mm | 5.5 mm |
| Creepage at 250 V working, PD 2, material group III | 2.5 mm | twice basic: 5.0 mm |

Two rules from the procedure are worth memorising: reinforced clearance uses the next impulse step, and reinforced creepage is twice the basic value. TI's [insulation guide SDAA268](https://www.ti.com/lit/an/sdaa268/sdaa268.pdf) walks through the same steps for a different standard and voltage.

Lambka's p1 applies a **project rule** of 6 mm clearance and 6 mm creepage between mains and SELV, and its independent check reports a closest distance of 6.36 mm. Under the orientation values above, that rule exceeds the reinforced requirement for OVC II and OVC III. It is a sensible margin for a learning board, but it is the project's choice, not a certification. It also says nothing about the inside of the HLK module, the optocoupler's internal insulation or the wiring in the box.

## Every path counts

A barrier fails at its weakest path. Walk all of them:

- copper on both layers, including pours and vias;
- component bodies and leads: the optocoupler's package, the module's pins, the triac's tab (connected to MT2, so live);
- mounting screws, standoffs and metal enclosure parts;
- wires inside the box that can come loose and reach the other side;
- external connectors: a programming header is only SELV while the barrier is intact.

Slots and grooves count toward creepage only when they meet a minimum width that depends on pollution degree (1 mm for pollution degree 2 in IEC 60664-1). Solder mask is not normally credited as insulation, and conformal coating reduces required distances only under specific rules and process control.

## Tests are not ratings

An optocoupler with a 4170 V RMS, one-minute isolation test rating has passed a dielectric test of its internal insulation; it does not mean its pins may sit 1 mm from mains copper. A one-minute withstand test of a finished product checks workmanship and design, but does not replace the distance requirements.

### Exercise 6 · Decide the inputs before the distances

Lambka could be (a) a plug-in box with a socket outlet for the lamp, or (b) a module wired into the ceiling rose. For each, state the overvoltage category, the insulation grade needed between mains and the programming header, and the orientation clearance and creepage from the table. Then list three p1 paths that are not covered by the PCB distance check.

<details><summary>Worked solution</summary>
<p>(a) Plug-in equipment: OVC II, rated impulse 2.5 kV. A touchable header needs reinforced (or double) insulation from mains: orientation clearance 3.0 mm, creepage 5.0 mm. (b) Fixed installation: OVC III, 4 kV; reinforced clearance uses 6 kV → 5.5 mm; creepage 5.0 mm. The p1 rule of 6 mm covers both, subject to the actual standard. Paths outside the PCB check: inside the HLK module and the MOC3063 package; mains wires in the terminal block reaching the low-voltage side if they come loose; the TO-220 tab (MT2, live) and any screw through it; the J2 header cable leaving the box; mounting holes and screws.</p>
</details>

# 07 | Protection parts: fuses, varistors, capacitors and resistors

Protective components limit the consequences of faults. Each responds to a specific stress and has its own failure modes. Coordination means checking that they work together: the fuse survives normal pulses but opens before the MOV burns, the MOV clamps without being destroyed by ordinary swells, and so on.

## Fuses

A fuse melts when its \(I^2t\) exceeds the melting integral of its element. Its datasheet gives a time–current curve, a melting \(I^2t\), a voltage rating and a **breaking capacity**: the largest prospective fault current it can interrupt safely. A glass 5×20 mm fuse may be rated to break only tens of amperes at 250 V; a sand-filled ceramic “H” fuse such as p1's Schurter-holder candidate is rated around 1500 A. In a domestic installation the prospective short-circuit current at a socket can be hundreds of amperes or more, so breaking capacity is not a detail.

Normal pulses must not age the fuse. The lamp's first-cycle inrush at the crest (chapter 3) is about 6.9 A decaying with \(\tau=R_{in}C\approx0.22\) ms, so

\[
I^2t\approx\tfrac12I_{pk}^2\tau\approx0.005\ \text{A}^2\text{s},
\]

far below the melting integral of a typical 1 A time-lag fuse. Check the exact fuse datasheet, and repeat the calculation for the supply module's own inrush. A time-lag (T) fuse tolerates pulses; a fast (F) fuse protects semiconductors better but nuisance-blows more readily.

A fuse limits fire and fault energy; it is not shock protection. For triac coordination compare the fuse’s **total clearing** \(I^2t\), including arcing, with the semiconductor’s permitted integral under compatible voltage, temperature and pulse conditions. Melting \(I^2t\) alone is insufficient, and the labels “1 A time-lag” and “4 A triac” do not establish coordination. See [Littelfuse, POWR-SPEED application guide, §3.8.3](https://www.littelfuse.com/~/media/electrical/application-notes/littelfuse-powr-speed-technical-applications-guide.pdf).

## Metal-oxide varistors

A MOV is a voltage-dependent resistor that conducts heavily above its varistor voltage and absorbs surge energy. A “275 VAC” rating is its maximum continuous voltage, not its clamping voltage, which is several hundred volts higher at surge currents. MOVs degrade with repeated surges: leakage rises, the device heats, and in sustained overvoltage (a lost neutral can put 400 V on a 230 V circuit) it can enter thermal runaway at a current too low to open an upstream 1 A fuse quickly. Thermally protected MOVs or a thermal fuse in contact with the MOV address that failure. Place the MOV after the fuse so that a shorted MOV opens the fuse.

## X and Y capacitors

Capacitors that connect across the line (line-to-neutral) are **X** class; capacitors that bridge to earth or across a barrier are **Y** class. Both are safety-rated for impulse withstand and flammability. Self-healing film X capacitors usually fail with gradual capacitance loss, but no rating guarantees an open-circuit failure. Y1 and Y2 differ in the insulation they may bridge: a Y2 is suitable for basic insulation and a Y1 for double or reinforced insulation. Never substitute an ordinary ceramic or film capacitor for either. Chapter 11's bleeder capacitor across the lamp sits across the line when the lamp is on, so it must be X-rated.

## Resistors on the mains

A resistor across mains needs its continuous AC **RMS** voltage checked against the specified AC rating, its stored-voltage discharge and surge **pulses** checked separately, adequate **power** with temperature derating and an understood **failure mode**. For example, [Vishay D/CRCW e3, document 20035, revision 14 April 2026](https://www.vishay.com/docs/20035/dcrcwe3.pdf) lists the 1206 operating limit as 200 V **AC RMS or DC**; treating 200 V as a universal sine-peak limit would misread it. Series resistors divide voltage, but tolerances and shorted neighbours change their shares (chapter 21). A “1 W” resistor says nothing about surge withstand or flammability. Fusible and flameproof types exist for exactly those reasons.

### Exercise 7 · Coordinate F1 and RV1

For p1's T1A ceramic fuse followed by a 275 VAC MOV, describe what happens in three events: a 1 kV surge of tens of microseconds, a lost neutral that puts 400 V on the line for an hour, and a short in the lamp cable. For each, name the protecting part, the energy path and the evidence you would need.

<details><summary>Worked solution</summary>
<p>Surge: the MOV clamps; the fuse must not blow on the surge current's \(I^2t\); evidence is the MOV's surge rating and the fuse's melting integral compared with the surge waveform. Lost neutral: 400 V exceeds the MOV's continuous rating, so it conducts and heats; the current may be well below what opens a 1 A time-lag fuse in a short time, so thermal protection or a thermally protected MOV is needed; evidence is a thermal fault test. Lamp-cable short: the triac (if on) and fuse carry the prospective fault current until the fuse clears; the fuse's breaking capacity must exceed the prospective current, and the triac's \(I^2t\) must exceed the fuse's let-through, or the triac is sacrificed. The upstream breaker also acts. Evidence is the datasheet comparison and, for a product, a fault test.</p>
</details>

# 08 | The isolated low-voltage supply

The low-voltage side of Lambka is a 5 V module, a linear regulator and an ESP8266 module whose radio draws short, large bursts. This chapter checks that chain the way a reviewer would.

## The module

The HLK-5M05 is a small encapsulated AC/DC module rated 5 V, 1 A (5 W). Modules of this class are typically flyback converters with optocoupler feedback. Three questions decide whether one can be the barrier in a product:

1. **Identity:** is the part from the manufacturer whose test reports and approvals you have, and is it the same model and revision? Copies are common.
2. **Conditions of use:** most modules require an external fuse, sometimes an input filter or a minimum load, and state the ambient temperature and creepage expected on the host PCB.
3. **Evidence:** a certificate tied to the standard you are using, not a marketing claim of “4 kV isolation”.

p1's BOM already notes a certified alternative with a different footprint. Treat the module choice as an open qualification item.

## Dropout in a linear regulator

An LDO regulates only while its input exceeds the output by its **dropout voltage**. The AMS1117 family, made by several manufacturers, is an older design with dropout typically around 1.1–1.3 V at several hundred milliamperes. From a 5 V module that leaves little margin:

\[
V_{5,min}=V_5(1-\text{tol})-I_{burst}R_{series}-\frac{I_{burst}t_{resp}}{C_{bulk}},\qquad \text{headroom}=V_{5,min}-3.3-V_{DO}.
\]

The last term is the bulk capacitor's droop while the module's control loop responds. With a 5 V ±5% module, 0.1 Ω of module and trace resistance, 0.4 A bursts, 50 µs response, 220 µF of capacitance on the 5 V rail and 1.2 V dropout, the worst-case headroom is about 0.12 V. With 1.3 V dropout it is about 0.02 V. Those are assumptions, not module data, and they show why a successful boot on the bench proves little. When headroom vanishes, the 3.3 V rail follows the 5 V droop; p1's 100 µF capacitor at the ESP's supply pin then carries the burst. It sags by about \(I\,t/C=0.4\times50\,\mu s/100\,\mu F=0.2\) V before the regulator recovers.

## Heat

Average dissipation in the regulator is \((5-3.3)\times0.08=0.14\) W at 80 mA average; during a 400 mA burst it is briefly up to about 0.8 W. In SOT-223 on a small copper area, a thermal resistance near 90 K/W gives about 12 K average rise. The module adds its own loss: at perhaps 70% efficiency, 0.4 W output costs about 0.57 W input. The ABS box has no airflow; the triac, module and regulator share its interior.

## Stability and capacitors

Older LDOs such as the AMS1117 often need an output capacitor with ESR in a stated range, or a minimum capacitance, to be stable. Large low-ESR ceramics can violate the requirement on some versions. Read the exact manufacturer's datasheet for capacitance, ESR and their DC-bias derating. The p1 note “needs ≥ 10 µF out” is a starting point to check against the part actually bought.

## Measure the real thing

The evidence that settles this chapter is an oscilloscope trace of the 5 V and 3.3 V rails during real Wi-Fi traffic, captured with the mains side **disconnected** and the 5 V supplied from a bench supply set to the module's minimum voltage. The module's own behaviour is then measured separately under its conditions of use.

### Exercise 8 · Find the margin

With Laboratory 4, find the dropout voltage at which the headroom reaches zero for the default assumptions. Then propose two design changes and estimate their effect on headroom and dissipation.

<details><summary>Worked solution</summary>
<p>Headroom reaches zero near 1.32 V dropout. Options: (1) a regulator with 0.3–0.5 V dropout at the burst current raises headroom by about 0.8 V without changing dissipation; (2) a small synchronous buck from 5 V to 3.3 V removes most of the dissipation (about 0.14 W becomes a few tens of milliwatts) but adds switching noise near the radio, needing layout care; (3) a higher-voltage module (for example 9–12 V) increases LDO loss sharply and is a poor fix. More 5 V bulk capacitance reduces only the response-time droop term.</p>
</details>

<div class="tool-slot" data-tool="supply"></div>

# 09 | Thyristors and triacs

A thyristor is a four-layer semiconductor that, once triggered, holds itself on by internal regenerative feedback. A triac behaves like two thyristors in inverse parallel with one gate, so it can conduct in both directions: a natural AC switch.

## Latching, holding and commutation

A gate current pulse starts conduction. The device **latches** only if the main current reaches the **latching current** \(I_L\) before the gate pulse ends. Once latched it stays on with no gate current until the main current falls below the **holding current** \(I_H\), which normally happens near each current zero. The gate cannot turn a triac off. That is why a triac switches AC loads cleanly: it always stops at a current zero, without interrupting current in the wiring inductance.

Datasheets give trigger current \(I_{GT}\), trigger voltage \(V_{GT}\), \(I_L\) and \(I_H\) at 25 °C. All rise as temperature falls. For the BT136-600E, a sensitive-gate (“E”) triac, \(I_{GT}\) is at most 10 mA in three of the four operating quadrants, and \(I_L\) and \(I_H\) maxima are of the order of 15–25 mA. Take the exact values and quadrants from the current manufacturer datasheet before using them.

## Quadrants

The triac can be triggered with either gate polarity in either half-cycle. Quadrant names combine the polarity of MT2 relative to MT1 with the gate polarity. Sensitivity differs: the quadrant with MT2 negative and gate positive is the least sensitive and is often not specified for sensitive or “snubberless” types. A zero-cross optocoupler drives the gate from MT2 through its own triac, so the gate current has the same polarity as MT2: it uses the two most sensitive quadrants.

## Commutation and dv/dt

Two voltage-rate limits matter:

- **Static dv/dt**: a fast rising voltage across an off triac injects displacement current into the gate region and can trigger it. Line transients and switching of other loads cause this.
- **Commutating dv/dt and di/dt**: with an inductive load, current reaches zero while the line voltage is far from zero. The voltage across the triac then jumps, and with charge still stored in the device it may retrigger and fail to turn off.

An RC snubber across the triac limits dv/dt, at the cost of off-state leakage into the load (chapter 11). “Snubberless” triacs tolerate higher commutation rates; that is a rating to compare with the load, not a promise that every load works without one. A MOV across the line limits surge amplitude, which is a different job.

## Ratings that matter

| Rating | Meaning | Lamp-switch check |
|---|---|---|
| \(V_{DRM}\), \(V_{RRM}\) | Repetitive off-state voltage | 600 V covers a 358 V crest; surges are the MOV's job |
| \(I_{T(RMS)}\) | RMS current at a stated case temperature | 4 A for BT136; a lamp needs tens of mA |
| \(I_{TSM}\), \(I^2t\) | Single-cycle surge and fusing integral | Lamp inrush and fuse let-through |
| \(I_{GT}\), \(I_L\), \(I_H\) | Gate and latching behaviour | The difficult numbers for small LED loads |
| Tab connection | Usually MT2 | The tab is live; it touches whatever it is mounted to |

## Conduction loss

On-state voltage is modelled as a threshold plus a resistance, \(v_T\approx V_{T0}+r_Ti\), so the loss is

\[
P=V_{T0}\overline{|i|}+r_TI_{rms}^2.
\]

Average and RMS currents both appear, and for pulsed currents they differ a lot. With illustrative values \(V_{T0}=1.0\) V and \(r_T=0.1\) Ω, the 7 W lamp of chapter 3 (23 mA average, 58 mA RMS) costs about 24 mW. A 100 W incandescent lamp (0.43 A RMS, 0.39 A average) costs about 0.41 W, enough to warm a TO-220 in a closed box by roughly 25 K without a heatsink. Use the datasheet's dissipation curve for the real part and the real current waveform.

### Exercise 9 · Read the triac for this load

Using the lamp of chapter 3, compare its current with a holding current of 15 mA and a latching current of 25 mA. In which part of each half-cycle can the triac latch? What happens in the rest of the half-cycle, and what must the gate drive therefore do?

<details><summary>Worked solution</summary>
<p>The lamp current exceeds 25 mA only inside its charging pulse, roughly the 2 ms before and around each crest. The triac can latch only there. For about 80% of each half-cycle the current is below the holding current, so the triac is off even when “on” is commanded. The gate drive must therefore deliver a trigger at the start of every charging pulse, every half-cycle, and that trigger must remain available until the current exceeds the latching current. A single pulse at the voltage zero crossing is not enough for this load. Chapter 10 examines whether a zero-cross optocoupler provides that trigger.</p>
</details>

# 10 | Driving a triac: zero-cross optocouplers and gate networks

The p1 drive chain is: GPIO5 switches a small N-MOSFET, which sinks current from 5 V through a 150 Ω resistor, an orange indicator LED and the infrared LED of an MOC3063. The MOC3063's output is a small photo-triac with a **zero-crossing inhibit** circuit; it fires the BT136's gate through R1 = 360 Ω, with R2 = 330 Ω from gate to MT1.

<figure><img src="figures/triac-drive.svg" alt="Low-voltage side: 5 V through R3 150 ohm, orange LED D1 and the optocoupler IR LED to MOSFET Q2 driven by GPIO5. Mains side: the optocoupler's zero-cross triac in series with R1 360 ohm from the fused line to the triac gate; R2 330 ohm from gate to MT1; the BT136 in series with the lamp."><figcaption>Figure 4. The p1 trigger chain. The optocoupler and its LED current are the only control path across the barrier.</figcaption></figure>

## The optocoupler's numbers

From onsemi's [MOC306xM datasheet](https://www.onsemi.com/pdf/datasheet/moc3163m-d.pdf): the MOC3063M is guaranteed to trigger at an LED current of at most **5 mA** at 25 °C, and the recommended operating current lies between that rated \(I_{FT}\) and the 60 mA absolute maximum. Its LED forward voltage is at most 1.5 V at 30 mA. The output's on-state voltage is at most 3 V at 100 mA, its holding current is typically 0.5 mA, and it will not trigger while the voltage across its output exceeds the **inhibit voltage**, typically 12 V and at most 20 V. Its single-cycle surge rating is 1 A peak, but its repetitive peak on-state current is only 100 mA. Its off-state leakage is at most 500 nA at 600 V, and its static dv/dt is at least 600 V/µs.

## Is the LED current enough?

The p1 note estimates \((5-1.9-1.2)/150\approx12.7\) mA. A worst-case check uses the supply's low tolerance and the highest forward voltages:

\[
I_{F,min}=\frac{V_{5,min}-V_{F,D1,max}-V_{F,IR,max}-V_{Q2}}{R_3}=\frac{4.75-2.4-1.5-0.05}{150}=5.3\ \text{mA}.
\]

With an assumed 2.4 V maximum for the orange LED (check the XL-2012UOC sheet), the margin over the 5 mA rating is only 7%. Trigger current rises at low temperature and as the infrared LED ages, so designs usually keep a factor of 1.5–2. A 100 Ω resistor would give 8.0–22.5 mA over the same tolerances, still far below the 60 mA limit. This is a review finding for p1, not a change made by this course.

## The gate network

When the photo-triac fires, current flows from MT2 through R1 and the photo-triac into the gate, and returns through the gate–MT1 junction and R2. R2 shunts about \(V_{GT}/R_2=3\) mA of leakage and noise away from the sensitive gate. The main triac triggers when the gate receives \(I_{GT}\) plus that shunt current:

\[
v_{trig}\approx V_{TM}+V_{GT}+R_1\left(I_{GT}+\frac{V_{GT}}{R_2}\right)\approx3+1+360\times13\,\text{mA}\approx8.7\ \text{V}.
\]

If the voltage across the switch follows the line, as for a resistive load before triggering, 8.69 V is reached after **85 µs at 230 V** or **77 µs at 253 V**, both at 50 Hz. The tool defaults to 253 V. At an assumed 20 V switch voltage the calculated gate current is about 41 mA. The datasheet’s 20 V inhibit value is a **maximum threshold**, not a guaranteed minimum firing window: comparing 8.69 V with 20 V does not by itself prove reliable triggering. The table specifies the LED trigger test at 3 V output voltage; retain the manufacturer’s circuit guidance and verify the actual device/load combination.

## What R1 is really protecting

p1's note justifies R1 by \(358\ \text{V}/360\ \Omega<1\) A, the photo-triac's surge rating. That is the right worst case to bound, but it is a **non-repetitive** rating. If the photo-triac were ever fired near the crest every half-cycle (a random-phase driver substituted, dv/dt triggering, or a load that keeps the main triac from latching), it would carry close to 1 A repetitively against a 100 mA repetitive rating, and R1 would see a peak of about 350 W for each microsecond-scale pulse. The zero-cross function is what keeps normal operation far away from that; the resistor and part choice must make the abnormal case survivable, and the substitution rule must say “zero-cross type only”.

## Will it keep the lamp on?

Chapter 9 showed that a capacitor-input lamp needs a fresh trigger for each charging pulse. The zero-cross detector senses voltage **across the photo-triac output**, not an independent line-to-neutral zero-cross signal. With a charged lamp capacitor these are different waveforms. Once the main triac turns on, its voltage collapses and the photo-triac can turn off even while its LED stays lit. If the main current has not reached latching current, repeated triggering can occur; [ST AN5114, Rev 2, §§2.3 and 3.4](https://www.st.com/resource/en/application_note/an5114-controlling-a-triac-with-a-phototriac-stmicroelectronics.pdf) explains this interaction. The lamp tool contains no triac or gate network, so its current waveform cannot predict whether that network retriggers successfully. One plausible result is a lamp that fails to light, flickers or lights only on some half-cycles. A small resistive or RC load across the lamp, the lamp's own input filter, or a non-zero-cross driver with deliberate phase control are candidate remedies. This is precisely the p1 pilot question; it is settled by recording the lamp current, triac voltage and gate current with the actual lamp, not by more calculation.

### Exercise 10 · Review the trigger chain

With Laboratory 5, report the LED-current range for R3 = 150 Ω and 100 Ω, the trigger voltage and delay, and the gate current at the inhibit limit. Then write three sentences for a design review: one finding, one question that needs measurement, and one substitution rule for the BOM.

<details><summary>Worked solution</summary>
<p>150 Ω: 5.3–15.0 mA; 100 Ω: 8.0–22.5 mA. The static network needs about 8.7 V across the switch; the resistive-load delay estimate is 77 µs at the tool’s 253 V (85 µs at 230 V). About 41 mA is calculated at an assumed 20 V; this is not a guaranteed firing window or a simulated lamp trigger. Finding: the worst-case LED current is only 1.07 times the rated trigger current; reduce R3 or justify the margin with the exact LED data and temperature range. Measurement: record lamp current, triac voltage and gate current with the chosen lamp to establish whether the triac is retriggered at every charging pulse. Substitution rule: the optocoupler must be a zero-cross MOC306x-class part with the same or lower trigger current and the same wide-lead package, never a random-phase driver.</p>
</details>

<div class="tool-slot" data-tool="triac"></div>

# 11 | LED lamps on a semiconductor switch: inrush, retriggering and ghosting

LED lamps are designed for mechanical switches. A semiconductor switch differs in two ways that matter: it is not a perfect open circuit when off, and it is not a perfect closed circuit when on. Both show up as lamp misbehaviour.

## Ghosting: the off state that is not off

Any path that passes current while the switch is off — an RC snubber, the optocoupler's leakage, a neon indicator, capacitance between switched and live wires in a long cable — feeds a small current into the lamp. The lamp's rectifier turns that current into charge on its bulk capacitor. Nothing in the lamp consumes it until the capacitor reaches the driver's start voltage; the driver then flashes the LEDs, drains the capacitor and the cycle repeats. The lamp glows faintly or blinks every second or so.

<figure><img src="figures/leakage.svg" alt="Mains source and an open switch bridged by a leakage path Cs and Rs. Across the lamp, an optional bleeder Cb in series with Rb. The lamp is a rectifier charging its bulk capacitor."><figcaption>Figure 5. Off-state leakage charges the lamp's bulk capacitor through its rectifier. A bleeder across the lamp gives the leakage a lower-impedance path.</figcaption></figure>

A typical SSR snubber of 10 nF and 100 Ω passes \(230\times2\pi\times50\times10\,\text{nF}=0.72\) mA. Laboratory 3 feeds that into a lamp model with 4.7 µF bulk capacitance, a 150 V start voltage and a 50 V stop voltage: the first flash comes after about 1.5 s and then one every 1.1 s. Those lamp parameters are assumptions; real lamps vary widely, which is why the same switch ghosts with one lamp and not another.

The Lambka prototype's cheap SSR board had such a snubber, which is why it needed a branch across the lamp. p1 has no snubber. Its remaining leakage paths are the optocoupler (at most 0.5 µA at 600 V), the triac's own off-state leakage, which rises steeply with temperature, and wiring capacitance. A few metres of switched cable run beside a live conductor may contribute a few hundred picofarads. In a **3 s simulation**, 0.3 nF raises the lamp’s bulk voltage to about 12 V and 1 nF to about 39 V. These are observation-window results, not equilibrium voltages. With 1 nF, no bleeder and no internal load, extending the same model to 20 s gives a first flash at about **14.5 s**. A short no-flash test cannot establish that ghosting never occurs. Whether p1 ghosts with a given lamp is a measurement.

## The bleeder

A bleeder across the lamp is a deliberate load that shunts the leakage. With a capacitive leakage \(C_s\) and a bleeder capacitor \(C_b\) (resistors small compared with the reactances), the off-state lamp voltage is set by a capacitive divider:

\[
V_{lamp}\approx V_{mains}\frac{C_s}{C_s+C_b}.
\]

With 10 nF of leakage and the p1 README's suggested 100 nF X2 + 1 kΩ bleeder, the lamp sees about 21 V RMS (30 V peak): below the **assumed 150 V** driver start threshold. That explains this model’s no-flash result; other drivers can start at lower voltages. When the lamp is on, the bleeder is across the full mains: it draws \(230/|1\,\text{k}\Omega-j31.8\,\text{k}\Omega|=7.2\) mA, dissipates about 52 mW in the resistor and needs an X-rated capacitor. It also appears in the off-state energy budget and, being a reactive load, in the power factor. The resistor limits the capacitor's charging current when the switch closes at a voltage other than zero.

The bleeder may have a second benefit for a zero-cross trigger: its current near the voltage zero, \(C_b\,dv/dt\approx100\,\text{nF}\times0.10\ \text{V/µs}=10\) mA, flows through the switch path and may help the gate-drive path. It is below the illustrative 15 mA main-triac holding current and 25 mA latching current, so it does not establish continuous main-triac conduction until the lamp’s charging pulse. That is a hypothesis for the pilot test, not an established fix.

## Inrush and repeated starts

Chapter 3 estimated first-cycle inrush: about 0.5 A when switched at a voltage zero and about 7 A at the crest for the model lamp. Zero-cross switching therefore protects the triac, fuse and lamp from the worst case, but every start still charges the lamp's capacitor. Rapid on/off cycling repeatedly stresses the lamp's input resistor and capacitor. Firmware should coalesce rapid commands and debounce local buttons; p1's planned 250 ms minimum interval is an operational guard, not a lamp-lifetime guarantee.

## Light output and flicker

A lamp's light depends on its driver, not directly on the switch. Two things the switch can add are delay and modulation. For a suitable load, the next voltage-zero opportunity arrives within half a cycle (10 ms at 50 Hz); successful latching and the lamp’s startup add further conditions, so measure the delay from command to light rather than promising one. Skipping whole cycles to dim an ordinary LED lamp produces visible flicker and stroboscopic effects; do not offer it. Dimming is a separate design that needs a lamp sold as dimmable and a phase-control circuit (chapter 12).

### Exercise 11 · Design and defend a bleeder

Using Laboratory 3, find the largest leakage capacitance for which the default lamp model never flashes within 5 s. Then size a bleeder that keeps the lamp below 50 V peak with the 10 nF SSR-style leakage, and compute its on-state current and resistor dissipation.

<details><summary>Worked solution</summary>
<p>With the default lamp (4.7 µF, 150 V start, no internal bleed), leakage of a few nanofarads is the boundary: 1 nF reaches about 39 V after 3 s but flashes after about 14.5 s, while 10 nF flashes about once per second. Set the requested 5 s duration before comparing cases; a no-flash result has that time scope only. Find the exact boundary with the tool; it depends strongly on the lamp's own internal load, which the model omits by default. To keep 10 nF leakage below 50 V peak, \(C_b\ge C_s(325/50-1)=55\) nF; choose 68–100 nF X2. With 100 nF and 1 kΩ: 7.2 mA on-state, 52 mW in the resistor, 230 V RMS across the capacitor. Verify with the actual lamp, because the start voltage and internal load are unknown.</p>
</details>

<div class="tool-slot" data-tool="ghost"></div>

# 12 | Choosing the switch: relay, SSR, triac or MOSFET

The right switch depends on the load, noise, lifetime, leakage and failure behaviour you can accept. Lambka chose solid-state switching deliberately for silence and speed. Here is the comparison that decision rests on.

| Switch | Strengths | Weaknesses |
|---|---|---|
| Electromechanical relay | Contact opening with very low leakage; select a contact rating for the lamp’s capacitive inrush | Audible click; coil power; contact wear and welding under capacitive inrush |
| Packaged SSR (opto + triac + snubber) | Silent; zero-cross types limit inrush | Snubber leakage causes ghosting; heat; failure mode is usually short |
| Discrete opto-triac + triac (p1) | Silent; snubber can be omitted if the actual commutation and transient stresses allow it; cheap | Small capacitive loads challenge latching and retriggering; failure mode usually short |
| Back-to-back MOSFETs with isolated gate drive | No holding current; can turn off at any time; trailing-edge dimming possible | More parts; isolated gate supply; switching transients need management |

## Failure modes decide the protection

Semiconductor switches usually fail **short**. A relay usually fails open, but its contacts can weld under high inrush. A product whose lamp must never be stuck on under a fault needs either a mechanical disconnect in series or a fault response that opens something upstream; firmware cannot turn off a shorted triac. For a lamp, stuck-on is usually an annoyance rather than a hazard, but write that judgement down.

## Dimming is another product

Phase-control dimmers delay the turn-on within each half-cycle (leading edge, with a triac) or turn off part-way through it (trailing edge, with MOSFETs or IGBTs). They need a zero-crossing reference, timing accurate to tens of microseconds and a lamp designed for dimming. Leading-edge dimming of capacitive-input LED lamps produces large current spikes and audible noise; trailing-edge dimming is usually kinder to them. A zero-cross optocoupler cannot do phase control at all, by design. p1's expansion header leaves room for a small MCU that could detect zero crossings and time a random-phase driver in a later spin; that would change the protection, EMC and lamp-compatibility analysis.

### Exercise 12 · Pick for a different load

A customer wants the same controller for (a) a 1.5 kW resistive heater, (b) a 40 W ceiling fan motor, (c) a strip of five 7 W LED lamps on one switch. For each, choose a switch type and name the one rating or behaviour you would check first.

<details><summary>Worked solution</summary>
<p>(a) Heater: 6.5 A RMS; a zero-cross triac on a heatsink or a relay. Check the triac's RMS rating at the real case temperature, or the relay's contact rating, and the terminal and track current. (b) Fan: inductive. A triac needs adequate commutating dv/dt rating or a snubber; check commutation. A relay avoids the issue. (c) Five lamps: the summed capacitor-charging pulses are larger, which helps latching, but inrush grows fivefold; check first-cycle inrush against the triac's surge rating and the fuse.</p>
</details>

# 13 | ESP8266 hardware and firmware fault behaviour

The ESP8266 makes Lambka useful; it also introduces states in which the output must still be safe: reset, boot, flashing, brownout, a hung task and an interrupted update.

## Strapping pins and boot behaviour

At reset the ESP8266 samples GPIO0, GPIO2 and GPIO15 to choose the boot mode, so those pins need defined pull-ups or pull-downs (p1: GPIO0 and GPIO2 high, GPIO15 low, EN and RST pulled up). Several pins toggle or output clock signals during boot, and the UART pins carry the boot ROM's messages. A load output must use a pin that stays quiet during reset and boot; GPIO5 is a common choice because it is not a strapping pin and is not used by the boot ROM. Confirm the behaviour on the actual module with a logic analyser before relying on it.

## Hardware defaults

p1's R5 pulls the MOSFET gate low with 100 kΩ. That keeps the opto LED off while GPIO5 is high-impedance: during reset, boot and flashing. It does **not** turn the lamp off if the processor actively drives GPIO5 high and then hangs. Define the electrical state for every processor state:

| Processor state | GPIO5 | Lamp |
|---|---|---|
| Unpowered or in reset | High impedance | Off (pull-down) |
| Boot ROM, download mode | High impedance (verify) | Off |
| Application running | Driven by firmware | As commanded |
| Application hung with output on | Driven high | **On until a watchdog reset** |
| Brownout during a radio burst | Undefined, then reset | Off after reset; may flicker |

## Firmware requirements that follow

- Configure GPIO5 as an output driven low as early as possible in startup.
- Use a hardware watchdog with bounded work between kicks, and test recovery with the output on.
- Make the power-restore policy explicit (always off, or last state) and limit flash writes if the state is saved.
- Debounce local buttons, coalesce rapid network commands and enforce a minimum switching interval.
- Keep local control working without Wi-Fi, and authenticate network control. Keep credentials out of source control and logs.
- Design over-the-air updates with authentication, an interrupted-update recovery path and rollback. Flash size alone does not provide two-slot recovery.
- Program and debug only from the external low-voltage supply with the mains disconnected; p1 provides J2 with a back-feed diode for that purpose.

## Faults the firmware cannot fix

A triac that has failed short, a MOSFET that has failed short and a welded relay all ignore the firmware. So does a lamp powered through a leakage path. Firmware reliability is necessary but is never the protection against a hardware fault.

### Exercise 13 · The radio task hangs with the lamp on

Describe, step by step, what happens if the Wi-Fi task deadlocks with GPIO5 high. Which mechanism turns the lamp off, how long might it take, and how would you test it without mains?

<details><summary>Worked solution</summary>
<p>The pull-down cannot override an actively driven high output, so the lamp stays on. If the watchdog is fed only from a healthy main loop, it expires after its timeout (often seconds) and resets the chip; GPIO5 goes high-impedance and R5 turns the opto LED off, so the triac stops at the next current zero. If the watchdog is fed from a timer interrupt that keeps running, it never fires: feed it only when every task has reported progress. Test with the opto LED circuit powered from the bench 5 V and mains disconnected: inject a deliberate deadlock in a test build, record GPIO5 and the LED current, and measure the time to reset.</p>
</details>

# 14 | PCB layout for mains

A mains PCB is first a safety drawing and only then a routing problem. Draw the domains before placing a single trace.

## Map the domains

Mark three kinds of region: **hazardous mains** (line, switched line, neutral and everything galvanically connected to them, including the triac tab and the optocoupler's output pins), **SELV** (everything that may be touched or connected to a programmer) and the **barrier** between them. Only components rated to bridge the barrier may cross it: here the supply module and the optocoupler. Every other crossing, including silkscreen-only “keep-outs”, is a defect.

p1 places mains on the left, SELV on the right and a 6 mm gap between them, with a milled slot under the optocoupler. The optocoupler's pin 5 (the photo-triac substrate) is unconnected but at mains potential, so the design rules treat its pad as mains. That is the level of detail the domain map needs.

## Distances in the layout

Apply the barrier rule (chapter 6) to copper on both layers, pads, vias, pours, slots, the board edge and mounting holes. Between different mains nets, functional spacing still matters: line to switched line and line to neutral see the full mains voltage and the same transients. p1 uses 2.5 mm functional spacing there. Remember the edge cases: a via under a component body, a pour that reaches a mounting hole, a test pad near the slot.

## Current and heat in traces

A lamp switch carries little current, but the fault current until the fuse clears is large. Size mains traces for the fuse's let-through, not only for the lamp: a trace that is a better fuse than the fuse is a design error. For normal current, an IPC-2152-style chart relates width, copper thickness and temperature rise; for 1 A on 35 µm copper, a 1 mm trace rises only a few kelvin. Keep the triac's MT1/MT2 copper wide enough to spread its small heat and the terminal joints robust.

## Loops and noise

The triac gate circuit is small and sensitive: keep R1, R2 and the optocoupler close to the triac, with the gate-to-MT1 loop short, so line transients do not couple into the gate. The low-voltage side still has a radio: keep the ESP module's antenna clear of copper on every layer and away from the mains wiring, and keep the 5 V and 3.3 V decoupling loops tight.

## Materials and process

Specify the laminate (and its CTI if creepage depends on it), the copper weight and the solder mask, but do not credit solder mask as insulation. Flux residues and dust reduce surface resistance, so specify cleaning. If the design relies on conformal coating, the process, coverage and inspection become part of the safety argument.

## What the CAD checks prove

ERC and DRC show that the board matches its schematic and its configured rules. They do not show that the rules are adequate, that components are approved and genuine, that wiring or the enclosure respects the barrier, or that the product survives faults. Report CAD results as CAD results.

### Exercise 14 · Audit a barrier

On p1's layout (or any mains board), list every object within 8 mm of the barrier line on either layer. For each, state its domain, its distance to the other domain and whether it is a permitted crossing. Then name one barrier path that the PCB rule checker cannot see.

<details><summary>Review criteria</summary>
<p>A complete answer includes pads of the module and optocoupler, the slot and its end clearances, pours on both layers, vias, silkscreen (irrelevant electrically but a hint of intent), mounting holes and their screws, and the board edge if the enclosure is conductive. Paths the checker cannot see: wires in the terminal block, the module's internal construction, the optocoupler's internal insulation, a metal screw through the triac tab, or a loose wire inside the box.</p>
</details>

# 15 | Enclosure, wiring and terminals

The enclosure completes the barrier, contains faults and keeps fingers out. A PCB that is perfect on its own can be made unsafe by one loose wire.

## The enclosure

Choose the enclosure material for insulation, maximum temperature, flammability and mechanical strength. “ABS” names a polymer family, not a rating: look for the flammability classification of the specific grade, its glow-wire or heat-resistance performance where the product standard asks for it, and its behaviour at the internal temperature. Openings must prevent access to hazardous parts with the standard test finger and keep foreign objects out. Screws holding the lid must not reach live parts.

## Securing what moves

Fix the PCB and the module mechanically. Provide strain relief so that a pull on the cable loads the enclosure, not the terminal. Route mains wires so that if one comes free from its terminal, it cannot reach the low-voltage side; ties, barriers or separate compartments achieve that. Breadboard jumpers and push-on connectors have no place in a mains assembly.

## Terminals, wires and ferrules

Select wire cross-section and insulation for the current, the installation rules and the temperature. Check the terminal block's rated voltage, current, wire range and torque; p1's MKDS 1,5 block is rated 320 V at 5.08 mm pitch. Ferrules on stranded wire must match the terminal and be crimped with the correct tool. A bare stranded end clamped in a screw terminal can loosen as the strands settle.

## Protective earth

If the lamp or the enclosure is Class I (with exposed metal that relies on earthing), the protective earth must be continuous through the product, never switched and never used as a return. A plastic, double-insulated (Class II) lamp has no earth connection; do not add one to plastic parts. Decide which class the product is before choosing terminals.

### Exercise 15 · Inspect a box

Imagine Lambka built into an ABS box with screw terminals and a cable gland. List ten inspection points that a reviewer would check before any energisation, in the order they would check them.

<details><summary>Review criteria</summary>
<p>Good lists include: enclosure material identity and rating; lid screws and their distance to live parts; cable gland or clamp providing strain relief; correct wire size and insulation colour; ferrules crimped and matched to the terminal; terminal torque; earth continuity if Class I; mains wires restrained away from SELV; PCB and module secured; no foreign objects or flux residue; the programming header inaccessible or clearly SELV; labelling of supply and load. Order should go from mechanical and insulation checks to continuity and insulation measurement, never starting with power.</p>
</details>

# 16 | Measurement and test planning

Measurements on mains equipment are where most hobbyist accidents happen. The course's experiments stay at low voltage; this chapter explains why and what a proper mains test procedure must contain.

## Instruments and categories

Meters and probes carry a **measurement category** (CAT II, III, IV) and voltage rating that state which installation points they may be used on. A CAT III 600 V meter suits work at a distribution board; a meter with no category marking belongs on bench electronics. Leads and probes need matching ratings and intact insulation.

A conventional bench oscilloscope's probe ground is connected to protective earth. Clipping it to a mains node connects that node to earth through the probe: a short circuit at best, an energised scope chassis if earth is missing. Floating the scope by defeating its earth makes every exposed metal part potentially live. An isolation transformer on the device under test changes the fault paths but is not a licence to clip grounds anywhere. Use a high-voltage differential probe rated for the differential and common-mode voltages, or a battery-powered isolated instrument rated for the job. Tektronix's [floating-measurement guide](https://www.tek.com/en/datasheet/floating-measurements-selection-guide) compares the options.

## Current measurement

A current probe or a clamp with enough bandwidth shows the lamp's pulsed current. A shunt in the neutral is tempting and dangerous: the shunt is at mains potential. Measure the voltage across it only with a rated differential probe.

## What can be learned at low voltage

These experiments need no mains connection:

1. With the mains disconnected, power the low-voltage side from a current-limited bench supply set to the module's minimum output. Verify GPIO5 and the opto LED current through reset, boot, download mode and a deliberate firmware hang.
2. Measure the 3.3 V rail during Wi-Fi traffic and compare with chapter 8's headroom estimate.
3. With an isolated, current-limited low-voltage AC source (for example a 24 V safety transformer) and a resistive load, observe triac triggering and commutation and compare the gate current with chapter 10's network. Check the gate network values before raising the voltage; R1 sized for 230 V delivers little gate current at 24 V.
4. Compare resistor and LDO heating with the calculations.

A 24 V surrogate does not reproduce a 230 V lamp's driver. The optocoupler's 20 V inhibit window occupies a large fraction of a 34 V-peak waveform. Such experiments teach device behaviour; they cannot qualify lamp compatibility, ghosting or insulation.

## A mains test procedure, when one is needed

A mains test is a separate, reviewed activity. Its written procedure states at least: who performs it and their competence; the location and the supply (with RCD protection and an accessible isolator); the enclosure state of the device; the instruments and their ratings; the connection diagram; the hazards and how each is controlled; the steps, limits and stop conditions; how stored energy is discharged and verified before touching; and what evidence is recorded. An RCD or a series incandescent “limiter” lamp reduces some consequences but is not isolation and not readiness.

### Exercise 16 · Write a low-voltage test card

Write a test card for experiment 1 above. Include setup, supply settings and current limit, connections, expected readings, stop conditions, evidence files and what the test does **not** establish.

<details><summary>Review criteria</summary>
<p>The card names the exact board revision, states that J1 is unconnected and the mains side unpowered, sets the bench supply to about 4.75 V with a current limit appropriate to the module (for example 0.5 A), and lists measurement points (GPIO5, Q2 drain, LED current via the voltage across R3). It predicts the LED current from chapter 10, defines stop conditions (current above the limit, smell, heat), names the log and trace files, and states that it establishes nothing about the mains side, the lamp or insulation.</p>
</details>

# 17 | Reading the p1 design: a case review

This chapter applies the course to the Lambka p1 pilot board as recorded on 22 October 2026. Each row is a review observation for the board's owner to consider, not a change made by this course.

| Area | p1 choice | Course finding | Evidence that would close it |
|---|---|---|---|
| Supply module | HLK-5M05, straddling the slot | Barrier depends on the module's construction and identity | Traceable certificate for the exact model; measured temperature in the box |
| 3.3 V regulator | AMS1117-3.3 from 5 V | Worst-case dropout headroom during bursts is near zero (chapter 8) | Rail traces during Wi-Fi traffic at 4.75 V input; or a lower-dropout regulator |
| Opto LED current | 150 Ω with orange LED in series | Worst case ≈ 5.3 mA against 5 mA rated trigger current (chapter 10) | Exact LED data and temperature range, or R3 ≈ 100 Ω |
| Gate network | R1 360 Ω, R2 330 Ω | Static trigger estimate ≈8.7 V; actual firing is unverified, and the 1 A rating is non-repetitive (chapter 10) | BOM rule: zero-cross driver only; gate-current trace with the lamp |
| Lamp compatibility | No snubber, no bleeder on board | Latching and retriggering with capacitive-input lamps is the open question (chapters 9–11) | Lamp current, triac voltage and gate current with the chosen lamps |
| Protection | T1A ceramic fuse, then 275 V MOV | Thermal behaviour of the MOV under sustained overvoltage is unaddressed (chapter 7) | Thermally protected MOV or thermal fuse; or a documented argument |
| Barrier | 6 mm project rule, 6.36 mm closest | Exceeds orientation reinforced values; wiring and screws not covered (chapter 6) | Standard and edition chosen; enclosure and wiring inspection |
| Programming | J2 with D2 back-feed diode | Correct intent; procedure must forbid use with mains connected | Written procedure; header inaccessible in the closed box |
| Firmware | Not written | Output default, watchdog, rate limit and update recovery are requirements (chapter 13) | Code review and fault-injection tests at low voltage |

Two items are stronger than they look. Choosing a zero-cross driver limits first-cycle inrush and keeps the optocoupler far from its surge rating in normal operation. Removing the SSR's snubber removes the largest leakage path that caused ghosting in the prototype. Two are weaker than they look: the LED-current margin and the LDO headroom are both easy to fix at this stage and hard to diagnose later.

### Exercise 17 · Write your own review

Pick three rows of the table. For each, write the finding in one sentence, the risk if it is wrong, the cheapest experiment that settles it and the change you would make if the experiment fails.

<details><summary>Review criteria</summary>
<p>A strong review keeps finding, risk and evidence separate, quantifies where possible (5.3 mA vs 5 mA, 0.02–0.12 V headroom) and proposes experiments that can run at low voltage first. It does not claim that the board is safe or unsafe; it states what is known, assumed and measured.</p>
</details>

# 18 | Review gates and capstone

A mains product passes through gates, each closed by evidence rather than by confidence. Use these for Lambka or your own design; the notebook's gate list tracks them.

| Gate | Deliverable | What a reviewer verifies |
|---|---|---|
| G0 requirements and standard | Intended use, installation, applicable standard and edition | Overvoltage category, pollution degree, insulation class, environment |
| G1 insulation and barrier | Barrier map, distances, component approvals | Every path, including wiring, screws and component internals |
| G2 protection coordination | Fuse, MOV, thermal and fault analysis | Breaking capacity, \(I^2t\), sustained overvoltage behaviour |
| G3 supply and control | Supply chain, headroom, firmware fault table | Worst-case margins and states during reset and hang |
| G4 switching and lamp compatibility | Gate-drive calculation and lamp test plan | Margins against \(I_{FT}\), \(I_{GT}\), \(I_L\), \(I_H\); ghosting |
| G5 CAD and enclosure | Schematic, layout, checks, enclosure and wiring design | Parity, rules, mechanical retention, access |
| G6 low-voltage tests | Test cards and records | Behaviour that can be shown without mains |
| G7 mains qualification | Reviewed procedure, measurements, standard assessment | Temperature, leakage, insulation, faults, EMC |

A course tick cannot close a gate. An agent review can find a missing number or an inconsistent rating; only evidence can establish behaviour.

## Oral examination

1. Why does a 7 W LED lamp draw a 0.2 A current peak, and when is its current below the triac's holding current?
2. What decides the clearance between the programming header and the mains, and why is the optocoupler's 4170 V rating not that number?
3. What happens if the firmware hangs with the lamp on?
4. Why must the opto LED current exceed the rated trigger current by a margin, and what is the margin on p1?
5. What does a 275 VAC MOV do during a lost neutral, and what stops it from overheating?
6. Why does a switched-off lamp sometimes glow, and how does a bleeder stop it?
7. Which CAD result would you report, and which claims does it not support?
8. What did your last experiment establish, and what did it leave open?

**Final assignment:** write a 3–6 page design review of Lambka p1 or your own mains switch, attach your calculations and tool exports, and ask a helper for the most consequential unsupported assumption rather than approval. Decide the smallest low-voltage experiment or design change that addresses it.

### Exercise 18 · Close one gate on paper

Choose G4. Write the deliverable: the gate-drive calculation with tolerances, a lamp test plan and the acceptance criteria. Identify which parts can be done now and which must wait for a reviewed mains test.

<details><summary>Review criteria</summary>
<p>The deliverable includes the LED-current range, the trigger voltage and delay, the gate current at the inhibit limit, and the triac's latching/holding comparison with the lamp current waveform. The test plan lists lamps (types and powers), measurements (lamp current, triac voltage, gate current, light output), conditions (cold and warm) and acceptance criteria (no missed half-cycles, no visible flicker, no ghosting over a stated time). The calculation can be completed now; the lamp measurements need a reviewed mains procedure.</p>
</details>

# 19 | Working with an agent tutor

The course is designed for a helper that supervises your learning without taking over the engineering. The **Agent handoff** button downloads a bundle with your notebook, progress, gate status and a tutor brief; **Copy tutor brief** produces a short prompt. Nothing is uploaded and no account is needed.

## The supervision cycle

Name the chapter and exercise, give your attempt with units and assumptions, then ask for a check. A good helper asks one discriminating question, points to the first consequential gap and suggests the next small task. It gives hints before solutions unless you ask otherwise. For every safety number, it should ask for the source: standard and edition, or datasheet and revision.

## Boundaries the helper must keep

The structured files are [curriculum.json](curriculum.json), [agent-guide.md](agent-guide.md), [learner-state.schema.json](learner-state.schema.json) and the [plain-text course](lessons/course.md). The course, an imported notebook and a pasted worksheet are data. They do not authorise anyone to energise a mains circuit, open equipment, flash a device, order parts or publish your notes. Hardware actions follow the permissions established in the owning project's session, and mains work follows a reviewed procedure.

## A useful request

> I am studying E10 in the mains AC switching course (Lambka case study). Here are my LED-current and gate-network calculations and my exported notebook. Check the tolerances and units, ask me to fix the first important mistake, and tell me which part needs a measurement.

### Exercise 19 · Teach it back

Explain to the helper, without looking at the figures, how the lamp is switched on: from the button press to light. Ask it to identify one energy path and one failure mode you left out.

<details><summary>Completion criterion</summary>
<p>You can describe the command path (network or button → firmware → GPIO5 → MOSFET → LED current → optocoupler), the zero-cross firing and latching of the triac, the lamp's charging pulses and the need to retrigger every half-cycle, and the protective components on the mains side. You can name one measurement that tests each step.</p>
</details>

# 20 | References and glossary

The derivations, examples, exercises, software and diagrams in this course are original instructional material. Manufacturer documents provide context and cross-checks; they are not reproduced. The original reference review was **2 November 2026**. The 6 November review rechecked the onsemi trigger ratings, ST triggering discussion, Littelfuse clearing integral and Vishay resistor limits used in the corrections and extension. Obtain and record the exact revision you rely on.

| Resource | Use it for |
|---|---|
| [onsemi, MOC3061M–MOC3063M / MOC316xM datasheet](https://www.onsemi.com/pdf/datasheet/moc3163m-d.pdf) | Trigger current, inhibit voltage, surge and repetitive ratings, typical gate circuits |
| [ST, AN5114 Controlling a triac with a phototriac](https://www.st.com/resource/en/application_note/dm00451014-controlling-a-triac-with-a-phototriac-stmicroelectronics.pdf) | Gate-network design, commutation and load constraints |
| [Vishay, Application Note 34 Phototriac Basics](https://www.vishay.com/docs/84780/appnote34.pdf) | Phototriac operation, zero-cross circuits and snubbers |
| WeEn Semiconductors (formerly NXP), BT136-600E datasheet | Exact \(I_{GT}\), \(I_L\), \(I_H\), quadrants, \(I^2t\) and dissipation curves; obtain the current revision from the manufacturer |
| [TI, Understand Safety Requirement and Isolation Needs, SDAA268](https://www.ti.com/lit/an/sdaa268/sdaa268.pdf) | Step-by-step clearance and creepage determination |
| [TI, Basic Calculation of a Buck Converter's Power Stage, SLVA477B](https://www.ti.com/lit/an/slva477b/slva477b.pdf) | First-pass buck calculations (chapter 4) |
| [Littelfuse, designing with thermally protected TMOV varistors](https://www.littelfuse.com/~/media/electronics_technical/application_notes/varistors/littelfuse_designing_with_thermally_protected_tmov_varistors_in_spd_and_ac_line_application_note.pdf) | MOV thermal runaway and thermal protection; the legacy link may redirect or fail |
| [Tektronix, floating measurements selection guide](https://www.tek.com/en/datasheet/floating-measurements-selection-guide) | Differential and isolated measurement options |
| IEC 60664-1 | Insulation coordination: overvoltage categories, clearance and creepage tables |
| IEC 61140 | Protection against electric shock: principles and equipment classes |
| IEC 60669-2-1, CISPR 15 and household-appliance standards | Candidate product and EMC standards; which apply depends on how the product is built, installed and sold |

The next courses in this series: [buck converters](https://psym.pl/buck-course/), [power LED drivers](https://psym.pl/led-course/) and [BLDC motor drives](https://psym.pl/bldc-course/).

## Glossary

| Term | Meaning |
|---|---|
| RMS / PF | Heating-equivalent magnitude / real power divided by apparent power, including distortion |
| OVC / PD / CTI | Overvoltage category / pollution degree / comparative tracking index |
| Basic / supplementary / reinforced | Insulation grades: one level, an independent second level, one system equivalent to two |
| SELV | Safety extra-low-voltage circuit: voltage limits plus protective separation, including under single faults |
| \(I_{GT}\), \(I_L\), \(I_H\) | Triac gate trigger, latching and holding currents |
| \(I_{FT}\), \(V_{INH}\) | Optocoupler LED trigger current and zero-cross inhibit voltage |
| Snubber | RC network that limits dv/dt; across a switch it adds off-state leakage |
| Bleeder | Deliberate load that shunts leakage or discharges stored energy |
| X / Y capacitor | Safety capacitor across the line / across a barrier or to earth |
| DNP | A footprint deliberately left unpopulated |

## Model limitations in one place

The power tool assumes a sinusoidal supply. The lamp tool models a bridge, series resistance, bulk capacitor and constant-power driver, without filter components, inductors or driver start-up. The ghosting tool uses an ideal bridge, a fixed start/stop threshold and a lumped leakage branch; real lamps have internal loads and filters. The supply tool uses a tolerance, a series resistance and a response time instead of a module model. The gate-network tool uses datasheet maxima and a fixed gate voltage; it does not simulate retriggering. The discharge tool uses an ideal RC plus entered tolerances; it does not model dielectric absorption, leakage or resistor faults automatically. Chapter 21 derives the fault cases. The lamp solver resolves its input RC time constant and rejects voltage collapse instead of extending the constant-power load to negative bulk voltage. None qualifies a component or a product.


# 21 | Extension: discharge tolerances and single faults

Chapter 2 gave an ideal discharge calculation. A nominal value at the exact limit has no room for component spread. This extension turns that calculation into a reviewable component budget. It uses the same **illustrative**, not normative, target: 100 nF across the pins, 253 V RMS maximum, and 60 V within 1 s. Use the actual product standard to choose a real target.

## Separate the slow-discharge and high-power corners

Let \(C_N\) be nominal capacitance, \(R_N\) the nominal **total** series resistance, and \(\epsilon_C,\epsilon_R\) their positive fractional tolerances. The slow corner has both values high:

\[
t_{slow}=R_N(1+\epsilon_R)C_N(1+\epsilon_C)
\ln\frac{\sqrt2V_{rms,max}}{V_t}.
\]

Therefore the largest nominal resistance is

\[
R_{N,max}=\frac{t_{target}}
{C_N(1+\epsilon_C)(1+\epsilon_R)\ln(\sqrt2V_{rms,max}/V_t)}.
\]

For capacitance +20% and resistance ±5%, the ideal 5.600 MΩ limit becomes **4.445 MΩ nominal**. Choose two equal 2.2 MΩ resistors in series, 4.4 MΩ total, as an arithmetic example. The nominal time is **0.786 s**; the slow corner is **0.990 s**. This is little margin: temperature coefficients, drift and additional input capacitance still need budgets.

Continuous power is greatest with resistance **low**, a different corner:

\[
P_{max}=\frac{V_{rms,max}^2}{R_N(1-\epsilon_R)}=15.3\ \text{mW}.
\]

Use [Laboratory 6 in chapter 2](#ch02): enter 4.4 MΩ, two resistors, C tolerance 20% and R tolerance 5%. Compare the nominal and slow-corner curves. The calculator proposes the tolerance-adjusted nominal limit when chosen resistance is zero.

## Equal nominal values do not guarantee equal voltage

For \(n\) equal nominal resistors, one at its high limit and the other \(n-1\) at their low limit, the largest individual voltage fraction is

\[
f_{max}=\frac{1+\epsilon_R}
{(1+\epsilon_R)+(n-1)(1-\epsilon_R)}.
\]

For two ±5% parts, this is 0.525: **132.8 V RMS** while connected to the line and **187.8 V initial peak** after unplugging at the crest. Those two numbers describe different stresses. Compare the continuous sinusoid with the part’s AC RMS rating, the charged-capacitor decay with its DC/pulse limits, and surges with its pulse specifications. A single wattage or package size settles none of them. Vishay document 20035, revision 14 April 2026, explicitly labels its operating-voltage column AC RMS/DC; its pulse graphs are separate.

## Faults change the circuit, not just the tolerance

An **open** in either series resistor breaks the only intended discharge path. With no other load in this ideal model the capacitor retains its initial voltage indefinitely. Two series parts provide voltage sharing, not redundancy. A second independent discharge branch can address this particular open-circuit fault, but adds power and needs its own fault analysis.

A **short** across one resistor leaves the surviving 2.2 MΩ part across the whole line. Nominal discharge becomes faster, about 0.393 s. At its −5% limit it dissipates **30.6 mW**, but it must withstand **253 V RMS** continuously and the **357.8 V** initial discharge voltage. A part can satisfy the milliwatt calculation while failing the voltage requirement. Whether a given fault must be applied, and which consequences are acceptable, comes from the applicable standard and construction assessment.

The analysis assumes ideal resistors and a single capacitor. Parallel loads can speed discharge but cannot be credited unless they remain present in the relevant fault; extra capacitance slows it. Dielectric absorption can produce voltage rebound. A calculation does not replace verification before contact.

### Exercise 21 · Reject a nominal-only discharge design

A proposal uses two 2.7 MΩ ±5% resistors and a 100 nF +20% capacitor for the illustrative target. Calculate nominal and slow-corner discharge times and decide whether the proposal meets it. Repeat with two 2.2 MΩ parts. For the replacement, report the worst individual voltage in normal operation and the open/short consequences. State which missing data prevent selecting a real resistor.

<details><summary>Worked solution</summary>
<p>5.4 MΩ gives 0.964 s nominal but 1.215 s at the slow corner, so it fails the stated arithmetic target. 4.4 MΩ gives 0.786 s nominal and 0.990 s at the slow corner. The largest normal individual share is 52.5%: 132.8 V RMS and 187.8 V initial peak. One open defeats discharge; one short leaves the surviving resistor at 253 V RMS, 357.8 V initial peak and up to 30.6 mW. Needed data include applicable standard and fault requirements, total capacitance including the module, actual resistor AC/DC/pulse and temperature ratings, drift, physical separation and evidence from the reviewed discharge test. The revised nominal value alone does not qualify the assembly.</p>
</details>
