...
- Sax Basic function help document. AWR_Sax_Basic.pdf
- Script Development Environment (SDE) Documentation. Scripting Development Environment
- AWR API UML Diagram Diagram. AWR_V13_API_Diagram.pdf
- Shipping AWR Scripts as Examples http://kb.awr.com/x/i4ddScripting KB http://kb.awr.com/x/5oRdExamples. Script Help Landing Page for AWR V15
- Scripting Topics. Scripting Landing Page
- The Some Topics to Think About section below contains useful information on building dialog boxes and other coding approaches that will be useful.
...
The code adds a new schematic and opens a new blank schematic window.
Note: If you run the script again, it will create a new schematic with a slightly different name.
The CreateSchematic code was done as a function to be able to send up an object for the schematic created. Keeping track of the schematic reference is vital in case you create objects by name that already exist; you can reference the schematic as created this way.
...
Next, we need to change the simulation frequencies as the defaults of 1, and 2 GHz would not result in meaningful simulation results. If you select Options > Project Options from the Microwave Office menus, the frequency list is displayed, this is to show the frequencies before the change.
The main subroutine should now look like below:
...
As an aside, simpler code to add frequencies is below. It is fewer lines but much slower to execute due to all the calls to add frequencies.
Code Block | ||
---|---|---|
| ||
Sub SetFrequencies Dim i As Integer Project.Frequencies.Clear For i = 100 To 1000 Step 10 Project.Frequencies.Add(i * 1e6) 'enter in base units, Hz. Next i End Sub |
...
Code Block | ||
---|---|---|
| ||
Option Explicit ' Code Module Sub Main Dim g As Graph Dim m As Measurement Debug.Clear For Each g In Project.Graphs Debug.Print g.Name For Each m In g.Measurements Debug.Print vbTab & m.Type Next m Next g End Sub |
Simulate
Next, we need to add a graph and some measurements to the graph.
...
After running the code, you will have your schematic and graph tiled now with simulation results.
Adding Markers
Next, we need to add markers to the traces to help find the 3dB roll-off frequency
...
Next, we need to set up the parameters we want to optimize and set optimization limits. The best way to see the before and after is to open the variable browser, View > Variable Browser.
The main subroutine should now look like below:
...
Then type or add the optimization goals code after the sub main subroutine. The syntax is a bit involved and usually takes a little trial and error to get it right.
Code Block | ||
---|---|---|
| ||
Sub SetOptGoals(s As Schematic) Project.OptGoals.Add(s.Name,"DB(|S(1,1)|)",mwOGT_LessThan,1,2,0,500e6,mwUT_Frequency,-17,-17,mwUT_DB) Project.OptGoals.Add(s.Name,"DB(|S(2,1)|)",mwOGT_GreaterThan,1,2,0,500e6,mwUT_Frequency,-1,-1,mwUT_DB) Project.OptGoals.Add(s.Name,"DB(|S(2,1)|)",mwOGT_LessThan,1,2,700e6,1000e6,mwUT_Frequency,-30,-30,mwUT_DB) End Sub |
...
- There is a helper function that helps set the optimizer type. The type is set by an integer and not name, so the function finds the name and returns the integer. Different versions of the software can change the order or number of optimizers, so this is the best way to use the right optimizer.
- There is a loop to wait for the optimizer to be done as we don't know in the code how long this will take.
Code Block | ||
---|---|---|
| ||
Sub Optimize Project.Optimizer.MaxIterations = 500 Project.Optimizer.Type = find_opt_type("Random (Local)") Project.Optimizer.NewWindow Project.Optimizer.Start While Project.Optimizer.Running=True Wait(0.5) Wend End Sub Function find_opt_type(nm As String) As Integer Dim typ As Integer Dim i As Integer typ = -1 For i = 1 To Project.Optimizer.TypeCount If nm = Project.Optimizer.TypeName(i) Then typ = i End If Next i If typ = -1 Then MsgBox ("could not find optimizer name specified:" & nm) End If find_opt_type = typ End Function |
...
When the script is done, you will see the message box shown below.
Some Topics to Think About
...
Option Explicit
This option was used in the guide and we highly recommend you use it since it forces all variables used to be defined and properly typed. VB is not strongly typed, so it's easy to get "spaghetti" code going. This option helps to cut down on it and helps the user instantly find typos in variable names.Option Explicit
...
The examples so far have shown working with the AWR SDE. Python is a common scripting language and could also be used to accomplish the same tasks (see AWR Scripting in Python: Getting Started and Installation for setup). We show the same code to complete the same functionality in python below.
...