Limiter & Switching Blocks
Blocks that bound a signal or select between signals. Several carry discrete state and so introduce discrete transitions into the model.
Limiter with constant bounds.
Syntax
& limx_ix_j{x_min}{x_max}x_i is the input, x_j is the (limited) output. x_min and x_max are constant bounds (data names, parameter names, or math expressions).
Internal states: none
Discrete variable:
Equations
Discrete transitions
if z = 0: if x_i > x_max: z ← 1 else if x_i < x_min: z ← -1else if z = 1: if x_i < x_max: z ← 0else: # z = -1 if x_i > x_min: z ← 0Initialization
if x_j > x_max: z ← 1else if x_j < x_min: z ← -1else: z ← 0Limiter with variable bounds.
Syntax
& limvbx_ix_minx_maxx_jx_i is the input; x_min and x_max are variable (state) lower and upper bounds; x_j is the (limited) output.
Internal states: none
Discrete variable:
Equations
Discrete transitions
if z = 0: if x_i > x_max: z ← 1 else if x_i < x_min: z ← -1else if z = 1: if x_i < x_max: z ← 0else: # z = -1 if x_i > x_min: z ← 0Initialization
if x_i > x_max: z ← 1else if x_i < x_min: z ← -1else: z ← 0Notes
Unlike lim, the bounds and are model states (variables) rather than fixed parameters, allowing dynamic limit variation during simulation.
Deadband.
Syntax
& dbx_ix_j{delta_1}{s_1}{a_1}{delta_2}{s_2}{a_2}x_i is the input, x_j is the output. Parameters , , , , , are data names, parameter names, or math expressions.
Internal states: none
Discrete variable:
Equations
Discrete transitions
if z ∈ {0, 1}: if x_i < delta_1: z ← -1else if z ∈ {-1, 0}: if x_i > delta_2: z ← 1else if z ∈ {-1, 1}: if delta_1 < x_i < delta_2: z ← 0Initialization
if x_i > delta_2: z ← 1else if x_i < delta_1: z ← -1else: z ← 0Notes
- The data must satisfy , , and .
- A common special case is and , although all values are permitted.
- The pwlin4, pwlin5, or pwlin6 blocks can be used as alternatives.
Hysteresis.
Syntax
& hystx_ix_j{x_I}{y_IB}{y_IA}{x_D}{y_DB}{y_DA}{z0}x_i is the input, x_j is the output. The parameters , , , , , define the hysteresis shape. z0 specifies the initial discrete state when the input starts in the indeterminate region.
Internal states: none
Discrete variable:
Equations
Discrete transitions
if z = -1: if x_i > x_I: z ← 1else: # z = 1 if x_i < x_D: z ← -1Initialization
if x_i > x_I: z ← 1else if x_i < x_D: z ← -1else: if z0 >= 0: z ← 1 else: z ← 0Notes
At , if the initial operating branch is indeterminate. The system could operate on either the line () or the line (). The user must therefore supply z0 to resolve the ambiguity.
If then is initialised to ; if then is initialised to , and z0 is ignored in both cases.
The data must satisfy . The degenerate case is not allowed by this block but can be handled with the pwlin4 block.
switch
Section titled “switch”Set the output state to one among input states, based on the value of a controlling state. Separate blocks exist for and .
Syntax
& switch2name of variable x_i(1)name of variable x_i(2)name of variable x_k (selector)name of variable x_j (output)For switch3–switch5, prepend additional input variables through before .
Internal States
None.
Discrete Variables
Equations
Discrete Transitions
where returns the nearest integer.
Initialization
Same as discrete transitions.
swsign
Section titled “swsign”Switch between two input states, based on the sign of a third input state.
Syntax
& swsignname of variable x_i (selected when x_k >= 0)name of variable x_j (selected when x_k < 0)name of variable x_k (sign selector)name of variable x_l (output)Internal States
None.
Discrete Variables
Equations
Discrete Transitions
if z = 1: if x_k < 0: z ← 2else if z = 2: if x_k >= 0: z ← 1Initialization
if x_k < 0: z ← 2else: z ← 1See Also
Section titled “See Also”- Block Index, all CODEGEN blocks by category
- CODEGEN Model Examples, complete models built from these blocks
- User-Defined Models, the DSL file format