* SPICE netlist
H1 N001 0 V1 1
V1 c Sw 0
R5 I_sense N001 100
C2 I_sense 0 100p
A1 set trip_reset 0 0 0 q_bar q 0 SRFLOP
V2 set 0 PULSE(0 1 0 {Trise_fall} {Trise_fall} {Ton_min} {Period})
V3 reset 0 PULSE(0 1 {Ton_max} {Trise_fall} {Trise_fall} {Trise_fall} {Period} )
H2 N002 0 V5 1
R8 N003 N002 100
C5 N003 0 100n
V4 ramp 0 PULSE(0 {slopeAmp} 0 {Period - 2*Trise_fall} {Trise_fall} {Trise_fall} {Period})
B1 sense_slope 0 V={Ri}*V(I_sense) + V(ramp)
V5 Sw N004 0
R10 I_out N003 1000
C7 I_out 0 10n
A2 0 reset 0 trip2 0 0 trip_reset 0 OR
B2 N005 0 V=if( V(sense_slope) > V(Vc), 1, 0)
R11 trip N005 100
C8 trip 0 10p
B3 FET_R 0 V=if( V(q) > 0.5, {Rfet}, 1meg )
R2 N004 p R=V(Rdiode)
B4 Rdiode 0 V= if( V(Sw) > V(p), 10m, 100k )
B5 trip2 0 V= V(trip) - V(set)
V6 On_time_ramp 0 PULSE(0 {1} 0 {Period - 2*Trise_fall} {Trise_fall} {Trise_fall} {Period})
B6 On_time 0 V=if( V(q) > 0.5, V(On_time_ramp), 0 )
R1 Sw a R = V(FET_R)
.param Period = {1/Fs}
.param Trise_fall = 1n
.param Ton_min = {D_min * Period }
.param Ton_max = {D_max * Period}
.param Rfet = 1m
.param Fs = 100k
.param D_max = 90
.param D_min = 5
.param slopeAmp = 0.8
.param Ri = 0.25

* LTspice schematic (.asc)
Version 4
SHEET 1 2368 1664
WIRE 368 -832 240 -832
WIRE -784 -784 -816 -784
WIRE -752 -784 -784 -784
WIRE -352 -784 -416 -784
WIRE -272 -784 -352 -784
WIRE -208 -784 -272 -784
WIRE -48 -784 -128 -784
WIRE -816 -768 -816 -784
WIRE -48 -768 -48 -784
WIRE -272 -752 -272 -784
WIRE -816 -672 -816 -688
WIRE -272 -656 -272 -688
WIRE -48 -656 -48 -688
WIRE 672 -592 608 -592
WIRE 784 -592 752 -592
WIRE 880 -592 784 -592
WIRE 1040 -592 960 -592
WIRE 1088 -592 1040 -592
WIRE 1168 -592 1088 -592
WIRE -400 -576 -528 -576
WIRE -304 -576 -400 -576
WIRE 368 -576 368 -832
WIRE 608 -576 608 -592
WIRE 784 -576 784 -592
WIRE 1040 -576 1040 -592
WIRE -880 -560 -1024 -560
WIRE -528 -544 -528 -576
WIRE 608 -480 608 -496
WIRE 784 -480 784 -512
WIRE 1040 -480 1040 -512
WIRE -528 -448 -528 -464
WIRE 368 -384 368 -496
WIRE 400 -384 368 -384
WIRE 432 -384 400 -384
WIRE 704 -384 512 -384
WIRE 1184 -384 784 -384
WIRE -768 -368 -1056 -368
WIRE -592 -368 -688 -368
WIRE -560 -368 -592 -368
WIRE -560 -352 -560 -368
WIRE -1056 -336 -1056 -368
WIRE -560 -256 -560 -288
WIRE 912 -256 848 -256
WIRE 960 -256 912 -256
WIRE -1056 -240 -1056 -256
WIRE 848 -240 848 -256
WIRE 368 -224 368 -384
WIRE 160 -208 112 -208
WIRE 192 -208 160 -208
WIRE -480 -176 -528 -176
WIRE -432 -176 -480 -176
WIRE 112 -176 112 -208
WIRE -528 -144 -752 -144
WIRE -432 -144 -528 -144
WIRE -304 -144 -368 -144
WIRE -224 -144 -304 -144
WIRE -80 -144 -112 -144
WIRE -48 -144 -80 -144
WIRE 848 -144 848 -160
WIRE -960 -128 -1056 -128
WIRE -896 -128 -960 -128
WIRE -1056 -112 -1056 -128
WIRE -528 -96 -592 -96
WIRE -224 -96 -528 -96
WIRE -96 -96 -128 -96
WIRE -48 -96 -96 -96
WIRE -752 -80 -752 -144
WIRE -592 -80 -592 -96
WIRE 112 -64 112 -96
WIRE -1056 0 -1056 -32
WIRE -752 16 -752 0
WIRE -592 16 -592 0
WIRE 368 16 368 -144
WIRE 400 16 368 16
WIRE -1072 640 -1184 640
WIRE -928 640 -1072 640
WIRE -1184 656 -1184 640
WIRE -720 720 -832 720
WIRE -576 720 -720 720
WIRE -832 736 -832 720
WIRE -1184 752 -1184 736
WIRE -832 832 -832 816
FLAG 240 -832 c
IOPIN -1040 -1456 BiDir
FLAG -48 -656 0
FLAG -352 -784 I_sense
FLAG -272 -656 0
FLAG -592 16 0
FLAG -752 16 0
FLAG -528 -144 reset
FLAG -528 -96 set
FLAG -304 -144 trip_reset
FLAG 1184 -384 p
IOPIN -96 -1008 BiDir
FLAG -96 -96 q
FLAG 608 -480 0
FLAG 784 -480 0
FLAG 400 16 a
IOPIN -880 -608 BiDir
FLAG 400 -384 Sw
FLAG -400 -576 sense_slope
FLAG 1088 -592 I_out
FLAG 1040 -480 0
FLAG -1024 -560 Vc
IOPIN -2304 -1184 In
FLAG -80 -144 q_bar
FLAG -1056 -240 0
FLAG -560 -256 0
FLAG -592 -368 trip
FLAG -480 -176 trip2
FLAG 112 -64 0
FLAG -816 -672 0
FLAG -784 -784 ramp
FLAG -528 -448 0
FLAG 848 -144 0
FLAG 912 -256 Rdiode
FLAG -1056 0 0
FLAG -960 -128 trip2
FLAG -1184 752 0
FLAG -1072 640 On_time_ramp
FLAG -832 832 0
FLAG -720 720 On_time
FLAG 160 -208 FET_R
SYMBOL h -48 -784 R0
SYMATTR Value2 1
SYMATTR InstName H1
SYMATTR Value V1
SYMBOL voltage 368 -592 R0
SYMATTR InstName V1
SYMATTR Value 0
SYMBOL res -224 -800 M90
SYMATTR InstName R5
SYMATTR Value 100
SYMBOL cap -256 -752 M0
SYMATTR InstName C2
SYMATTR Value 100p
SYMBOL srflop -176 -48 M180
SYMATTR InstName A1
SYMBOL voltage -592 -96 M0
SYMATTR Value PULSE(0 1 0 {Trise_fall} {Trise_fall} {Ton_min} {Period})
SYMATTR InstName V2
SYMBOL voltage -752 -96 R0
SYMATTR Value PULSE(0 1 {Ton_max} {Trise_fall} {Trise_fall} {Trise_fall} {Period} )
SYMATTR InstName V3
SYMBOL h 608 -592 R0
SYMATTR Value2 1
SYMATTR InstName H2
SYMATTR Value V5
SYMBOL res 768 -608 R90
SYMATTR InstName R8
SYMATTR Value 100
SYMBOL cap 768 -576 R0
SYMATTR InstName C5
SYMATTR Value 100n
SYMBOL voltage -816 -784 R0
SYMATTR Value PULSE(0 {slopeAmp} 0 {Period - 2*Trise_fall} {Trise_fall} {Trise_fall} {Period})
SYMATTR InstName V4
SYMBOL bv -528 -560 R0
SYMATTR InstName B1
SYMATTR Value V={Ri}*V(I_sense) + V(ramp)
SYMBOL voltage 416 -384 R270
SYMATTR InstName V5
SYMATTR Value 0
SYMBOL res 976 -608 R90
SYMATTR InstName R10
SYMATTR Value 1000
SYMBOL cap 1024 -576 R0
SYMATTR InstName C7
SYMATTR Value 10n
SYMBOL Digital\\or -400 -96 M180
SYMATTR InstName A2
SYMBOL bv -1056 -352 R0
SYMATTR InstName B2
SYMATTR Value V=if( V(sense_slope) > V(Vc), 1, 0)
SYMBOL res -672 -384 R90
SYMATTR InstName R11
SYMATTR Value 100
SYMBOL cap -576 -352 R0
SYMATTR InstName C8
SYMATTR Value 10p
SYMBOL bv 112 -192 R0
SYMATTR InstName B3
SYMATTR Value V=if( V(q) > 0.5, {Rfet}, 1meg )
SYMBOL res 688 -368 R270
SYMATTR InstName R2
SYMATTR Value R=V(Rdiode)
SYMBOL bv 848 -256 R0
SYMATTR InstName B4
SYMATTR Value V= if( V(Sw) > V(p), 10m, 100k )
SYMBOL bv -1056 -128 R0
SYMATTR InstName B5
SYMATTR Value V=  V(trip) - V(set)
SYMBOL voltage -1184 640 R0
SYMATTR Value PULSE(0 {1} 0 {Period - 2*Trise_fall} {Trise_fall} {Trise_fall} {Period})
SYMATTR InstName V6
SYMBOL bv -832 720 R0
SYMATTR InstName B6
SYMATTR Value V=if( V(q) > 0.5, V(On_time_ramp), 0 )
SYMBOL res 352 -240 R0
SYMATTR InstName R1
SYMATTR Value R = V(FET_R)