* Z:\home\khalils\Downloads\files\data\raw_asc\3efa3948e235_ConstPowerLoads.asc
* Generated by LTspice 26.0.1 for Windows.
* Constant Power Loads with linear starting range and current limit\n(some concepts from yahoo LTSPICE group, 2004)
* Va Vb
* Imax ->
* 0V --- voltage Vx -->
* 0A->
* Alternative Syntax using R
;-as cpwr1, alt. formula similar to analogspiceman/yahoo, for positive Vx
;-as cpwr2,alt. formula, for pos. & neg. Vx
;-only values Vx>0 give current >0
;-as cpwr1 but pos. and neg. Vx
B3 x 0 I=cpwr3(pwr,Imax,Va,Vb,V(x))
B1 x 0 I=cpwr1(pwr,Imax,Va,Vb,V(x))
B2 x 0 I=cpwr2(pwr,Imax,Va,Vb,V(x))
V1 x 0 0
R2 x 0 R=V(x)/cpwr2(pwr,Imax,Va,Vb,V(x))
B4 x 0 I=cpwr4(pwr,Imax,Va,Vb,V(x))
.params: pwr=10W Imax=5A Vb=pwr/Imax ;Vb always calculated!
.params: Va=Vb/5 ;Va is arbitrary, but 0 < Va <= Vb !
.dc V1 -5 5 .01
.func cpwr3(pwr,Imax,Va,Vb,Vx) {limit(if(Vx>Vb,pwr/Vx,Imax*Vx/Va),Imax,0)}
.func cpwr4(pwr,Imax,Va,Vb,Vx) {limit(if(ABS(Vx)>Vb,pwr/ABS(Vx),Imax*ABS(Vx/Va)),Imax,0)*SGN(Vx)}
.func cpwr1(pwr,Imax,Va,Vb,Vx) {if(Vx>0,if(Vx<Va,Vx/Va*Imax,if(Vx<Vb,Imax,pwr/Vx)),0)}
.func cpwr2(pwr,Imax,Va,Vb,Vx) { cpwr1(pwr,Imax,Va,Vb,ABS(Vx))*SGN(Vx) }
.backanno
.end

* LTspice schematic (.asc):
Version 4
SHEET 1 1172 680
WIRE -128 176 -128 112
WIRE 16 112 -128 112
WIRE 16 240 16 112
WIRE 16 368 16 240
WIRE 16 496 16 368
WIRE 48 112 16 112
WIRE 96 112 48 112
WIRE 96 240 16 240
WIRE 96 368 16 368
WIRE 96 496 16 496
WIRE 464 240 96 240
LINE Normal 672 288 784 288
LINE Normal 624 352 672 288
ARC Normal 768 352 1072 112 779 310 915 362
SYMBOL bi 96 112 R0
SYMATTR InstName B1
SYMATTR Value I=cpwr1(pwr,Imax,Va,Vb,V(x))
SYMBOL bi 96 368 R0
WINDOW 0 30 7 Left 0
SYMATTR InstName B3
SYMATTR Value I=cpwr3(pwr,Imax,Va,Vb,V(x))
SYMBOL bi 96 496 R0
SYMATTR InstName B4
SYMATTR Value I=cpwr4(pwr,Imax,Va,Vb,V(x))
SYMBOL res 448 224 R0
WINDOW 3 24 2 Left 0
SYMATTR Value R=V(x)/cpwr2(pwr,Imax,Va,Vb,V(x))
SYMATTR InstName R2
SYMBOL voltage -128 160 R0
WINDOW 123 0 0 Left 0
WINDOW 39 24 132 Left 0
SYMATTR InstName V1
SYMATTR Value 0
SYMBOL bi 96 240 R0
WINDOW 0 37 20 Left 0
SYMATTR InstName B2
SYMATTR Value I=cpwr2(pwr,Imax,Va,Vb,V(x))
FLAG -128 256 0
FLAG 96 192 0
FLAG 48 112 x
FLAG 96 320 0
FLAG 96 448 0
FLAG 96 576 0
FLAG 464 320 0
TEXT -136 -256 Left 0 !.params: pwr=10W Imax=5A Vb=pwr/Imax ;Vb always calculated!\n.params: Va=Vb/5     ;Va is arbitrary, but 0 < Va <= Vb  !
TEXT -154 330 Left 0 !.dc V1 -5 5 .01
TEXT -136 -56 Left 0 !;-as cpwr1, alt. formula similar to analogspiceman/yahoo, for positive Vx\n.func cpwr3(pwr,Imax,Va,Vb,Vx) {limit(if(Vx>Vb,pwr/Vx,Imax*Vx/Va),Imax,0)}
TEXT -136 24 Left 0 !;-as cpwr2,alt. formula, for pos. & neg. Vx\n.func cpwr4(pwr,Imax,Va,Vb,Vx) {limit(if(ABS(Vx)>Vb,pwr/ABS(Vx),Imax*ABS(Vx/Va)),Imax,0)*SGN(Vx)}
TEXT -136 -192 Left 0 !;-only values Vx>0 give current >0\n.func cpwr1(pwr,Imax,Va,Vb,Vx) {if(Vx>0,if(Vx<Va,Vx/Va*Imax,if(Vx<Vb,Imax,pwr/Vx)),0)}
TEXT -136 -128 Left 0 !;-as cpwr1 but pos. and neg. Vx\n.func cpwr2(pwr,Imax,Va,Vb,Vx) { cpwr1(pwr,Imax,Va,Vb,ABS(Vx))*SGN(Vx) }
TEXT -136 -312 Left 0 ;Constant Power Loads with linear starting range and current limit\n(some concepts from yahoo LTSPICE group, 2004)
TEXT 664 264 Left 0 ;Va           Vb
TEXT 568 288 Left 0 ;Imax ->
TEXT 608 368 Left 0 ;0V  --- voltage Vx  -->
TEXT 568 352 Left 0 ;0A->
TEXT 488 192 Left 0 ;Alternative Syntax using R