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.
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.
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.
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
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.
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.
.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.
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.
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?