; Qspice Worst Case w/ tempco ; Modification of example at www.analog.com ; "LTspice: Worst-Case Circuit Analysis with Minimal Simulations Runs" ; https://www.analog.com/en/resources/technical-articles/ltspice-worst-case-circuit-analysis-with-minimal-simulations-runs.html ; ; This modification adds parameter tempco and provides for asymetrical tolerance and tempco ; ; Kenneth Galer && John Glaberson ; 11May24 release ; ; USAGE: ; On Schematic ********************************************************** ; ; Include this file located in same directory as the .qsch file ; inc wct.sp ; ; Define the Min and Max temp range in DegC as below on schematic ; .param MinTemp = -40 ; DegC ; .param MaxTemp = 125 ; DegC ; .param Tnom = 25 ; DegC ; Ambient is assumed the same for all componenets ; Note: If multiple components have a tempco defined, it is faster to sim the effects of ; tolerance only by setting all three temps to the same value. ; ; Define analysis as on schematic ; .op .ac etc... ; ; Define num_of_indexed_func_calls on schematic ; Note: Be sure that this is corrected as you change the circuit. When it's wrong ; the results wil be wrong. Each wct() function on the schematic must have a ; unique index starting at 0 and continuous. Order does not matter. ; .param num_of_indexed_func_calls = 3 ; Enter Manually ; ;************************************************************************ ; ; Define each component parameter in question with a wct() func call ; Multiple parameters per component are allowed ; wct(10K, 1, 1, 150, 150, 0) 10K +/-1%, +/-150ppm index=0 ; wct(1K, 0, 0, 0, 0, 1) 1K perfect index=1 ; wct(1K, 0, 0, 150, 0, 4) 1K +/-0% +150ppm -0ppm index=4 ; wct(1000uf, 50, 20, 0, 0, 0) 1000uF +50% -20% 0ppm index=0 ; wct(0, 10m, 10m, 50, 50, 0) Limits mode +10m -10m +/-50ppm ; wct(0, 100uh, 350uh, 0, 0, 0) Value defined using limits and w/o a tempco ; ; Tolerance Mode: ; wct(nom, tol_pos, tol_neg, tc_pos, tc_neg, index) ; where: ; nom = Nominal Value ; tol_pos = Positive tolorance in % ; tol_neg = Negative tolorance in % (negative sign is optional) ; tc_pos = Positive Tempco in ppm ; tc_neg = Negative Tempco in ppm (negative sign is optional) ; Function index - integer index, for each wct() call, starts at 0, must be unique and continuous ; ; By using 0 as the nominal, Limits Mode is invoked. The second argument becomes Most_pos_val and ; the third argument becomes Most_neg_val. Nominal is calculated as the limits average ; Tempco is the same as above. ; Ex: wct(0, 10mv, 10mv, 150, 0, 0) Limits mode +/-10m +150ppm ; ; Limits mode: ; wct(nom, Most_pos_val, Most_neg_val, tc_pos, tc_neg, index) ; where: ; nom = Nominal Value set to 0 (Required) ; Max_pos_val = Positive max limit ; Max_neg_val = Negative max limit (negative sign is optional) ; tc_pos = Positive Tempco in ppm ; tc_neg = Negative Tempco in ppm (negative sign is optional) ; Function index - integer index, for each wct() call, starts at 0, must be unique and continuous ;************************************************************************ .param dT_hot = MaxTemp - Tnom .param dT_cold = Tnom - MinTemp .param numruns = 2**num_of_indexed_func_calls .step param run 0 numruns 1 .func wct(nom, tol_pos, tol_neg, tc_pos, tc_neg, index) + if( run == numruns, + if(nom == 0, find_avg_nom(nom), nom), ; if last run and nom == 0, use calculated nom + if( nom == 0, ; else all other runs + if( binary(run, index), ; Limits mode + tol_pos * (1 + tc_err_high(tc_pos)), + tol_neg * (1 - tc_err_low(tc_neg)) + ), + if( binary(run, index), ; Tolerance Mode + nom * (1 + per2err(tol_pos)) * (1 + tc_err_high(tc_pos)), + nom * (1 - per2err(tol_neg)) * (1 - tc_err_low(tc_neg)) + ) + ) + ) .func find_avg_nom(nom) tol_neg+((tol_pos-tol_neg)/2) .func tc_err_high(tco) dT_hot * ppm2err(tco) .func tc_err_low(tco) dT_cold * ppm2err(tco) .func per2err(tol) abs(tol)/1e2 .func ppm2err(tc) abs(tc)/1e6 ; Returns a 0 or 1 integer, 0 = low mode, 1 = high mode .func binary(run, index) floor(run/(2**index)) - 2*floor(run/(2**(index+1)))