Basic Potentiometer simulation

I’m trying to have a basic simulation with R_POT but it’s not working.
I don’t understand if i need to define a model for R_POT or if i just need to do a .param

You also need to define in the text box, what kind of simulation type the program shall run e.g. „.trans xx xx xx“

Yes, i did a .dc simulation, but my problem is about the R_POT, i don’t know how to define it correctly.

Treat it like a sensor: 3 electral nodes, do a subcircuit model with what is inside, put a parameter to the symbol with wiper percentage.

1 Like

A very convenient way to “simulate” a potentiometer in the simulator is to use the “tune” function in the top menu at the mouse cursor.

If you click it, then you can click any resistor or capacitor in the schematic and it will be added to the “Tune” area. There you can enter maximum and minimum limits and then use the slider to adjust, or directly type a value in the middle box.

In your particular case, just replace the potentiometer with a normal resistor in the schematic, and connect the non-inverting pin to the net between the resistors and use the tune function to “tune” the lower resistor.

This way you have live update of your simulation results when you’re sliding the slider.

1 Like

Hi, I wrote this one,

I’m not sure if the .param should be in the text file or juste in the schema.

I really like the tune option and @paulvdh 's idea very much, however it won’t work correctly in your specific circuit. You’re using all three terminals of the potentiometer, i.e. ratio-metric, and his approach will only work if you were only using two terminals (like a rheostat). I tried my best to incorporate a way to use the tune functionality, but it’s too limited of a feature to be used practically for a full potentiometer. You can somewhat pull it off with two resistors, but then you have to manually adjust two sliders and keep track of the total resistance in your head while doing it.

Therefore, I agree that @holger 's approach is the best way to handle this, especially since it preserves the schematic for actual circuit layout and construction. Here is an attached sample project that shows on the left how to do it using two discrete resistors and .param statements. Then on the right, the idea is finished by putting the two resistors in a subcircuit and then adjusting the on-schematic text for “value” and “ratio”. If you simulate, you can see that both outputs are the same.
pot_test.zip (6.6 KB)

The default parameters should be in the text file (see the included RPOT_subckt.lib), and then they can be overridden in the schematic via that purple text box in my example that says: RPOT value=10k ratio=0.4

1 Like

Ste, nice work! It might be helpful to add two small series resistors (1 mOhm or so) into the model, to avoid zero resistance, which ngspice does not like. Best done by adding it directly:

{value*ratio + 0.001}
{value*(1-ratio) + 0.001}
1 Like

At least the “Tune” method is usable for potentiometers where the wiper is connected to one of the ends…
I also like to have the slider and live update while dragging.

With your numbers I have to punch in the numbers in the schematic and then re-run the simulation. Is this correct, or did I miss something?


3 other remarks:

  • I had to rename RPOT_subsckt.lib to rpot_subsct.lib because Linux file systems are case sensitive.
  • It’s more intuitive to swap the parameters, so a “high ratio” results in a high output voltage.
  • Wat are the “pot_test.raw” and pot_test.op.raw files? The simulation still seemed to run just fine after I deleted these files.

@holger: Yeah, I had 1m added at first, but I wasn’t sure if I wanted to confuse people with it and then have to explain what it was later. So I tried without it, and it worked so I left it out. I agree though, it was a bad move. Thanks for catching that. I’ll try not to overthink it in the future.
RPOT_subckt.lib (188 Bytes)

Correct, I pointed this out already. Like I said, I tried several ways to try and incorporate the Tune feature into my answer but had no success beyond manually adjusting two sliders. I really like the Tune feature in general and glad you brought it up.

Yes, that’s correct. You can write a .control statement to step through and run the sim automatically at specific ratio values, but I suck at .control statements so I didn’t bother writing an example.

1.) I can see that happening if you manually type in the .LIB filename, but shouldn’t the BROWSE button automatically handle this?
2.) Yeah, that makes sense for this example. But it’s not universal, think of rotating the symbol by 180°, feeding a negative voltage in, etc. I can’t wait until KiCad 6 when we’ll be able to put short .subckt commands on the schematic as text so we can make quick tweaks to it for our specific use-cases.
3.) I dunno. I think it’s leftover data from ngspice from when I last ran the simulation. I just zip up my entire project folder after verifying them, and then upload them here.