* SPICE netlist
VDAD+5 DAD_5V 0 5
Ra N002 N003 3.9k
Rb N003 0 1k
Roff N003 DAD_5V 220
VBattery V_battery 0 EXP(3.0 4.2 2m 5m 25m 0.005)
R4 N001 V_schmitt 4k
Q3 N001 N001 DAD_5V 0 PNP
Q4 N004 N001 DAD_5V 0 PNP
R5 N005 DAD_5V 850
R7 0 N005 1k
XU1 N003 V_battery DAD_5V 0 N002 level2 Avol=1Meg GBW=10Meg Slew=10Meg Ilimit=25m Rail=0 Vos=0 En=0 Enk=0 In=0 Ink=0 Rin=500Meg ;pnba In+)In-)V+)V-)OUT
XU2 N005 N002 DAD_5V 0 V_schmitt level2 Avol=1Meg GBW=10Meg Slew=10Meg Ilimit=25m Rail=0 Vos=0 En=0 Enk=0 In=0 Ink=0 Rin=500Meg ;pnba In+)In-)V+)V-)OUT
V1 VRef_4_15 0 4.15
V2 VRef_3_9 0 3.9
R8 N008 0 .1
R9 N007 N006 100k
R10 0 N009 100k
R11 N008 N009 1k
R12 0 N006 1k
XU4 N014 N007 DAD_5V 0 V_termination level2 Avol=1Meg GBW=10Meg Slew=10Meg Ilimit=25m Rail=0 Vos=0 En=0 Enk=0 In=0 Ink=0 Rin=500Meg ;pnba In+)In-)V+)V-)OUT
R13 N014 DAD_5V 4.7k
R14 N014 0 100
XU5 N017 N010 DAD_5V LT1117 ;pnba ADJ)OUT)IN
R1 N010 N017 1k
R2 N017 0 2.2k
Q1 N011 N015 N012 0 NPN
R15 N015 V_schmitt 10k
R6 N016 V_termination 10k
XU3 N009 N006 DAD_5V 0 N007 level2 Avol=1Meg GBW=10Meg Slew=10Meg Ilimit=25m Rail=0 Vos=0 En=0 Enk=0 In=0 Ink=0 Rin=500Meg ;pnba In+)In-)V+)V-)OUT
Q2 N012 N016 N013 0 NPN
V3 N008 0 1m
R3 0 N013 4.7k
D1 N004 V_battery D
D2 N011 V_battery D
R16 N011 N010 10k
.tran 40m

* LTspice schematic (.asc)
Version 4
SHEET 1 3808 1504
WIRE -1248 -720 -1248 -752
WIRE -1056 -720 -1248 -720
WIRE -656 -720 -1056 -720
WIRE 288 -704 192 -704
WIRE 592 -704 288 -704
WIRE 1088 -704 592 -704
WIRE 1392 -704 1088 -704
WIRE -1056 -624 -1056 -720
WIRE -656 -624 -656 -720
WIRE -848 -576 -992 -576
WIRE -720 -576 -848 -576
WIRE 592 -544 592 -704
WIRE 560 -528 448 -528
WIRE 1392 -528 1392 -704
WIRE 848 -512 624 -512
WIRE 1360 -512 848 -512
WIRE -1056 -496 -1056 -528
WIRE -848 -496 -848 -576
WIRE -848 -496 -1056 -496
WIRE 560 -496 448 -496
WIRE 1632 -496 1424 -496
WIRE -656 -480 -656 -528
WIRE -224 -480 -656 -480
WIRE 1360 -480 1264 -480
WIRE -1056 -464 -1056 -496
WIRE -1904 -448 -1904 -512
WIRE -1712 -448 -1712 -512
WIRE -1504 -448 -1504 -560
WIRE 592 -416 592 -480
WIRE 1392 -416 1392 -464
WIRE 1088 -352 1088 -704
WIRE 1136 -352 1088 -352
WIRE 1264 -352 1264 -480
WIRE 1264 -352 1216 -352
WIRE -1904 -336 -1904 -368
WIRE -1712 -336 -1712 -368
WIRE -1712 -336 -1904 -336
WIRE -1504 -336 -1504 -368
WIRE -1504 -336 -1712 -336
WIRE -1056 -336 -1056 -384
WIRE -224 -336 -224 -480
WIRE -224 -320 -224 -336
WIRE 1264 -320 1264 -352
WIRE -1504 -304 -1504 -336
WIRE 288 -240 288 -704
WIRE 304 -240 288 -240
WIRE 448 -240 448 -496
WIRE 448 -240 384 -240
WIRE 528 -240 448 -240
WIRE 848 -240 848 -512
WIRE 848 -240 608 -240
WIRE 1264 -208 1264 -240
WIRE 448 -192 448 -240
WIRE -224 -128 -224 -272
WIRE -224 -128 -736 -128
WIRE 240 -128 -224 -128
WIRE -736 -80 -736 -128
WIRE 240 32 240 -128
WIRE 352 32 240 32
WIRE 448 32 352 32
WIRE 1216 48 1136 48
WIRE 1376 48 1296 48
WIRE 688 208 448 208
WIRE 1136 208 1136 48
WIRE 1136 208 944 208
WIRE 448 240 448 208
WIRE 1264 256 1264 208
WIRE 1136 272 1136 208
WIRE 1232 272 1136 272
WIRE 1696 272 1696 240
WIRE 1376 288 1376 48
WIRE 1376 288 1296 288
WIRE 1664 288 1376 288
WIRE 1232 304 1136 304
WIRE 1904 304 1728 304
WIRE -1248 320 -1248 -720
WIRE -1184 320 -1248 320
WIRE -880 320 -928 320
WIRE -848 320 -880 320
WIRE -736 320 -736 -16
WIRE -736 320 -768 320
WIRE -656 320 -736 320
WIRE -432 320 -560 320
WIRE -112 320 -336 320
WIRE 1664 320 1600 320
WIRE 1696 352 1696 336
WIRE 448 368 448 320
WIRE 544 368 448 368
WIRE 688 368 864 208
WIRE 688 368 544 368
WIRE 864 368 688 208
WIRE 1136 368 1136 304
WIRE 1136 368 944 368
WIRE 1264 384 1264 320
WIRE 1456 384 1424 384
WIRE 1600 384 1600 320
WIRE 1600 384 1536 384
WIRE 352 400 352 32
WIRE 384 400 352 400
WIRE 448 400 384 400
WIRE 1600 416 1600 384
WIRE 448 432 448 400
WIRE -880 496 -880 320
WIRE -608 496 -608 384
WIRE -384 496 -384 384
WIRE 1136 512 1136 368
WIRE 1600 544 1600 496
WIRE 448 560 448 512
WIRE -1056 608 -1056 416
WIRE -880 608 -880 576
WIRE -880 608 -1056 608
WIRE -608 624 -608 576
WIRE -384 624 -384 576
WIRE 1136 624 1136 592
WIRE -880 640 -880 608
WIRE -880 752 -880 720
FLAG -1504 -304 0
FLAG 592 -416 0
FLAG 448 -112 0
FLAG -1504 -560 DAD_5V
FLAG -1248 -752 DAD_5V
FLAG -1056 -336 V_schmitt
FLAG 448 -528 V_battery
FLAG 192 -704 DAD_5V
FLAG 1632 -496 V_schmitt
FLAG 1392 -416 0
FLAG 1264 -208 0
FLAG -608 624 V_schmitt
FLAG -1712 -512 VRef_4_15
FLAG -1904 -512 VRef_3_9
FLAG 1136 624 0
FLAG 1424 384 DAD_5V
FLAG 1600 544 0
FLAG 1696 352 0
FLAG 1696 240 DAD_5V
FLAG -880 752 0
FLAG -384 624 V_termination
FLAG 448 560 0
FLAG 1264 384 0
FLAG 1264 208 DAD_5V
FLAG 384 400 V_battery
FLAG 448 128 0
FLAG 544 368 0
FLAG 1904 304 V_termination
FLAG -32 320 0
SYMBOL voltage -1504 -464 R0
SYMATTR InstName DAD+5
SYMATTR Value 5
SYMBOL res 624 -256 R90
SYMATTR InstName Ra
SYMATTR Value 3.9k
SYMBOL res 432 -208 R0
SYMATTR InstName Rb
SYMATTR Value 1k
SYMBOL res 400 -256 R90
SYMATTR InstName Roff
SYMATTR Value 220
SYMBOL voltage 448 416 R0
SYMATTR InstName Battery
SYMATTR Value EXP(3.0 4.2 2m 5m 25m 0.005)
SYMBOL res -1072 -480 R0
SYMATTR InstName R4
SYMATTR Value 4k
SYMBOL pnp -992 -528 R180
SYMATTR InstName Q3
SYMBOL pnp -720 -528 M180
SYMATTR InstName Q4
SYMBOL res 1232 -368 R90
SYMATTR InstName R5
SYMATTR Value 850
SYMBOL res 1248 -224 M180
SYMATTR InstName R7
SYMATTR Value 1k
SYMBOL OpAmps\\UniversalOpamp2 592 -512 R0
SYMATTR InstName U1
SYMBOL OpAmps\\UniversalOpamp2 1392 -496 R0
SYMATTR InstName U2
SYMBOL voltage -1712 -464 R0
SYMATTR InstName V1
SYMATTR Value 4.15
SYMBOL voltage -1904 -464 R0
SYMATTR InstName V2
SYMATTR Value 3.9
SYMBOL res 432 224 R0
SYMATTR InstName R8
SYMATTR Value .1
SYMBOL res 1312 32 R90
SYMATTR InstName R9
SYMATTR Value 100k
SYMBOL res 1152 608 R180
SYMATTR InstName R10
SYMATTR Value 100k
SYMBOL res 848 384 R270
SYMATTR InstName R11
SYMATTR Value 1k
SYMBOL res 848 224 R270
SYMATTR InstName R12
SYMATTR Value 1k
SYMBOL OpAmps\\UniversalOpamp2 1696 304 R0
SYMATTR InstName U4
SYMBOL res 1552 368 R90
SYMATTR InstName R13
SYMATTR Value 4.7k
SYMBOL res 1584 400 R0
SYMATTR InstName R14
SYMATTR Value 100
SYMBOL PowerProducts\\LT1117 -1056 320 R0
SYMATTR InstName U5
SYMBOL res -896 480 R0
SYMATTR InstName R1
SYMATTR Value 1k
SYMBOL res -896 624 R0
SYMATTR InstName R2
SYMATTR Value 2.2k
SYMBOL npn -656 384 R270
SYMATTR InstName Q1
SYMBOL res -624 480 R0
SYMATTR InstName R15
SYMATTR Value 10k
SYMBOL res -400 480 R0
SYMATTR InstName R6
SYMATTR Value 10k
SYMBOL OpAmps\\UniversalOpamp2 1264 288 R0
SYMATTR InstName U3
SYMBOL npn -432 384 R270
SYMATTR InstName Q2
SYMBOL voltage 448 224 R180
SYMATTR InstName V3
SYMATTR Value 1m
SYMBOL res -16 304 R90
SYMATTR InstName R3
SYMATTR Value 4.7k
SYMBOL diode -240 -336 R0
SYMATTR InstName D1
SYMBOL diode -720 -16 R180
SYMATTR InstName D2
SYMBOL res -752 304 R90
SYMATTR InstName R16
SYMATTR Value 10k