Ngspice - How my Variable Resistor Lib is written

KiCAD Version: 6.0.11
My variable resistor model which can be controlled by an outside pwl voltage source has the final code as follows

* source variableR
.subckt VR P1 P2 CTR Rm
R1 Rm P1  R=(50k-V(CTR)+.001)
R2 P2 Rm  R=(V(CTR)+.001)
.ends VR

BTW, I don’t know why I need to attach .001 at the end. The simulation will report an error without these .001.
Anyway, the model is now able to work properly.
The following picture shows how I test the model.

1 Like

Simulators are just a peace of software to solve mathematical equations. Spice, if I remember correctly, solves the circuital nodal voltages and needs the resistance values to do it (V1-V2)/R + … = 0.

Your minimum values prevents the math by 0 division. Some programming strategies includes use eps value (something like 1e-HUGE).

I would try 1e-12, for example.