Can I restrict the value of a .param variable?

In QSpice if I have a statement ‘.param Duty_Cycle = 0.5’ can I make a it so that the duty cycle is always between 0 and 1?
So if someone or even I on accident go out of that range my simulation will throw a warning or an error?

There is no direct way to achieve this, but there are at least three indirect methods:

  1. Set up two parameters, one for user input and another using the limit() function, which establishes the relationship between .param userDuty and .param Duty in this example.
  2. When used (assuming duty is converted into a voltage for comparison in a sawtooth), in the behavioral voltage source, employ the limit() function, as demonstrated by B1 in this example.
  3. A workaround involves constructing a symbol with a command (dot directive). Here, .param symbolDuty is not a direct text line but is created from a symbol. With symbols, there is a programming attribute that can constrain its input limits, illustrated by “.param0to1.qsym” in this example.

Typically, limiting the range of input occurs when creating custom symbols (as these symbols are shared for others to reuse, with the hope that users do not input values outside the specified bounds). However, a schematic is usually shared as an example, and users should be aware of what they are modifying.

param0to1.qsch (38.4 KB)
.param0to1.qsym (270 Bytes)

1 Like