OCEAN Script – 2 : CMOS Inverter


This post describes how to write a ocean script to run transient analysis and save simulation results to a data file. In this example script, transient analysis is performed on a CMOS inverter. The capacitive load on the inverter is swept over a range and inverter characteristics like rise time, fall time, and propagation delay are extracted using inbuilt functions.

Even though parametric sweep is the good option for sweeping load on the inverter, foreach command is used to just demonstrate it’s usage.

To run ocean script you need the following files

  • Netlist file that describes of your design.
    OCEAN look for netlist, netlistHeader and netlistFooter files in the same directory
  • Model files for the elements that you used in your design



Also you should specify to simulator the path for the following directories

  • Results directory path where your simulation results are to be stored
  • File path where your simulation data is to be saved

In this example script, we can break-up the code for command settings into COMMON SETTINGS and DESIGN SPECIFIC SETTINGS.


In DESIGN SPECIFIC SETTINGS-1, we set file pointer to data file and set the path for results directory. By this approach we can do all the necessary modifications to command settings at one place.

;; ----- DESIGN SPECIFIC SETTINGS - 1  ----- 
fileptr = outfile( "inv_tran.dat")     ;; DEFINE OUTPUT DATA FILE
sprintf(myresdir "./TranResults")      ;; SET RESULTS DIRECTORY

In COMMON SETTINGS section the command settings remain same for most of the scripts. You can reuse same piece of code.

;; ----- COMMON SETTINGS ----- 
ocnWaveformTool( 'wavescan )           ;; SELECT WAVEFORM TOOL
simulator( 'spectre )                  ;; SET SIMULATOR
design( "netlist" )                    ;; SPECIFY DESIGN
resultsDir( myresdir )                 ;; SET RESULTS DIRECTORY 
modelFile(                             ;; SET MODEL FILES PATH
    '("/cad/library/xxmc/Models/Spectre/model_name.lib.scs" "tt")  )
temp( 70 )                             ;; SET TEMPERATURE

design("netlist") The netlist file for your design. If you use same name for all your netlists you no need to modify your code here.
resultsDir( myresdir ) Get the results directory info from DESIGN SPECIFIC SETTINGS-1
Note: If we want to do corner analysis we have to modify modelFile() command

The DESIGN SPECIFIC SETTINGS-2 code snippet vary a lot from design to design. The code is self-explanatory and outline for the code is given below

  • To sweep Cload, list() is used here
  • Header information is printed into output data file through fprintf command. Header information quite useful for future reference of data
  • SKILL construct foreach is used to repeat the analysis for each Cload value
  • In each iteration after ‘tran’ analysis, select the results and use data access commands to plot waveforms and process post-simulation data. You can save the data to output data file using either fprintf() or ocnPrint()
  • Then close the file using close() command
;; ----- DESIGN SPECIFIC SETTINGS - 2 ------
;; DEFINE YOUR DESIGN VARIABLES HERE
desVar( "vth" 0.6 )
CloadList = list( 5f 10f 20f 50f ) 
 
;; WRITE HEADER INFO TO OUTPUT DATA FILE
fprintf( fileptr "Cload\t\t tr\t\t tf\t\t tpdlh\t\t tpdhl\t\t tpd\n")
 
 
foreach( (capval) Cloadlist            ;; SWEEP CAP LOAD ON INVERTER
desVar( "Cload" capval  )
 
;; RUN COMMANDS TO DO TRANSIENT ANALYSIS
analysis('tran ?start 0 ?stop 2n  ?step 10p  ?strobeperiod 1p ?errpreset "conservative"  ?sort "name"  )
saveOption('save "all" )
run()
 
; DATA ACCESS COMMAND TO PROCESS POST-SIMULATION DATA
selectResults('tran)
plot( v("vout") )
tr=riseTime( v("vout") 1n t 2n t 10 90 )
tf=riseTime( v("vout") 1n t 2n t 90 10 )
tpdlh=delay( v("vin") vth 1 'falling v("vout") vth 1 'rising )
tpdhl=delay( v("vin") vth 1 'rising v("vout") vth 1 'falling )
fprintf( fileptr "%e\t%e\t%e\t%e\t%e\t%e\n", capval , tr, tf, tpdlh, tpdhl, (tpdlh+tpdhl)/2) 
)                                ; END OF foreach
close(fileptr)
plot( v("vin") )

SAMPLE OCEAN SCRIPT

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
;; OCEAN example to simulate a CMOS Inverter                          ;;
;; File name: inv_tran.ocn                                            ;;
;; Find rise time, fall time and propagation delay of a cmos inverter ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    
 
 
;; ----- DESIGN SPECIFIC SETTINGS - 1  ----- 
fileptr = outfile( "inv_tran.dat")     ;; DEFINE OUTPUT DATA FILE
sprintf(myresdir "./TranResults")      ;; SET RESULTS DIRECTORY 
 
 
;; ----- COMMON SETTINGS ----- 
ocnWaveformTool( 'wavescan )           ;; SELECT WAVEFORM TOOL
simulator( 'spectre )                  ;; SET SIMULATOR
design( "netlist" )                    ;; SPECIFY DESIGN
resultsDir( myresdir )                 ;; SET RESULTS DIRECTORY 
modelFile( 
    '("/cad/library/xxmc/Models/Spectre/model_name.lib.scs" "tt") )
temp( 70 )                             ;; SET TEMPERATURE 
 
;; ----- DESIGN SPECIFIC SETTINGS - 2 ------
;; DEFINE YOUR DESIGN VARIABLES HERE
desVar( "vthreshold" 0.6 )
CloadList = list( 5f 10f 20f 50f ) 
 
;; WRITE HEADER INFO TO OUTPUT FILE
fprintf( fileptr "Cload\t\t tr\t\t tf\t\t tpdlh\t\t tpdhl\t\t tpd\n")
 
 
foreach( (capval) Cloadlist            ;; SWEEP CAP LOAD ON INVERTER
desVar( "Cload" capval  )
 
;; RUN COMMANDS TO DO TRANSIENT ANALYSIS
analysis('tran ?start 0 ?stop 2n  ?step 10p  ?strobeperiod 1p ?errpreset "conservative"  ?sort "name"  )
saveOption('save "all" )
run()
 
; DATA ACCESS COMMAND TO PROCESS POST-SIMULATION DATA
selectResults('tran)
plot( v("vout") )
tr=riseTime( v("vout") 1n t 2n t 10 90 )
tf=riseTime( v("vout") 1n t 2n t 90 10 )
tpdlh=delay( v("vin") vth 1 'falling v("vout") vth 1 'rising )
tpdhl=delay( v("vin") vth 1 'rising v("vout") vth 1 'falling )
fprintf( fileptr "%e\t%e\t%e\t%e\t%e\t%e\n", capval , tr, tf, tpdlh, tpdhl, (tpdlh+tpdhl)/2) 
)                                ; END OF foreach
close(fileptr)
plot( v("vin") )

To run simulation, invoke ocean environment, and then load the ocean script file

$ ocean
ocean> load "inv_tran.ocn"

During simulation, the traces are appended to existing waveform window and computed results are appended to inv_tran.dat file. Once the simulation is completed your data file should have the content in the following format.

Cload		 tr		 tf		 tpdlh		 tpdhl		 tpd
0.000000e+00	5.092371e-12	6.732403e-12	5.482314e-12	5.443199e-12	5.462757e-12
5.000000e-15	1.139018e-11	1.340210e-11	9.182815e-12	9.493721e-12	9.338268e-12
1.000000e-14	1.838357e-11	2.092753e-11	1.268909e-11	1.325545e-11	1.297227e-11
1.500000e-14	2.536965e-11	2.853815e-11	1.608702e-11	1.687184e-11	1.647943e-11
2.000000e-14	3.232729e-11	3.616340e-11	1.944034e-11	2.042152e-11	1.993093e-11

Leave a Comment