Browse Source

example update: sim_status, mc_source and others

pre-master-46
Holger Vogt 8 years ago
parent
commit
73f8925c1e
  1. 12
      examples/Monte_Carlo/MC_2_control.sp
  2. 18
      examples/Monte_Carlo/MC_ring.sp

12
examples/Monte_Carlo/MC_2_control.sp

@ -1,3 +1,4 @@
*ng_script
* Perform Monte Carlo simulation in ngspice * Perform Monte Carlo simulation in ngspice
* script for use with 25 stage Ring-Osc. BSIM3 * script for use with 25 stage Ring-Osc. BSIM3
* circuit is in MC_2_circ.sp * circuit is in MC_2_circ.sp
@ -5,9 +6,8 @@
* start script by 'ngspice -o MC_2_control.log MC_2_control.sp' * start script by 'ngspice -o MC_2_control.log MC_2_control.sp'
* *
.control .control
save buf $ we just need output vector buf, save memory by more than 10x
let mc_runs = 10 $ number of runs for monte carlo
let run = 1 $ number of the actual run
let mc_runs = 10 $ number of runs for monte carlo
let run = 1 $ number of the actual run
* Where to find the circuit netlist file MC_2_circ.sp * Where to find the circuit netlist file MC_2_circ.sp
set sourcepath = ( D:\Spice_general\ngspice\examples\Monte_Carlo ) set sourcepath = ( D:\Spice_general\ngspice\examples\Monte_Carlo )
@ -19,14 +19,14 @@
dowhile run <= mc_runs dowhile run <= mc_runs
* without the reset switch there is some strange drift * without the reset switch there is some strange drift
* towards lower and lower frequencies * towards lower and lower frequencies
reset
set run ="$&run" $ create a variable from the vector
set rndseed = $run $ set the rnd seed value to the loop index
set run = $&run $ create a variable from the vector
setseed $run $ set the rnd seed value to the loop index
if run = 1 if run = 1
source MC_2_circ.sp $ load the circuit once from file, including model data source MC_2_circ.sp $ load the circuit once from file, including model data
else else
mc_source $ re-load the circuit from internal storage mc_source $ re-load the circuit from internal storage
end end
save buf $ we just need output vector buf, save memory by more than 10x
tran 15p 200n 0 tran 15p 200n 0
write mc_ring{$run}.out buf $ write each sim output to its own rawfile write mc_ring{$run}.out buf $ write each sim output to its own rawfile
linearize buf $ lienarize buf to allow fft linearize buf $ lienarize buf to allow fft

18
examples/Monte_Carlo/MC_ring.sp

@ -1,5 +1,9 @@
Perform Monte Carlo simulation in ngspice Perform Monte Carlo simulation in ngspice
* 25 stage Ring-Osc. BSIM3
* 25 stage Ring-Osc. BSIM3 with statistical variation of various model parameters
* cd into ngspice/examples/Monte_Carlo
* start in interactive mode 'ngspice MC_ring.sp' with several plots for output
* or start in batch mode, controlled by .control section (Control mode)
* with 'ngspice -b -r MC_ring.raw -o MC_ring.log MC_ring.sp'.
vin in out dc 0.5 pulse 0.5 0 0.1n 5n 1 1 1 vin in out dc 0.5 pulse 0.5 0 0.1n 5n 1 1 1
vdd dd 0 dc 3.3 vdd dd 0 dc 3.3
@ -151,6 +155,15 @@ cout buf ss 0.2pF
reset reset
end end
***** plotting ********************************************************** ***** plotting **********************************************************
if $?batchmode
echo
echo Plotting not available in batch mode
echo Write linearized vout0 to vout{$mc_runs} to rawfile $rawfile
echo
write $rawfile {$plot_out}.allv
rusage
quit
else
setplot $plot_out setplot $plot_out
plot vout0 ylabel 'RO output, original parameters' $ just plot the tran output with nominal parameters plot vout0 ylabel 'RO output, original parameters' $ just plot the tran output with nominal parameters
setplot $plot_fft setplot $plot_fft
@ -171,7 +184,7 @@ cout buf ss 0.2pF
* put data into the correct bins * put data into the correct bins
let run = 0 let run = 0
dowhile run < mc_runs dowhile run < mc_runs
set run = "$&run" $ create a variable from the vector
set run = $&run $ create a variable from the vector
let val = maxffts[{$run}] let val = maxffts[{$run}]
let part = 0 let part = 0
* Check if val fits into a bin. If yes, raise bin by 1 * Check if val fits into a bin. If yes, raise bin by 1
@ -199,6 +212,7 @@ cout buf ss 0.2pF
let diff40 = (vecmax(halfffts) - vecmin(halfffts))*1e-6 let diff40 = (vecmax(halfffts) - vecmin(halfffts))*1e-6
echo echo
echo Max. jitter is "$&diff40" MHz echo Max. jitter is "$&diff40" MHz
end
rusage rusage
.endc .endc
******************************************************************************** ********************************************************************************

Loading…
Cancel
Save