Ngspice Potentiometer Code Model Tuner Support
This partially implements #4960 (closed)/#2426 (closed)/#2130 (closed)/ƒ22681 for the potentiometer
code model (XSPICE A
device) of ngspice.
A potentiometer is usually modeled as a subckt1 with 2 resistors and a parameter for the wiper position.
However, changing a subckt parameter in ngspice using alterparam
also requires a reset
each time.
Changing both resistors directly using 2 alter
commands would not require a reset
, but resistor names, values and possible ranges would have to be figured out first.
The XSPICE behavioral potentiometer
2 code model, however, has a model parameter that can be changed using altermod
without a reset
, similarly to how alter
is used to change the instance value of a passive device.
A drawback is that code models currently don't support instance parameters, only model parameters, so all devices using the same model will have the same parameters also.
While the potentiometer
code model also supports a log law behavior (model parameters: log=1 log_multiplier=2
) with 10% resistance ratio at mid-travel, its end positions are swapped (100% ratio at 0% travel, and 1% ratio at 100% travel) compared to the linear behavior.
To work around this bug and to also allow additional resistance laws, a parameterized characteristic curve for the tuner slider is used instead, which can be used for the passive devices as well (drag the black point in the graph for the possible curves).
No nice GUI yet (hardwired choice item instead of popup). Maybe something with configurable presets for common laws (lin/log/rev/S)? Like it's done for grid sizes or zoom factors?
-
enable potentiometer
code model selection from file (in Model tab) -
enable tuner for potentiometer
code model -
characteristic curves for tuners -
transformation function (default: linear) -
curve parameter presets (10 hardwired) -
curve parameter user settings (GUI?)
-
Example schematic using the potentiometer
code model (works but not tunable in 5.1.7+): pot.zip
Example sub-circuit for an (ideal linear) potentiometer:
.subckt potentiometer a b c R=100k ratio=0.50
+ Rmin=1 Rab=Rmin+ratio*(R-2*Rmin) Rbc=R-Rab
+ TC=0 Kf=0
.model potentiometer R TC1=TC TC2=0 Kf=Kf Af=2
Rab a b potentiometer R=Rab
Rbc b c potentiometer R=Rbc
.ends potentiometer
Example usage of potentiometer
code model, with an equivalent circuit (linear only), for 0 < position < 1
and r > 0
:
.model pot potentiometer r=100k position=0.5
ARV1 1 2 3 pot
* corresponds to:
.model pot r r=100k
.param position=0.5
RRV1$0 1 2 pot noise=0 scale=position
RRV1$1 2 3 pot noise=0 scale={1-position}