The following is an example of a script for setting the switching timing of a PAM inverter.
app = designer.GetApplication()
# Create a dialog box
dialog = app.CreateDialogBox()
# Set the dialog title
dialog.SetTitle("Settings for Inverter Switch")
# Add integer input field: Number of poles
dialog.AddInteger("int_name", "Number of Pole", 2)
# Add real number input field: Initial phase of U-phase
dialog.AddReal("real_name", "Initial phase of U(-360 < setting value < 360)", 0.0)
# Add real number input field: Commutating Sequence
dialog.AddReal("another_real", "Commutating Sequence(UWV=0, UVW=1)", 0)
# Add String Input Field: Macro component Name
dialog.AddString("string_name", "Name of Macro component", "PAM")
# Display Dialog
dialog.Show()
# Retrieve settings from dialog
v1 = dialog.GetValue("int_name")
v2 = dialog.GetValue("real_name")
v3 = dialog.GetValue("another_real")
v4 = dialog.GetValue("string_name")
# Assign the set value to a variable
ComSeq = v3
P = v1
Uini = v2
# Define the switch cycle (mechanical angle)
Period = 360/(P/2)
# Calculate the switch's starting angle
def getSt1(phase, switchNumber):
angle = 210 if switchNumber%2==0 else 30
# Calculation of the U-phase
if phase == "U":
# U-phase start angle
st1 = (-Uini+angle)/(P/2)
# Calculation of the V-phase
elif phase == "V":
# Determine phase based on Commutating Sequence
if ComSeq == 0:
st1 = (-Uini+angle)/(P/2)+120/(P/2)
else:
st1 = (-Uini+angle)/(P/2)-120/(P/2)
# Calculation of the W-phase
elif phase == "W":
# Determine phase based on Commutating Sequence
if ComSeq == 0:
st1 = (-Uini+angle)/(P/2)-120/(P/2)
else:
st1 = (-Uini+angle)/(P/2)+120/(P/2)
else:
return 0.0
return st1
# Calculate and apply the switch settings
def setSwitch(phase, switchName, switchNumber):
# Get Start Angle
st1 = getSt1(phase, switchNumber)
# Calculate the end angle
st2 = st1+120/(P/2)
# Set initial state (0: OFF, 1: ON)
sIni = 0
# If st2 is 0 or less, advance st1 and st2 by Period.
if st2 <= 0:
st1 = st1+Period
st2 = st2+Period
sIni = 0
# When st1 is negative and st2 is positive (when the ON period crosses the zero point)
if (st1 < 0) and (st2 > 0):
st1t = st1
st1 = st2
st2 = st1t+Period
sIni = 1
# When st1 is less than or equal to Period and st2 exceeds Period (when the ON period spans Period)
if (st1 <= Period) and (st2 > Period):
# Divide the values of st1 and st2 into periods and reorder them so that st1 < st2.
st1t = st1
st1 = st2-Period
st2 = st1t
sIni = 1
# If st1 is greater than or equal to Period, roll back st1 and st2 by Period.
if st1 >= Period:
st1 = st1-Period
st2 = st2-Period
sIni = 0
# Get the current study
study = app.GetCurrentStudy()
# Retrieve the switch within the macro component
comp = study.GetCircuit().GetSubCircuit(v4).GetComponent(switchName)
# Set the 1-period
comp.SetValue("Period", Period)
# Set the first transition
comp.SetValue("t1", st1)
# Set the second transition
comp.SetValue("t2", st2)
# Set initial state
comp.SetValue("InitialState", sIni)
# W-Phase Switch Settings
setSwitch("W", "S1", 1)
setSwitch("W", "S2", 2)
# V-Phase Switch Settings
setSwitch("V", "S3", 3)
setSwitch("V", "S4", 4)
# U-Phase Switch Settings
setSwitch("U", "S5", 5)
setSwitch("U", "S6", 6)


