Potentiometer TextBox

I’ve looked at other links for potentiometer SPICE simulation and I’m having similar problems, or what I think is similar. I can get the simulation to run but when I change a TextBox parameter, the wiper value remains to what is in the library. There was a bug in 5.0 that I assume was corrected.

Below is screen shot of my schematic and the TextBox.

Am I doing something wrong or am I expecting something that can not be done?

Thanks

I am not sure about the details, but I have read several times on this forum that ngSpice does not directly support potentiometers, and you have to model it as two resistors and a formula, like in the post below:

But when reading the ngSpice manual, apparently it does support potentiometers:

12.2.34 Potentiometer

Description: A resistance potentiometer with three connections: r0, wiper , and r1.
Parameter position determines the lower and upper portions of the resistance.
Rlower is located between r0 and wiper, Rupper between wiper and r1. If log is
set to FALSE, Rlower = position ∗ r. If log is set to TRUE, then
Rlower = r ∗ 10 −position∗log_multiplier . For Rupper we always have
Rupper = r − Rlower. position <= 0 is resolved to position = 1e − 9,
position >= 1 is resolved to position = 0.999999999.

Also, via this search:
https://forum.kicad.info/search?expanded=true&q=potentiometer%20%23schematic%3Asimulation-ngspice

you find:

Paulvdh,

I think I need to add some clarification to my question. The potentiometer model works fine I would like to change parameters in the potentiometer library with a TextBox. Is this a reasonable effort? If it is, what should I do different. Also If it is, for a circuit with two potentiometers how would one differentiate the TextBox for one device from the TextBox for the other.

Thanks

I used a TrimPot but, that’s not important (if you already have your Pot).

I set it up in the Panel (screenshot).

As far as a Text panel with your param, that’s fine but, it’s not real-time (need to re-annotate). Thus, Perhaps a useful approach is to use the Tune feature in the simulator… video

NOTE: In video, I selected the Value to tune. I could have selected the Ratio value, too or, instead… might have been more useful for demo…

ngspice does (but only 1 per model), it just wasn’t documented. But KiCad doesn’t support dynamically changing them.

.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

1 Like

Please post the potentiometer model which you have attached to RV1.

This is what you may get with KiCad-7.99. I have decided to only use 7.99 for simulation.

intro5.7z (4.6 KB)

If you insist on using parameters in a text box, you might get this:

intro5-2.7z (4.4 KB)

Holger et all,
Below is library I’m using and it works fine.
I’ve tried using the parameters in a TextBox as shown in my last response but the parameters actually used are from the library and the TextBox parameters appear to have no impact on the simulation.

I’m running KiCad 7.0.7

There are a number of suggestions in these responses that will take me some time to fully review. Thank you for the responses.

rpot_subckt.lib (189 Bytes)

FYI - if you don’t know it, Click the Sim Command Cog and goto the “Custom tab, Load directives from Schematic” to get them loaded. Set the Compatibility mode as needed (User config) or other as needed.

Parameter replacement has to be enforced by {}. You may try

.param val1=1k pos1=0.3

in the text box and the model attached to the pot:

.subckt rpot 1 2 3
R1 1 2 {value*ratio + 1m}
R2 2 3 {value*(1-ratio)+ 1m}
* below are default parameters, which are required by some simulators
.param value={val1}
.param ratio={pos1}
.ends

For different potentiometers you will need different models (val1, val2 etc.).

Not tested on 7.0.7!

Alternatively (ngspice runs both):

.subckt rpot 1 2 3 params: value={val1} ratio={pos1}
R1 1 2 {value*ratio + 1m}
R2 2 3 {value*(1-ratio)+ 1m}
.ends

As well as that posted above already:

.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

And (as mentioned), these assignments are just default parameters that are overridden by any corresponding parameters passed during invocation (X). Rmin is the contact resistance of 1Ω (which in common real pots is usually more that 10× as much). The noise parameter defaults are for carbon pots (as were commonly used in guitar pedal effects). It just looks a little less gebastelt than adding 1mΩ. It also allows to override Rab with a value instead of ratio with a ratio (and Rbc ist still correctly calculated from R, which might be convenient once .step dec gets supported for log law).

I appreciate the responses but they all seem to focus on the model/subcircuit that works fine.

Can you point me to a reference that talks about implementing .step and .param changes from a text box. I’ve looked in the KiCad manuals and the NG Spice manual but I don’t see a clear description as to how to implement .step and .param changes. That seems to be the real issue I am still unclear about.

Thanks

Different values and at end of my interest in this topic but, conclude with this:

And, I happily admit I prefer LTspice and am not a NGspice guru.

That said, I previously posted comment about this and show it in video below…

Option 1) Change the Value in the Panel - don’t update from Schematic. Just update/refresh the Simulation

Option 2) Change the Value in the Schematic - re-Annotate and update from Schematic.


I did Not setup a voltage divider or do any real work but, you get the idea…
Screen Shot 2023-09-29 at 15.24.10

Please have a look at this thread: Is it possible to perform a simulation with parametric sweep?

Holger,
I’ve done some quick looking at the link you provided and I believe that will give me what I need but it will take some time to fully digest it. I don’t think there is any real value in keeping this ticket open any longer. If I can determine a concise example of what I’m trying to do, I may post the results so others can benefit.

Thanks to all

Just a question: in order to use:
.model potmod potentiometer(position={pos} r={value} log=FALSE log_multiplier=1) in a ngspice netlist, it is necessary to load the cm model with a line before, so the pot model is found:
codemodel <path to library>/xtradev.cm

Did you parametrize you spiceinit to do this or Kicad 7.99 will do a search do it behind the scenes?

On the other hand, do these models allow for sweep of “pos” parameter via control section in netlist?

Yes, if installed correctly, it will do (I use this under MS Windows).

Yes, parameters like {pos} may be swept by the ‘alterparam’ command (followed by ‘reset’).

I’m eager to have this Kicad when gets out of beta stage!

Code models are already available in KiCad 7.0.10.

For sweeping, you will need the extra loop, with external data evaluation (in KiCad 7 as well as in KiCad 8).

1 Like