Author Topic: Simulating potentiometers using LTSpice.  (Read 20904 times)

0 Members and 3 Guests are viewing this topic.

Offline Zero999Topic starter

  • Super Contributor
  • ***
  • Posts: 19527
  • Country: gb
  • 0999
Simulating potentiometers using LTSpice.
« on: April 21, 2019, 02:20:21 pm »
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 increment

Where
variable_name is the name of the variable i.e. POT
start_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 simulation
increment 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 values


demo 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.
« Last Edit: April 29, 2019, 09:52:07 am by Zero999 »
 
The following users thanked this post: BravoV, ggchab, SilverSolder, Cliff Matthews, HoracioDos, soldar

Offline iMo

  • Super Contributor
  • ***
  • Posts: 4789
  • Country: pm
  • It's important to try new things..
Re: Simulating potentiometers using LTSpice.
« Reply #1 on: April 21, 2019, 06:54:46 pm »
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 :)
« Last Edit: April 21, 2019, 06:57:34 pm by imo »
 

Offline Zero999Topic starter

  • Super Contributor
  • ***
  • Posts: 19527
  • Country: gb
  • 0999
Re: Simulating potentiometers using LTSpice.
« Reply #2 on: April 21, 2019, 07:08:56 pm »
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 :)
It 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.
 

Offline iMo

  • Super Contributor
  • ***
  • Posts: 4789
  • Country: pm
  • It's important to try new things..
Re: Simulating potentiometers using LTSpice.
« Reply #3 on: April 21, 2019, 07:51:51 pm »
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
« Last Edit: April 21, 2019, 08:36:22 pm by imo »
 

Offline Zero999Topic starter

  • Super Contributor
  • ***
  • Posts: 19527
  • Country: gb
  • 0999
Re: Simulating potentiometers using LTSpice.
« Reply #4 on: April 22, 2019, 01:20:51 pm »
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.
 

Offline Zero999Topic starter

  • Super Contributor
  • ***
  • Posts: 19527
  • Country: gb
  • 0999
Re: Simulating potentiometers using LTSpice.
« Reply #5 on: April 22, 2019, 09:57:32 pm »
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)

« Last Edit: April 23, 2019, 09:24:41 am by Zero999 »
 
The following users thanked this post: Cliff Matthews

Offline Zero999Topic starter

  • Super Contributor
  • ***
  • Posts: 19527
  • Country: gb
  • 0999
Re: Simulating potentiometers using LTSpice.
« Reply #6 on: April 23, 2019, 09:48:16 pm »
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.

« Last Edit: April 23, 2019, 09:52:19 pm by Zero999 »
 
The following users thanked this post: Cliff Matthews

Offline Zero999Topic starter

  • Super Contributor
  • ***
  • Posts: 19527
  • Country: gb
  • 0999
Re: Simulating potentiometers using LTSpice.
« Reply #7 on: April 27, 2019, 10:17:43 pm »
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.

« Last Edit: April 29, 2019, 09:50:14 am by Zero999 »
 
The following users thanked this post: Cliff Matthews, iMo

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Simulating potentiometers using LTSpice.
« Reply #8 on: April 28, 2019, 12:29:43 am »
I posted these parameter controlled and voltage controlled LTspice models and symbols last summer: potentiometer.zip in the topic https://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: [Select]
* 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
.ENDS
contains 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.
« Last Edit: April 28, 2019, 12:31:55 am by Ian.M »
 
The following users thanked this post: Zero999, Cliff Matthews, iMo

Offline Zero999Topic starter

  • Super Contributor
  • ***
  • Posts: 19527
  • Country: gb
  • 0999
Re: Simulating potentiometers using LTSpice.
« Reply #9 on: April 28, 2019, 09:48:46 am »
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.
 
The following users thanked this post: Ian.M, Cliff Matthews, iMo

Offline iMo

  • Super Contributor
  • ***
  • Posts: 4789
  • Country: pm
  • It's important to try new things..
Re: Simulating potentiometers using LTSpice.
« Reply #10 on: April 28, 2019, 11:22:49 am »
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
Great! I tried to pass the control voltage into the pot model, but got an error, probably because the missing 10G resistor..
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf