# How to approximate the behavior of an inverse log potentiometer with ngspice?

I'm trying to write a Spice model able to approximate the behavior of an inverse log potentiometer, but cannot find the right formula to do it.

What I have done so far:

I have already written the models for linear (type B) and log (type A) potentiometers. POT_R is the resistance of the potentiometer and POT_POS is a value between 0 and 1 indicating the position of the potentiometer (0 being CCW, and 1 being CW)

Model for a linear potentiometer:

.SUBCKT POT_B 1 2 3
R23 2 3 {POT_R*(1-POT_POS)}
R12 1 2 {POT_R*POT_POS}
.ENDS


With this linear model if the POT_R value is 100, then the resistance between the pins is the following:

PINS     CCW     25%    50%    75%     CW
R23      0       25     50     75      100
R12      100     75     50     25      0


Model for a log potentiometer:

.SUBCKT POT_A 1 2 3 PARAMS: RANGE=1000
R23 2 3 {POT_R-(POT_R/RANGE)*PWR(RANGE,POT_POS)}
R12 1 2 {(POT_R/RANGE)*PWR(RANGE,POT_POS)}
.ENDS


With this log approximation model, if the POT_R value is 100, then the resistance between the pins is the following (and approximates well enough a type A potentiometer for me):

PINS     CCW     10%     25%     50%     75%     90%     95%     CW
R23      100     99.8    99.4    96.2    82.2    50.1    29.2    0
R12      0       0.2     0.6     3.8     17.8    49.9    70.8    100


In other words, when turning the knob from CCW to CW, the value of R23 first drops slowly then the drop accelerates while the value of R12 first grows slowly, then the grow accelerates.

What I'm trying to do:

Now I'm struggling with approximating a reverse log (type C) potentiometer... What I want to obtain is values similar to these ones with a POT_GAIN_R value of 100:

PINS     CCW     5%      10%     25%     50%     75%     90%     CW
R23      100     70.8    49.9    17.8    3.8     0.6     0.2     0
R12      0       29.2    50.1    82.2    96.2    99.4    99.8    100


In other words, when turning the knob from CCW to CW, the value of R23 needs first to drop fast then the drop needs to slow down while the value of R12 needs to grow quick, then the grow needs to slow down.

Here the INVERSE_LOG_FORMULA should return a value between 0 and POT_R

.SUBCKT POT_A 1 2 3 PARAMS: RANGE=1000
R23 2 3 {POT_R - INVERSE_LOG_FORMULA}
R12 1 2 {INVERSE_LOG_FORMULA}
.ENDS


Hope somebody can help me finding the right formula to achieve this using ngspice (to be run from within KiCad.)

Thanks in advance.

• Have you tried switching the resistors between themselves (while keeping that pwr() formula)? – a concerned citizen Apr 25 '20 at 19:10