.func CHRG_DELAY(rdacFLX,rdacCHRG) FLX_PW3(rdacFLX)+CHRG_PW(rdacCHRG)
.func CHRG_PW1(rdacCHRG) (2e-4*rdacCHRG*rdacCHRG-0.0507*rdacCHRG+6.5198)*pwr(1.025,rdacCHRG)*1e-9
.func CHRG_PW2(rdacCHRG) (1.4e-5*rdacCHRG*rdacCHRG-0.0073*rdacCHRG+4.1)*pwr(1.025,rdacCHRG)*1e-9
.func CHRG_PW3(rdacCHRG) rdacCHRG<132?CHRG_PW1(rdacCHRG)/ChrgAdj1()/ChrgAdj2():CHRG_PW2(rdacCHRG)/ChrgAdj1()/ChrgAdj2()
.func ChrgAdj1() ((ChrgVref==0.625) && (Chrg2x==1))?(3.95977e-6*rdacCHRG*rdacCHRG-0.00152089*rdacCHRG+0.64):1
.func ChrgAdj2() ((ChrgVref==1.25) && (Chrg2x==2))?(-1.1568e-5*rdacCHRG*rdacCHRG+0.00523951*rdacCHRG+1.40102):1
.func FIRE_PW1(rdacFire) (3.83e-05*rdacFire*rdacFire-0.00925*rdacFire+0.767)*pwr(1.025,rdacFire)*1e-9
.func FIRE_PW2(rdacFire) (0.0015*(rdacFire-115)+0.203)*pwr(1.025,rdacFire)*1e-9
.func FIRE_PW3(rdacFire) rdacFire<115?FIRE_PW1(rdacFire)/FireAdj1()/FireAdj2(): FIRE_PW2(rdacFire)/FireAdj1()/FireAdj2()
.func FireAdj1() ((FireVref==0.625) && (Fire2x==1))?(3.95977e-6*rdacFire*rdacFire-0.00152089*rdacFire+0.64):1
.func FireAdj2() ((FireVref==1.25) && (Fire2x==2))?(-1.1568e-5*rdacFire*rdacFire+0.00523951*rdacFire+1.40102):1
.func FireRef(x) (x==1.25)?1:(4e-6*rdacFire*rdacFire-0.0016*rdacFire+0.64)
.func FLX_PW1(code) (2e-5*code*code-0.0024*code+2.9456)*pwr(1.025,code)*1e-9/Flux2x
.func FLX_PW2(code) (-6.6e-6*code*code+0.0028*code+2.8729)*pwr(1.025,code)*1e-9/Flux2x
.func FLX_PW3(code)  code<51?FLX_PW1(code)/VinAdjust():FLX_PW2(code)/VinAdjust()
.func VinRef(x) (x==5)?5:(x==12)?12:(x==1.25)?Vinput:2*Vinput
.func VinAdjust() Vinput/VinRef(FluxVinRef)
.meas Fluxmark1 find time when V(fluxPulse)=2.5
.meas Fluxmark2 find time when V(fluxPulse)=2.5 cross=2
.meas Flux_pw param Fluxmark2-Fluxmark1
.meas Firemark1 find time when V(firePulse)=2.5
.meas Firemark2 find time when V(firePulse)=2.5 cross=2
.meas Fire_pw param Firemark2-Firemark1
.meas CharDelay Firemark1-Fluxmark2
