LTSpice XVII sweeping or stepping subckt parameters - Page 1
Forum section: electronics / projects

author: chris_leyson
author_rank: Super Contributor
timestamp: September 04, 2020, 09:04:05 pm
content: I'm trying to do monte carlo and/or worst case analysis for a digital transistor and I would like to step the resistor values over their tolerance range but after googling for a day I've got nowhere. Last resort would be removing the resistors from the sub circuit and just save the transistor model into standard.bjt and then tweak external resistors. Do I need to edit the model and add a PARAM variable to the following, R1 2 Base Rb 10k, R2 Base 3 Re 10k ? DTC114EE sub circuit, courtesy of ROHM below.Code:* DTC114EE DIGITAL NPN BJT model* Date: 2007/01/11* BJT with resistors*****************C B E.SUBCKT DTC114EE 1 2 3R1 2 Base Rb 10kR2 Base 3 Re 10kQ1 1 Base 3 QDTC1.MODEL Rb RES+ R=1.MODEL Re RES+ R=1.MODEL QDTC1 NPN+ IS=20.000E-15+ BF=198.80+ VAF=15+ IKF=.28787+ ISE=20.001E-15+ NE=1.6289+ BR=8.4556+ VAR=100+ IKR=.2645+ ISC=8.0686E-12+ NC=2.3678+ NK=.75224+ RE=.2+ RB=10.670+ RC=1.1274+ CJE=11.342E-12+ MJE=.38289+ CJC=4.0230E-12+ MJC=.34629+ TF=500.00E-12+ XTF=580.91+ VTF=195.13+ ITF=19.351+ TR=200.00E-9+ XTB=1.5000.ENDS DTC114EE

author: Ian.M
author_rank: Super Contributor
timestamp: September 04, 2020, 09:55:08 pm
content: That's what you *should* do if you want it clean. See LTspice help file: '.PARAM -- User-Defined Parameters' for an example of passing parameters to a subcircuit. You'd probably also want to parameterize the gain.Its already been half-way set up for it with:Code:.MODEL Rb RES+ R=1.MODEL Re RES+ R=1The '1' in those two model statements is a unity multiplier for the values in the R1 and R2 component lines respectively.Try:Code:* DTC114EE DIGITAL NPN BJT model* Date: 2007/01/11 mod. 2020/09/04 Ian.M* BJT with resistors, parameterized for Monte Carlo*****************C B E.SUBCKT DTC114EE 1 2 3.params Krb=1 Kre=1 Kbeta=1 ; default to unit multiplierR1 2 Base Rb 10kR2 Base 3 Re 10kQ1 1 Base 3 QDTC1.MODEL Rb RES+ R={Krb}.MODEL Re RES+ R={Kre}.MODEL QDTC1 NPN+ IS=20.000E-15+ BF={198.80*Kbeta}+ VAF=15+ IKF=.28787+ ISE=20.001E-15+ NE=1.6289+ BR=8.4556+ VAR=100+ IKR=.2645+ ISC=8.0686E-12+ NC=2.3678+ NK=.75224+ RE=.2+ RB=10.670+ RC=1.1274+ CJE=11.342E-12+ MJE=.38289+ CJC=4.0230E-12+ MJC=.34629+ TF=500.00E-12+ XTF=580.91+ VTF=195.13+ ITF=19.351+ TR=200.00E-9+ XTB=1.5000.ENDS DTC114EEThen you can pass in per-instance parameters to your DTC114EE model, set in the generic Component Attribute Editor:e.g.Code:Krb=1.1 Kre=0.9 Kbeta=0.8which gives you a DTC114EE with its series base resistor 10% high, its shunt base resistor 10% low and 20% below nominal gain, or for your specific application you'd need to use multipliers derived from your Monte Carlo or Worst Case functions.

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: September 04, 2020, 10:12:50 pm
content: Hi,Here is one solution:and the results:I have attached the LTspice modelRegards,Jay_Diddy_Bparameter sweep digital transistor.asc(1.79 kB - downloaded 87 times.)

author: Ian.M
author_rank: Super Contributor
timestamp: September 04, 2020, 10:25:14 pm
content: Yes, but my way you don't need to know at the schematic level that the internal R1 (Rb)and R2 (Rbe) are meant to be 10K, just use:Code:Krb=mc(1,0.1) Kre=mc(1,0.1)

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: September 04, 2020, 10:33:24 pm
content: Hi,@Ian.M+1Both will get the job done for the OP.I have expanded my version to include BF variation:I would encourage you to but the model on the schematic, so that it is portable.Jay_Diddy_Bparameter sweep digital transistor with BF.asc(2.09 kB - downloaded 97 times.)

author: chris_leyson
author_rank: Super Contributor
timestamp: September 05, 2020, 01:41:39 am
content: Thanks Ian.M and Jay_Diddy_BI'm kicking myself for missing that. R1 and R2 variation could be 30% and R2/R1 ratio has 20% limit. I had a sneaky feeling that a model edit might be in order to pass parameters. Thanks again guys.

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: September 05, 2020, 02:54:03 am
content: Chris,You need to do something like this:.param para_R1={mc(10,0.3)}R1 = 10K 30%and.param para_R2={mc(1.0417*para_R1,0.2)}1.0417 is the average of 1/0.8 and 1/1.2This randomizes R1 and the sets R2 with a random ratio up to 20%Jay_Diddy_B

author: chris_leyson
author_rank: Super Contributor
timestamp: September 05, 2020, 10:15:58 am
content: Thanks J_Diddy_B, I've been doing some Monte Carlo on a few circuit blocks just to make sure the designs are 100% guaranteed to work, it's important if you're manufacturing by the hundreds of thousands. The company use a fair amount of digital transistors as well, either for drivers or level shifters, so I thought it might be wise to look at those as well. Thanks, that has helped my understanding of LTSpice and params. I think Bob Pease absolutely hated SPICE but I think SPICE3 is a great tool for sanity checking designs.