Add a limit capability to the code model aswitch

Example switch-oscillators_inc.cir showed currents up to 3GA
This commit is contained in:
Holger Vogt 2020-10-03 10:16:15 +02:00
parent 4bcacb310d
commit fdc143ce16
4 changed files with 30 additions and 20 deletions

View File

@ -3,14 +3,13 @@
.control .control
destroy all destroy all
run run
plot I(vmeasure) plot I(vmeasure) ylimit 0 5m
plot V(Osc_out) plot V(Osc_out)
rusage rusage
.endc .endc
.ic v(N017)=0.25 .ic v(N017)=0.25
.tran 50p 40n 50p uic .tran 50p 40n 50p
*.option method=gear maxord=3
VDD VDD2 0 DC 3 VDD VDD2 0 DC 3

View File

@ -8029,7 +8029,7 @@ static struct card *pspice_compat(struct card *oldcard)
tfree(card->line); tfree(card->line);
rep_spar(modpar); rep_spar(modpar);
card->line = tprintf( card->line = tprintf(
".model a%s aswitch(%s %s %s %s log=TRUE)", modname, ".model a%s aswitch(%s %s %s %s log=TRUE limit=TRUE)", modname,
modpar[0], modpar[1], modpar[2], modpar[3]); modpar[0], modpar[1], modpar[2], modpar[3]);
} }
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
@ -8210,7 +8210,7 @@ static struct card *pspice_compat(struct card *oldcard)
tfree(card->line); tfree(card->line);
rep_spar(modpar); rep_spar(modpar);
card->line = tprintf( card->line = tprintf(
".model a%s aswitch(%s %s %s %s log=TRUE)", modname, ".model a%s aswitch(%s %s %s %s log=TRUE limit=TRUE)", modname,
modpar[0], modpar[1], modpar[2], modpar[3]); modpar[0], modpar[1], modpar[2], modpar[3]);
} }
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)

View File

@ -150,7 +150,14 @@ void cm_aswitch(ARGS) /* structure holding parms,
if ( PARAM(log) == MIF_TRUE ) { /* Logarithmic Variation in 'R' */ if ( PARAM(log) == MIF_TRUE ) { /* Logarithmic Variation in 'R' */
intermediate = log(r_off / r_on) / (cntl_on - cntl_off); intermediate = log(r_off / r_on) / (cntl_on - cntl_off);
r = r_on * exp(intermediate * (cntl_on - INPUT(cntl_in))); r = r_on * exp(intermediate * (cntl_on - INPUT(cntl_in)));
if(r<=1.0e-9) r=1.0e-9;/* minimum resistance limiter */
if (PARAM(limit) == MIF_TRUE) {
if(r<r_on) r=r_on;/* minimum resistance limiter */
if(r>r_off) r=r_off;/* maximum resistance limiter */
}
else {
if(r<=1.0e-9) r=1.0e-9;/* minimum resistance limiter */
}
pi_pvout = 1.0 / r; pi_pvout = 1.0 / r;
pi_pcntl = intermediate * INPUT(out) / r; pi_pcntl = intermediate * INPUT(out) / r;
} }
@ -158,14 +165,18 @@ void cm_aswitch(ARGS) /* structure holding parms,
intermediate = (r_on - r_off) / (cntl_on - cntl_off); intermediate = (r_on - r_off) / (cntl_on - cntl_off);
r = INPUT(cntl_in) * intermediate + ((r_off*cntl_on - r = INPUT(cntl_in) * intermediate + ((r_off*cntl_on -
r_on*cntl_off) / (cntl_on - cntl_off)); r_on*cntl_off) / (cntl_on - cntl_off));
if(r<=1.0e-9) r=1.0e-9;/* minimum resistance limiter */
if (PARAM(limit) == MIF_TRUE) {
if(r<r_on) r=r_on;/* minimum resistance limiter */
if(r>r_off) r=r_off;/* maximum resistance limiter */
}
else {
if(r<=1.0e-9) r=1.0e-9;/* minimum resistance limiter */
}
pi_pvout = 1.0 / r; pi_pvout = 1.0 / r;
pi_pcntl = -intermediate * INPUT(out) / (r*r); pi_pcntl = -intermediate * INPUT(out) / (r*r);
} }
/*pi_pvout = 1.0 / r;*/
if(ANALYSIS != MIF_AC) { /* Output DC & Transient Values */ if(ANALYSIS != MIF_AC) { /* Output DC & Transient Values */
OUTPUT(out) = INPUT(out) / r; /* Note that the minus */ OUTPUT(out) = INPUT(out) / r; /* Note that the minus */
PARTIAL(out,out) = pi_pvout; /* Signs are required */ PARTIAL(out,out) = pi_pvout; /* Signs are required */

View File

@ -67,11 +67,11 @@ Null_Allowed: yes yes
PARAMETER_TABLE: PARAMETER_TABLE:
Parameter_Name: r_on Parameter_Name: r_on limit
Description: "on resistance" Description: "on resistance" "set upper and lower limits to resistance"
Data_Type: real Data_Type: real boolean
Default_Value: 1.0 Default_Value: 1.0 false
Limits: - Limits: - -
Vector: no Vector: no no
Vector_Bounds: - Vector_Bounds: - -
Null_Allowed: yes Null_Allowed: yes yes