Pages

2012-12-04

Dive into OCEAN Script

I’ve been prepared this post with the original title of “Data and variables” with the structure of a list of frequently used commands and settings in a OCEAN Script. It’s been a very slow and boring process then I realized that I was essentially doing a language reference which is not what I did to jump start my simulation. So let’s scratch that and do it the right way, instead.

Let’s dive right into OCEAN Script!

Extending the script we built in previous post, we get a new script as below. The script will configure the simulation, run it, store data it generated, calculate the specifications of the opamp, and then write the result to an output file.

 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
48
49
50
; This is a comment line. 
; The comment starts from ";" character and ends at the end of the line.

; 1. Setups for simulator, targeted design, model file,
; simulation type and parameters.
simulator( 'spectre )
design( "OceanScriptLib" "Opamp_tb" "schematic" )
createNetlist(?recreateAll t)
; 1.1. Check model file setting with your CAD support, if any.
modelFile( '("~/model.scs" "TYP") )
analysis('ac ?start "0.1"  ?stop "1G"  )

; 2. Set value of load capacitor at 5pF, bias current at 10uA. 
; "CL" and "IB" are the values declared in schematic. desVar = design variable.
desVar( "CL" 5p )
desVar( "IB" 10u )

; 3. Save the current going through port VDD of component I1,
; for estimating current consumption of the opamp.
saveOption('save "selected")
save( 'v "/OUT" )
save( 'i "/I1/VDD" )

; 4. Execute the simulation
run()

; 5.1. Calculate GBW, PM, GM, OLGain, and IDC
; using built-in functions and store results in variables.
GBW = gainBwProd(VF("/OUT"))
PM = phaseMargin(VF("/OUT"))
GM = gainMargin(VF("/OUT"))
OLGain = ymax(dB20(real(VF("/OUT"))))
IDC = average(mag(IF("/I1/VDD")))

; 5.2. Read design variable CL and assign the result to calculation parameter Cl.
Cl = evalstring( desVar("CL") )

; 5.3. Calculate Figure-of-Merit of the opamp. FOM = GBW(MHz) * CL(pF) / IDC(mA)
; GBW(MHz) = GBW * 1e-6; CL(pF) = CL * 1e12; IDC(mA) = IDC * 1e3.
FOM = 1e3 * GBW * CL / IDC

; 6.1. Define, create the output file and write the first line into it. 
out = outfile("~/Opamp.txt" "w")
fprintf(out, "GBW PM GM OLGain IDC FOM\n")
close(out)

; 6.2. Open ouput file and append calculated results into it.
out = outfile("~/Opamp.txt" "a")
fprintf(out,"%10.2e %10.2e %10.2e %10.2e %10.2e %10.2e\n",GBW,PM,GM,OLGain,IDC,FOM)
close(out)

I hope the explanation given in the code is clear enough. After reading the script, you may try to modify the code to your particular setup and put it to work. Remember to check out the simulation result in the output file, see how well your opamp performs.

P.S. It may seem that writing the script from scratch is an overwhelming task. Luckily, there is a faster way to dive into OCEAN Script, thanks to a built-in feature in ADE.

Once the evaluation bench for Opamp is done. Go to your ADE window to configure for your simulation. Then, in ADE go to Session > Save Ocean Script > a new window titled "Save Ocean Script to File" would pop-up. Enter path and file name for .ocn file.

I'm sure you get the idea.

No comments:

Post a Comment