* SPICE netlist
D1 N008 N010 D
D2 N008 N011 D
D3 N008 N012 D
R5 N010 N014 {r_limit}
R6 N011 N017 {r_limit}
R7 N012 N019 {r_limit}
V7 N013 0 PULSE(3.3 0 0 100n 100n 1m 2m)
V2 N016 0 PULSE(3.3 0 250u 100n 100n 1m 2m)
V8 N018 0 PULSE(3.3 0 500u 100n 100n 1m 2m)
XU7 N015 N016 N007 0 N017 LM324 ;pnba In+)In-)V+)V-)OUT
XU8 N015 N018 N007 0 N019 LM324 ;pnba In+)In-)V+)V-)OUT
Q1 N001 N005 N007 0 2N2222
R17 N005 N004 1k
XU10 N006 N003 N001 0 N004 LM324 ;pnba In+)In-)V+)V-)OUT
R18 N009 0 {pot_r}
V1 N001 0 12
R19 N006 N002 10k
R20 N004 N003 10k
V3 N002 0 3.3
R23 N002 N015 10k
R24 N015 0 10k
R1 N003 N009 1k
R2 0 N006 10k
R3 N008 N007 56
XU6 N015 N013 N007 0 N014 OP284 ;pnba In+)In-)V+)V-)OUT
.SUBCKT LM324 1 2 3 4 5
C1 11 12 5.544E-12
C2 6 7 20.00E-12
DC 5 53 DX
DE 54 5 DX
DLP 90 91 DX
DLN 92 90 DX
DP 4 3 DX
EGND 99 0 POLY(2) (3,0) (4,0) 0 .5 .5
FB 7 99 POLY(5) VB VC VE VLP VLN 0 15.91E6 -20E6 20E6 20E6 -20E6
GA 6 0 11 12 125.7E-6
GCM 0 6 10 99 7.067E-9
IEE 3 10 DC 10.04E-6
HLIM 90 0 VLIM 1K
Q1 11 2 13 QX
Q2 12 1 14 QX
R2 6 9 100.0E3
RC1 4 11 7.957E3
RC2 4 12 7.957E3
RE1 13 10 2.773E3
RE2 14 10 2.773E3
REE 10 99 19.92E6
RO1 8 5 50
RO2 7 99 50
RP 3 4 30.31E3
VB 9 0 DC 0
VC 3 53 DC 2.100
VE 54 4 DC .6
VLIM 7 8 DC 0
VLP 91 0 DC 40
VLN 0 92 DC 40
.tran 10n 10m
.param r_limit=670
.param pot_r={10k/64}

* LTspice schematic (.asc)
Version 4
SHEET 1 2800 2080
WIRE 136 -1040 -24 -1040
WIRE 456 -1040 136 -1040
WIRE 136 -944 136 -1040
WIRE 136 -832 136 -864
WIRE -264 -752 -488 -752
WIRE 24 -720 -104 -720
WIRE 152 -720 104 -720
WIRE -264 -704 -264 -752
WIRE 456 -640 456 -1040
WIRE -24 -624 -24 -1040
WIRE -104 -608 -104 -720
WIRE -56 -608 -104 -608
WIRE 152 -592 152 -720
WIRE 152 -592 8 -592
WIRE 232 -592 152 -592
WIRE 392 -592 312 -592
WIRE -488 -576 -488 -752
WIRE -392 -576 -488 -576
WIRE -264 -576 -264 -624
WIRE -56 -576 -264 -576
WIRE -264 -528 -264 -576
WIRE -104 -528 -104 -608
WIRE -24 -528 -24 -560
WIRE -488 -480 -488 -576
WIRE 456 -480 456 -544
WIRE 648 -480 456 -480
WIRE 1240 -480 728 -480
WIRE -264 -384 -264 -448
WIRE -104 -384 -104 -448
WIRE -488 -368 -488 -400
WIRE 1240 -352 1240 -480
WIRE 1240 -352 1176 -352
WIRE 1288 -352 1240 -352
WIRE 1400 -352 1288 -352
WIRE 1176 -288 1176 -352
WIRE 1288 -288 1288 -352
WIRE 1400 -288 1400 -352
WIRE 1176 -160 1176 -224
WIRE 1288 -160 1288 -224
WIRE 1400 -160 1400 -224
WIRE 456 -144 456 -480
WIRE 456 -144 376 -144
WIRE 488 -144 456 -144
WIRE 632 -144 488 -144
WIRE -104 -112 -104 -304
WIRE -968 -48 -1400 -48
WIRE 376 -48 376 -144
WIRE -968 -32 -968 -48
WIRE 344 -32 -968 -32
WIRE 1176 -16 1176 -80
WIRE 1176 -16 408 -16
WIRE -1400 0 -1400 -48
WIRE 344 0 264 0
WIRE 376 48 376 16
WIRE -1400 112 -1400 80
WIRE 488 128 488 -144
WIRE 456 144 -1400 144
WIRE 1288 160 1288 -80
WIRE 1288 160 520 160
WIRE 264 176 264 0
WIRE 456 176 264 176
WIRE -1400 208 -1400 144
WIRE 488 224 488 192
WIRE -1400 320 -1400 288
WIRE 632 352 632 -144
WIRE 600 368 -744 368
WIRE -744 384 -744 368
WIRE -744 384 -1400 384
WIRE 1400 384 1400 -80
WIRE 1400 384 664 384
WIRE 264 400 264 176
WIRE 600 400 264 400
WIRE -1400 416 -1400 384
WIRE 632 448 632 416
WIRE -1400 528 -1400 496
WIRE -392 720 -392 -576
WIRE -392 848 -392 800
WIRE 264 848 264 400
WIRE 264 848 -392 848
WIRE -392 896 -392 848
WIRE -392 1040 -392 976
FLAG -1400 112 0
FLAG -1400 320 0
FLAG -1400 528 0
FLAG 376 48 0
FLAG 488 224 0
FLAG 632 448 0
FLAG -24 -528 0
FLAG -104 -112 0
FLAG 136 -832 0
FLAG -488 -368 0
FLAG -392 1040 0
FLAG -264 -384 0
SYMBOL LED 1160 -288 R0
SYMATTR InstName D1
SYMBOL LED 1272 -288 R0
SYMATTR InstName D2
SYMBOL LED 1384 -288 R0
SYMATTR InstName D3
SYMBOL res 1160 -176 R0
SYMATTR InstName R5
SYMATTR Value {r_limit}
SYMBOL res 1272 -176 R0
SYMATTR InstName R6
SYMATTR Value {r_limit}
SYMBOL res 1384 -176 R0
SYMATTR InstName R7
SYMATTR Value {r_limit}
SYMBOL voltage -1400 -16 R0
SYMATTR InstName V7
SYMATTR Value PULSE(3.3 0 0 100n 100n 1m 2m)
SYMBOL voltage -1400 192 R0
SYMATTR InstName V2
SYMATTR Value PULSE(3.3 0 250u 100n 100n 1m 2m)
SYMBOL voltage -1400 400 R0
SYMATTR InstName V8
SYMATTR Value PULSE(3.3 0 500u 100n 100n 1m 2m)
SYMBOL OpAmps/opamp2 488 96 R0
SYMATTR InstName U7
SYMATTR Value LM324
SYMBOL OpAmps/opamp2 632 320 R0
SYMATTR InstName U8
SYMATTR Value LM324
SYMBOL npn 392 -640 R0
SYMATTR InstName Q1
SYMATTR Value 2N2222
SYMBOL res 328 -608 R90
SYMATTR InstName R17
SYMATTR Value 1k
SYMBOL OpAmps/opamp2 -24 -656 R0
SYMATTR InstName U10
SYMATTR Value LM324
SYMBOL res -120 -400 R0
SYMATTR InstName R18
SYMATTR Value {pot_r}
SYMBOL voltage 136 -960 R0
SYMATTR InstName V1
SYMATTR Value 12
SYMBOL res -248 -608 R180
SYMATTR InstName R19
SYMATTR Value 10k
SYMBOL res 120 -736 R90
SYMATTR InstName R20
SYMATTR Value 10k
SYMBOL voltage -488 -496 R0
SYMATTR InstName V3
SYMATTR Value 3.3
SYMBOL res -408 704 R0
SYMATTR InstName R23
SYMATTR Value 10k
SYMBOL res -408 880 R0
SYMATTR InstName R24
SYMATTR Value 10k
SYMBOL res -120 -544 R0
SYMATTR InstName R1
SYMATTR Value 1k
SYMBOL res -248 -432 R180
SYMATTR InstName R2
SYMATTR Value 10k
SYMBOL res 744 -496 R90
SYMATTR InstName R3
SYMATTR Value 56
SYMBOL OpAmps/OP284 376 -80 R0
SYMATTR InstName U6