# LTspice: Vary a resistor's value over time

I want to simulate the load regulation of a power-supply. I'm sure I remember being able to vary the value of a resistor over the course of a simulation in LTspice, but I can't remember how. Anyone?

Use the SpecialFunctions/Varistor.asy component with a time-varying voltage source

• +1 Thanks, Its not how I remember doing it but It should do the trick. I won't mark this approved just yet I like to see if anyone has any alternatives..(although it doesn't look likely...) – volting Jul 20 '10 at 15:29
• There are plenty of alternatives - You could use a transistor with a known Rds characteristic, and change the gate voltage from 0 to saturation, or just put in a voltage or current source and ramp through the voltage or current range that you want to establish across your resistor. The varistor, however, is the controllable resistor you asked for. – Kevin Vermeer Jul 20 '10 at 16:35
• Sure.. but if my memory serves me correctly(which it probably doesn't) it is possible to do it with a regular resistor + some simulation command, which would be more intuitive and straight forward. Anyway Thanks again for the suggestions – volting Jul 20 '10 at 18:19
• Use the source, Luke! Open up the varistor model definition and subcircuit, and figure out what it does - The SPICE commands should be in there somewhere. This document: ltspice.linear.com/software/scad3.pdf should help you. – Kevin Vermeer Jul 20 '10 at 19:20
• Point taken! It came to me... what I used before was a parametric sweep – volting Jul 20 '10 at 20:22

Unfortunately using a varistor will not work, as a varistor itself has a dependence on the voltage across it. Much simpler is to right click onto an existing resistor, and to enter a formula. E.g.

R=11-100*time


will linearily reduce the resistance from 11Ohm to 1Ohm over the time of 100ms. You can use almost all functions available for the voltage b sources (arbitrary behavioural voltage source), as well as all kinds of measurements e.g. of voltages of other nodes.

There is another way. Setup a Voltage source and choose the output you want. Label the output net VResistance. Volts on source will be exactly what the resistance is. I.e. 10KV will be the same as 10K ohm. Then use the standard resistor with the assignment R=V(Vresistance). As the voltage source changes, the resistor changes with it. The nice thing about this is the PWL file can now be used to control the resistance. Expecially nice when running things from Mathematica or Matlab.

• Nice Paul, that was exactly what I was looking for. Even tried "R=PWL(...)" as the value. – rdtsc Aug 11 '15 at 21:28
• I had to google "PWL file", but now I see potential advantage of this method when interacting with external programs. By the way, I think under the hood this works also as behavioral (expression) for the resistor. – Fizz Oct 13 '15 at 22:32
• This was my favorite solution. Full write up here:electronicspoint.com/resources/… – Frederick Sep 30 '18 at 21:28

Using McHale's suggestion, I produced a Current Dummy xLoad to test power supplies and power circuits. Based on a PWL sequence, the Load sucks current from the power supply, no matter the voltage at the supply.

The PWL sequence specifies a ramp&shake profile that exercises the supply, so one could analyse the behavior of such supply, if it bounces, oscillate, ring, voltage recuperation time, etc.

The xLoad .asy file can be anything with two connections, since it behaves like a dynamic resistor that change its value based on the PWL values AND the voltage applied at the Load inputs. You can apply a 10Vdc with a ripple of 9V and the Load will adapt its dynamic resistor so it follows the current profile from the PWL.

The xLoad has only one parameter, "mult". This parameter allows the user to change the maximum current from the PWL profile, so, mult=1 will use a profile that will suck maximum of 1A from the supply, mult=4.2 will suck a maximum of 4.2A. Your xload.asy must have a visible attribute "mult=1", so the xLoad will work, and you will be able to change the attribute at any time.

The xLoad uses a small capacitor to round very sharp edges that can simulate very high frequencies and rings, what doesn't happen in real life, so all the corners are a little rounded. If you want to change or eliminate this feature, just change the value of C1 from 10n or even eliminate that line. The feature is just a RC filter, R2 and C1, other way to change the filter is changing the value or R2, just don't delete such line, xLoad will not work without R2, you can change its value to zero ohms to eliminate completely the filter, even so I don't know why you will want to have MegaHertz sharp corners.

Create a text filename XLOAD.SUB into your LTSPICE/LIB/SUB directory, with the following contents (the "v1" line is long, not broken):

    * xLOAD
* PWL Current Profile
* By Wagner Lipnharski Nov/2015
*
*              Positive (Input)
*              |  Negative (Output)
*              |  |

V1 3 2 PWL(0 0 +100m 0 +0.1m 0.2 +5m 0.2 +.1m 0.5 +5m 0.5 +.1m 1 +5m 1 +.1m 1.5 +5m 1.5 +.1m 2 +5m 2 +.1m 2.5 +5m 2.5 +.1m 3 +5m 3 +.1m 3.5 +5m 3.5 +.1m 4 +10m 4 +1m 3.5 +8m 3.5 +1m 4 +10m 4 +2m 2.5 +8m 2.5 +2m 4 +10m 4 +2m 1.5 +8m 1.5 +2m 4 +3m 4 +2m 0.2 +3m 0.2 +2m 4 +10m 4 +3m 0.2 +8m 0)

R1 1 2 R=V(1,2)*4/(mult*V(4,2)+1n)

R2 3 4 1k

C1 4 2 10n


1. Set the value of resistor that you want to be variable, to be {R} (don't forget the curly brackets!)
2. Click on .op (far right on the toolbar)
3. Type: .step param R 1 10k 1k (steps from 1 to 10K in 1k increments)