Simulating potentiometers using LTSpice. - Page 1
Forum section: electronics / beginners

author: Zero999
author_rank: Super Contributor
timestamp: April 21, 2019, 02:20:21 pm
content: In responding to another thread it became apparent that it's not obvious how to simulate a potentiometer, using LTSpice. Rather than clog it up, I decided to make a quick tutorial and it can be made sticky if people find it useful, otherwise it'll just sink to the bottom of the list and rot, if it's no good.There are several ways to do it.Firstly the potentiometer must be broken down into two resistors: the top (POT1a) and bottom (POT1b), with the wiper joining them both. If you wanted to, you could add an extra resistor in series with the wiper, to emulate the contact resistance, but it's not needed in most applications, as it's small, compared to the total resistance.Now you need a way to alter the resistance value.There are three ways:Use the .step param directive..step param variable_name start_value end_value incrementWherevariable_name is the name of the variable i.e. POTstart_value is the resistance value at the beginning of the simulation.,end_value is the resistance value to be swept towards, as the end of the simulationincrement is the step size.The value of the potentiometer is simply set to {variable_name} with a mathematical expression. To make a potentiometer, the top resistor's value is incremented, as the bottom resistor value is decremented, with a small value added to both to ensure neither value is zero: LTSpice can't handle zero Ohm resistors as they result in division by zero.demo 1 and 2 use the step param method.demo 1 uses absolute valuesdemo 2 uses a percentage which is scaled, allowing the potentiometer's value to be more easily changed.The above two are fine, but no good for analysing the transient response, as the resistance is varies.demo 3 uses the time to control the resistance. The downside to this is changing the length of the simulation time affects the resistance value.demo 4 uses a voltage to control the resistance. A voltage of near 0V to 1V is used because it makes scaling easier. Note again, to avoid zero Ohm resistors, the voltage can never equal 0 or 1. It's a bit more tricky to set up but is the most flexible option since the resistance can be arbitrarily varied at and speed and wave shape.

author: iMo
author_rank: Super Contributor
timestamp: April 21, 2019, 06:54:46 pm
content: There is a pot available, and it works. What I miss is an interactive behavior, a knob I turn while I get new simulation results instantly

author: Zero999
author_rank: Super Contributor
timestamp: April 21, 2019, 07:08:56 pm
content: Quote from: imo on April 21, 2019, 06:54:46 pmIt isn't part of the default install though. Attached is the library I often use, but I often prefer the methods described above because they're more portable and the voltage controlled one is very powerful.

author: iMo
author_rank: Super Contributor
timestamp: April 21, 2019, 07:51:51 pm
content: I've tried to push the control voltage into the model ( the "T" or "wiper" position ) without a success.Would be nice to have: to implement your model into the "pot" subcircuit, such we can use any parameter as the wiper position..A collection of various pots (lin/log/pow/tab):PS:http://ltwiki.org/files/LTspiceIV/examples/LtSpicePlus/Gen/Chaos&Noise/OpticalAWGN/potentiometer_standard.lib

author: Zero999
author_rank: Super Contributor
timestamp: April 22, 2019, 01:20:51 pm
content: The step command works with the library, but not the time or voltage control methods, which is odd. I think it's a fault of LTSpice, rather than the library.Why do you need the library? The only advantage I can see is the symbol makes drafting easier and the schematic more clear. It doesn't benefit simulation. Logarithmic potentiometers are easy to implement, using the methods I've described previously.A log potentiometer can be simulated by using the exponential function.

author: Zero999
author_rank: Super Contributor
timestamp: April 22, 2019, 09:57:32 pm
content: Here's a logarithmic potentiometer simulation.The 50% wiper setting gives 10% of the resistance for an audio taper.http://www.resistorguide.com/potentiometer-taper/3.322 = log(0.1)/log(0.5)

author: Zero999
author_rank: Super Contributor
timestamp: April 23, 2019, 09:48:16 pm
content: Here's another time controlled resistor, which does a linear sweep (sawtooth) at 100Hz. Interestingly, it never gets to +/-1 because the time steps don't align to 10ms. If they did, it could generate an error, which could be overcome by adding 1m to both expressions.

author: Zero999
author_rank: Super Contributor
timestamp: April 27, 2019, 10:17:43 pm
content: Here's a potentiometer which sweeps linearly back and forth in a triangle wave.It demonstrates using a function.For example:.func ramp (frequency) {2*abs(round(frequency*time)-frequency*time)}Which returns a linear ramp back and forth, at a given frequency.frequency is a variable within the function and time is the SPICE internal variable.Internal SPICE functions are used: abs returns the absolute value so abs(-1) = 1 and abs(1) = 1 and round returns the nearest whole number e.g. round(1.6) = 2.Then there are the cw (clockwise) and acw (anticlockwise) functions which return the resistance of one half of the potentiometer. For the purposes of the simulation the pot's wiper is first rotated clockwise, then back, anticlockwise. The cw function returns the value of the section of the pot who's resistance increases, as it's rotated clockwise and the acw does the opposite.The .param statement sets P1, a global variable with the value of the potentiometer.The .step param cause the simulation to be repeated with different values of P1_F, ranging from 20Hz to 100Hz.

author: Ian.M
author_rank: Super Contributor
timestamp: April 28, 2019, 12:29:43 am
content: I posted these parameter controlled and voltage controlled LTspice models and symbols last summer:potentiometer.zipin the topichttps://www.eevblog.com/forum/beginners/seeking-help-with-ltspice-simulation-of-variable-power-supply/where their usage is described.N.B. if you don't want the LTspice netlist generator to optimise away (as internally unconnected) the control voltage to a model, you *MUST* connect that terminal to something internally in the subcircuit. Therefore the model for PotentiometerVC:Code:* This is the potentiometerVC* _____* 1--|_____|--2* |* 3** 4 - control voltage*.SUBCKT potentiometerVC 1 2 3 4.func w()=limit(V(4),1m,.999)R0 1 3 R={Rtot}*(1-w())R1 3 2 R={Rtot}*w()R2 4 0 10G.ENDScontains an extra 10 gigaohm resistor (virtually an insulator) from the control voltage terminal (4) to net 0, (global ground) so the netlist generator doesn't remove the terminal 4 connection.

author: Zero999
author_rank: Super Contributor
timestamp: April 28, 2019, 09:48:46 am
content: A demonstration of Ian's library.It's such a shame LTSpice doesn't have a way to embed symbols. The model could easily be embedded into the .asc file but not the symbol.

author: iMo
author_rank: Super Contributor
timestamp: April 28, 2019, 11:22:49 am
content: Quote from: imo on April 21, 2019, 07:51:51 pmGreat! I tried to pass the control voltage into the pot model, but got an error, probably because the missing 10G resistor..