Reference Full example

Full example

A sinusoidal PWM inverter with an LC output filter. It's small enough to read in one sitting and exercises all three module domains at once — which makes it the best single answer to "how do these fit together?"

The source

Domain responsibilities

analog module Stamps L and C into the MNA matrix. The inductor current and capacitor voltage are tracked by the solver automatically.
digital module Compares the sine reference against the triangle carrier each step and writes ±400 V to generator_output.
module Wires the filter and generator together. Routes generator_output to the driven voltage source.

Note that nothing here reaches across a domain boundary illegally: the digital module never touches a primitive, the analog module holds no state, and main does no arithmetic. See Modules & domains.

Expected output

main.lc_out≈ 400 V peak sine at 50 Hz
main.generator_outputSquare wave ±400 V at 20 kHz

The LC filter passes 50 Hz — well below its ~2.5 kHz cutoff — and rejects the 20 kHz switching frequency, which sits 8× above cutoff and is attenuated roughly 64×.