blob: d155c877878a398a6341a85cd42bd57db282a098 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
*ng_script
* Perform Monte Carlo simulation in ngspice
* script for use with 25 stage Ring-Osc. BSIM3
* circuit is in MC_2_circ.sp
* edit 'setcs sourcepath' for your path to circuit file
* start script by 'ngspice -o MC_2_control.log MC_2_control.sp'
*
.control
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
setcs sourcepath = ( D:\Spice_general\ngspice\examples\Monte_Carlo )
* create file for frequency information
echo Monte Carlo, frequency of R.O. > MC_frequ.log
* run the simulation loop
dowhile run <= mc_runs
* without the reset switch there is some strange drift
* towards lower and lower frequencies
set run = $&run $ create a variable from the vector
setseed $run $ set the rnd seed value to the loop index
if run = 1
source MC_2_circ.sp $ load the circuit once from file, including model data
else
mc_source $ re-load the circuit from internal storage
end
save buf $ we just need output vector buf, save memory by more than 10x
tran 15p 200n 0
write mc_ring{$run}.out buf $ write each sim output to its own rawfile
linearize buf $ lienarize buf to allow fft
fft buf $ run fft on vector buf
let buf2=db(mag(buf))
* find the frequency where buf has its maximum of the fft signal
meas sp fft_max MAX_AT buf2 from=0.1G to=0.7G
print fft_max >> MC_frequ.log $ print frequency to file
destroy all $ delete all output vectors
remcirc $ delete circuit
let run = run + 1 $ increase loop counter
end
quit
.endc
.end
|