skill
SPICE Simulation Skills
Public Made by Adomby adom
Pick, run and license the right SPICE simulator from an AI thread: ngspice in the container by default, LTspice and PSpice for TI on a Windows host for vendor models.
main
John Lauer
Publish 0.1.0
5442934
* Portable 12V->5V 1A sync buck, 500 kHz voltage mode, type-III-ish comp
* Only R L C V E S B elements + .model SW: runs in ngspice, LTspice, QSPICE, PSpice
Vin vin 0 12
Vramp ramp 0 PULSE(0 1 0 1.98u 10n 10n 2u)
* power stage (ideal switches with Rds(on))
S1 vin sw hs 0 SWH
S2 sw 0 ls 0 SWL
L1 sw lx 15u
Rdcr lx vout 0.05
Cout vout ce 44u
Resr ce 0 5m
Rload vout 0 5
* load step 1A -> 2A at 3 ms
Sstep vout ld stp 0 SWH
Rld ld 0 5
Vstp stp 0 PULSE(0 1 3m 1u 1u 1 2)
* feedback 5V -> 0.8V ref, soft start 1 ms
Rtop vout fb 52.5k
Rbot fb 0 10k
Vref ref 0 PWL(0 0 1m 0.8)
* OTA error amp (gm) with Rc/Cc/Cp, output clamped 0..2 V, feed-forward cap on Rtop
Cff vout fb 1n
Gea 0 eo ref fb 200u
Rea eo 0 10Meg
Rc eo cz 10k
Cc cz 0 10n
Cp eo 0 100p
Dhi eo vhi DCLAMP
Vhi vhi 0 2
Dlo 0 eo DCLAMP
.model DCLAMP D(Is=1e-12 N=0.05)
Bcomp vc 0 V=max(0.02,min(0.98,v(eo)*0.5))
* PWM: comparator of vc vs ramp -> gate drives (smooth)
Bhs hs 0 V=0.5+0.5*tanh(200*(v(vc)-v(ramp)))
Bls ls 0 V=0.5-0.5*tanh(200*(v(vc)-v(ramp)))
.model SWH SW(Ron=0.1 Roff=1Meg Vt=0.5 Vh=0)
.model SWL SW(Ron=0.06 Roff=1Meg Vt=0.5 Vh=0)
.tran 20n 5m 0 20n
.meas tran vavg AVG v(vout) FROM=2.5m TO=2.9m
.meas tran vpp PP v(vout) FROM=2.5m TO=2.9m
.meas tran vmin MIN v(vout) FROM=3m TO=3.5m
.meas tran vavg2 AVG v(vout) FROM=4.5m TO=4.9m
.end