Dave shows how to do temperature and parameter sweeping of your circuit using LTspice

Hi I Thought I'd Just run you through a quick little tutorial here in LT Spice, showing you a very valuable technique called Uh temperature sweeps. and that's uh, analyzing your circuit not just in the regular Uh domains, but over temperature variations and it's not really obvious how to do this in LT spice. Uh, unless you're familiar with the spice commands and things like that, it's much easier. In other Uh circuit simulation tools, they might have a menu option or some other option to do temperature sweeping.

It's really obvious, but um, it's not so obvious in LT Spice. So, but it's really very easy and it's built in there. you just don't know it. So let's run through it.

And temperature sweeping. Your circuit simulation can be a very valuable technique to see how your circuit is going to perform uh, over a real world temperature variation or a Sim circuit simulated temperature variation. It's going to be fairly close in most cases and uh, it's a a step which a lot of people uh, simply forget to do. They will simulate their circuit and it works just fine.

but then when they build it up, they find that oh, it's not working as they intended because the temperature variation has changed and every component has regardless of what the component is, has some sort of Uh temperature coefficient. so its uh parameters. Its value will change with temperature and there's a way to simulate this now. I'm uh using LT Spice of course it's my favorite Uh circuit simulator tool.

It's free and uh, it's not the easiest to use though. I've done a few little Um tutorials here and there on it so we'll learn how to do temperature variation in this one. and as far as I know, there's nothing in the tool, you know, the menus or anything like that, the simulation commands and stuff like that to do a temperature variation. So how do you do it? Good question.

Well the circuit we're going to use here is a very simple two transistor constant current circuit and you may have seen this before or you may have seen A variation with Q2 transistor here replaced with two series uh diodes. It really doesn't make much difference you can use either and what it does is it basically sets up a constant current through R1 here through this transistor q1 uh based on the base em uh voltage of the Uh transistor and the and the source here in this case are Q2 or two series doodes. You may have also seen one with an LED in here as well that can be used as well cuz all you need is anything that generates a constant voltage greater than the basem drop of q1. So anything here like an LED which might have say a 1.8 vol drop for a red LED uh will set up a constant current through here.

But as you should know, uh, the Bas mid uh uh voltage will change with temperature and we're going to find out how much by doing a temperature parameter sweep in LT spice. So let's go. First thing we'll do here is we'll run a regular Sim transient simulation here and let's set it up so that, um, our stop time is 1 second and we've got starts at zero uh seconds and we'll have a Time step of 1 millisecond so we'll get 1,000 points there and it puts our spice command down here and we'll add a spice command later to do the temperature sweeping. So this is prob.
if you've used LT Spice or any other circuit simulator with transer response, this is what we'll do. So we'll go up here and we'll run it and it's running and then we can see our constant current through R1 Here and there it is. It's 6.1 milliamps, which is not surprising. around about 0.6 Vols um uh, base emitter drop.

uh basically and where uh on divided by 100 ohms is 6.1 milliamps and that isn't really going to change uh much at all with this uh voltage is with the uh Supply voltage up here because it's a constant current gener Ator that's what it's designed to do. generate a constant current through R1 regardless of the voltage here so we can go in there and we can modify that and we can call that say 20 Vols Okay, and we can run that again and bingo there it is. It's still that 6.1 milliamps. It hasn't varied at all now.

I might as well show you uh before I show you the temperature parameter sweep. Let's go for a basic parameter sweep. You notice how I man ually changed that uh V2 voltage there from Uh 10 Vol to 20 Vols and we ran the simulation again. Well what if you wanted to do sweep that value across? So the way we do this is we go into V2 here and instead of putting that value in there like we did before, we put in a curly bracket and that indicates to uh the Spice engine the LT spice that this is going to be a parameter which we're going to modify when it's running the circuit simulation and can give this a label and we can call this say VN like this and we close it with a curly bracket like that and now we can actually use a Spice Directive a Spice command and we go up here this little tab up here called spice Directive.

We go in and we can use a command which is called a step command and then we want to tell it and use another command that we want to step the parameter so we use param like this and then we give it the label we just gave it which is VN and then we use another command called list I Know it sounds complicated but you know it's once you learn this once, it's pretty easy to do and then that just tells us that Uh tells the engine that we're going to list some values here that we want to sweep through. So we want 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 and you can put in as many as you want so it'll sweep through. So that command is to step through the parameter the in with a list of values 1 2, 3, 4, 5, 6, 7, 8, 9, 10. Simple.

Then that puts that command onto your schematic there and you can now run this simulation. and it should In theory, if we measure the voltage here Bingo Look, it's now stepped it I Know these scales are slightly off, but that is cuz that's that auto scale uh function. but that is 1, 2, 3, 4, 5, 6, 7, 8, 9 10 volts there. So circuit simulation has gone through and done this transient response.
Um, with a th000 steps, it's done it 10 different times for all of those values and we can now look at the variation in this. Look at the variation in the constant current here for this V2 varying from 1 volt through to 10 and you see that it's pretty darn close. Look, it's 6.10 you know. Third decimal place.

There, it changes little bit, so that's a really pretty good constant current circuit at one temperature because it's only simulating this at one Nom temperature which is nominally room temperature. So that's called parameter sweeping and you can not only do that for voltage, you can do it for any parameter in any circuit component. So this resistor. here.

you could Sweep use that exact same command to sweep through. Say this. this resistor. You could change the Val value from 1K up to 100K or something like that.

And you could, uh, these transistors. Here you could go in and you can change any one of the parameters in there using that parameter command. But we want to do a temperature sweep. So we do exactly the same thing.

We put in our spice directive and we go dot step and then we want to put in instead of peram. We don't want to change the parameter we want to use. We want to sweep the global temperature in this circuit. So you use the command temp and then we want to list them again.

And let's say we want to list. Uh, go from 0 5, 10, 15, 20, 25, 30, 35, 40, 45, and 50. We want to sweep from 0 through to 50. C We just put that in there like this.

That's our spice command, our spice directive and we go ahead and run that and Wow! Look, we've got got a spread of parameters here. Let's go in and check it out. We got our current through here. Aha! Look at this over temperature.

You'll see that the temperature. as the temperature changes by each 5 degrees, it jumps from 5.67 milliamps, 5.76 and it spreads by almost like 1 milliamp there. So you know that's a fair error to go from 5.6 milliamps to 6 .6 milliamps over a 50 temperature range. And you wouldn't have known this unless you did a temperature parameter sweep.

Now there's actually an easier way than just doing this list. if you want to, um, say you want to do one degree steps from 0 to 50. you don't actually have to type in 1, 2, 3, 4, 5 right up to 50. You can actually go in there and you can modify this and instead of putting list, you can just leave out the list command and you can put zero 50 and then the step value so it will.

You're telling the engine now to go, Uh, to step from 0 to 50 with an increment of one. So there's only three parameters there. So we do that and we execute our there it is bang. It's running through 50 different transient simulations there of our it's exactly the same before except we've got greater resolution and you can see those values Change Magic! Now at this point I Know what you're thinking: Can we actually combine more than one parameter sweep at the same time? Can we sweep V2 over here at the same time as we sweep the temperature? Well, you bet we can.
Well, we can't do it at the same time, but it will, but we can make it step through as many parameters as we like. So in this case, I'm going to combine the two exact things we've done before our spice Direct directive here which is our Set uh temp from 0 to 50 and 5 steps. and also we're going to step our parameter VN from 1 to 10 in 1V steps. So what it's going to do is it's going to run through this transient response not just 10 times here, but it's going to do it 10 times for each one of these 10 times here.

So let's give that a go. Let's run that. by the way, I've Tred changed my Transit time to be a 10 millisecond uh step just so the simulation uh is a bit shorter. but it's going to be no different.

So let's run that and Bingo! what do we get? You see, it ran through it ran through like a 100 times to give us all these responses. Now you Pro we're looking at the current through R1 Here we can look at the VN value up here. you can see it St from 1 volt through the 10 volts. but let's look at how our constant current load here changes over temperature.

Now that looks just like before. But let's zoom in here and you'll notice if you can just see that that with each one of these lines there is a slight variation with all the other lines. so let's see if we can actually zoom into this bit here and see if we can see the variation. Look at that.

So there you go. for each one of those temperature steps. We have an input voltage step like this and you can see that minute change. We're only talking.

you know, 6.58 milliamps up to 6.51 milliamps. Not much change at all. You know you're only talking 10 microamps. 20 microamps change based on that voltage at that particular temperature.

So that's how it works. So you can see the minor variations in each one of those and you can do that for sweeping as many parameters as you like. So as you saw, that can be a very powerful tool. We're just getting simple flat, uh uh, curves there.

When you do a more complex circuit, maybe you're sweeping like a band pass filter or something magical like that, you're sweeping responses. You can combine them all with all the different types of Um Analysis functions you've got in a spice tool. Can be very, very powerful and I won't go through it. I Encourage you to go and experiment on your own.

Now Um, let's do a simple let's uh, change this circuit just out of curiosity. Let's uh, do an LED Let's add an LED in here and uh, see what happens? See if that's any better than our two transistor circuit. So we pick a new uh Diode Nichia. There we go.
We got a Nicha I Have no idea what an Nscw 100 Nichia lead is, but uh, there's all of the spice values in there. 30 milliamps? I s Yeah, Okay, let's just pick that as a typical Diode. You'd have to have a look at the data sheet, but let's do that. Uh, run that simulation again and see what we get here.

Wham Let's have a look in here. Wow, look at that. That's quite. That's a quite a substantial variation.

You're talking 12.5 milliamps there. From 12.5 milliamps to 14.5 milliamps. Now let's go back to our dual transistor configuration for a second. and instead of having our fixed 3.3 volts here like we did before powering this, I'm actually going to uh, take this from the inut from the input Supply voltage V2 here and I've just run the simulation again Exactly the same parameters as before, but look at the quite the spread in variation.

You notice how we had like, uh, before we had like just you know, a single line with the temperature variations very clumped together. You know they've got a much wider spread like that because the VN is changing. It's changing this current through R2 Here we can actually get a spread of that and you can actually see that that current changing through R2 as V2 gets stepped here. so V2 gets stepped.

I've set it from 3 volts through to 10 volts. so it gets stepped 3, 4, 5, 6, 7, 8, 9 10 volts. You can see and in between those, you have the individual temperature variations. So going back and looking at our two transistor constant current Source Here it's quite crude.

uses Jelly Bean 239 04s How good is it? Well, using a constant V1 Here, if you uh, we can see the result over a 50 C range, it's about a 15% change over a 50 Celsius uh rise. So that's a Uh around about 0.3% per Dees Celsius Is that any good? Well, if we take a look at the classic LM 334 constant current source uh chip, then it has essentially the same temperature coefficient. It's got around approximately. 33% per deg C temperature dependence.

So there you go. It's as good as an LM 334. Basically I Rather like it, it's neat. Let's just try one other totally different example here: I've got a C Pits uh oscillator which comes with the Uh as an example comes with the LT spice circuit.

I've added my It doesn't normally do the temperature variation, but I've added my spice. uh directive here. Step temp from 0 to 50 5 steps. Let's run it.

Look at that beautiful look at all the temperature variations in there. Fantastic. And you can almost get works of art with these things. It's almost.

You know, it's almost art. What you can actually uh, make with the results from these parametric uh sweeps and and temperature sweeps. Good stuff. So I hope you enjoyed that I Hope you found it interesting in how easy it is to do temperature parameter sweeps or any parameter sweeps in LT spice because it's a shame that it's not immediately obvious how to do it.
they don't have like a menu option in here in simulate it would have been nice if you know somehow they had you know an option in here to sweep and to do like a temperature and automatically um added that command I Know it's not much, but it just would have been easier for beginners to find that. otherwise it's just buried away as a regular spice command. And if you don't know your uh spice commands to do uh, temperature sweeping then well, you'll be sitting here looking through all the menus scratching your head. So I encourage you to have a play around with temperature sweeping next time you simulate your circuit.

It's a very powerful and essential tool I Hope you liked it and if you like the video, please give it a big thumbs up. Catch you next time.

Avatar photo

By YTB

30 thoughts on “Eevblog #301 – ltspice temperature sweep tutorial”
  1. Avataaar/Circle Created with python_avatars Nguyễn hải says:

    You try to give the video more brightness it will be great if you do

  2. Avataaar/Circle Created with python_avatars Yusra Ejaz says:

    You try to give the video more brightness it will be great if you do

  3. Avataaar/Circle Created with python_avatars Morten Lund says:

    You can not get enough thumbs up for this one. Thank for your great way of teaching. And inspiring attitude. And humor. And much more.

  4. Avataaar/Circle Created with python_avatars Bunker Squirrel says:

    Love it. Thanks for the tutorial!
    We learned off a 20+ year old iteration of Pspice at uni. Worked well but the app code was really starting to show its age. Glad to see some companies are still giving circuit sim some TLC!

  5. Avataaar/Circle Created with python_avatars electronic home says:

    Thanks Dave, 8 years later!…

  6. Avataaar/Circle Created with python_avatars Sun Flower says:

    As always Dave, great piece of work. Your forum is always a platform to learn new things.

    Thanks for the input

  7. Avataaar/Circle Created with python_avatars Matthew P says:

    U make LT so easy and it really isn't that complex of a program

  8. Avataaar/Circle Created with python_avatars INC says:

    nice!

  9. Avataaar/Circle Created with python_avatars Simon Bramble says:

    excellent tutorial. Thanks for spreading the word!

  10. Avataaar/Circle Created with python_avatars richardnanis says:

    Very good tutorial – do more on LTspice please! One correction: at 15.10 to 15.25 its the other way round with temperature and voltage i guess 🙂

  11. Avataaar/Circle Created with python_avatars Sardor Israilov says:

    thanks a lot! do you know how to make a graph of voltage over temperature

  12. Avataaar/Circle Created with python_avatars mohammad sawaftah says:

    thank you for the great tutorial
    it would be great if u could help me with the following question:

    how can i simulate a detector (sensor "resistance" that change it's value over temperature)??
    that mean's the resistance should change with different temperature

    thank you very much

  13. Avataaar/Circle Created with python_avatars Redal Khummi says:

    how to plot voltage versus temperature?? am having trouble doing that.

  14. Avataaar/Circle Created with python_avatars Hola! Varsha Bendre says:

    Thanks for sharing this, I learn something useful about parameters sweep

  15. Avataaar/Circle Created with python_avatars PirateKitty says:

    I wish I had a bigger thumb to give.. Learned about temp sweep. Didn't know it existed. It pays to watch Dave's videos.

  16. Avataaar/Circle Created with python_avatars Popart 2015 says:

    I would like to see an Astable Multivibrator circuit simulated, something never saw on Youtube due to the no variability of components in a simulated environment with the consequent fail in the simulation of such circuit!

  17. Avataaar/Circle Created with python_avatars Trix Kemuel says:

    Thanks for this. I learned something useful. Didn't know I could step params.. I was looking for a variable pot or switch like the old electronics workbench, but this .step thing can be used to achieve similar results. Thank you.

  18. Avataaar/Circle Created with python_avatars Music Lovers says:

    Can we use temperature without sweep???
    i.e. single temperature value.
    If so….then how???

  19. Avataaar/Circle Created with python_avatars 8 Bits says:

    I must agree with you Dave, I love LTSpice, not only is it free but it is accurate and easy to use, compared to others like CircuitLab and EveryCircuit, neither of which are free, and neither are full-blown SPICE simulators. Not only that but you can add in various manufacturer's component databases, which is very handy for simulating circuits without Linear Tech's own devices. 10/10 IMO

  20. Avataaar/Circle Created with python_avatars Matt Tisler says:

    Thanks so much. That was awesome!

  21. Avataaar/Circle Created with python_avatars Sasha Gazman says:

    Thanks for sharing!

  22. Avataaar/Circle Created with python_avatars Tom Burke says:

    If you know there's only one "bias point," Instead of doing a transient sweep to get node voltage (as you are doing in this case), you cat do an operating point calculation.

  23. Avataaar/Circle Created with python_avatars Tom Burke says:

    the temp won't be in C – it's kelvin, I believe…

  24. Avataaar/Circle Created with python_avatars Robert Thurman says:

    I know this is old but if you haven't gotten an answer yet… monte carlo is also available – "mc(val, tol)" command.

  25. Avataaar/Circle Created with python_avatars Pablo88 says:

    How can I identify in the graph which trace correspond to which parameter value?

  26. Avataaar/Circle Created with python_avatars gamccoy says:

    I really liked this one. Good job.

  27. Avataaar/Circle Created with python_avatars MichaelJE2 says:

    Sounds like a good series! 😀

  28. Avataaar/Circle Created with python_avatars rapsod1911 says:

    Bandgaps.asc is good example of temp effect on electronics.

  29. Avataaar/Circle Created with python_avatars CampKohler says:

    The temp varied for the entire ckt, but obviously every component is not going to have the same effect on the ckt; some parts will have little effect on the output and some will have a large effect. When the output varies with temp more than you want, how can you find out which part(s) is the villan?

    Wouldn't it be neat if they applied color to the schematic, showing which parts had the most effect (sort of like an IR photo)?

  30. Avataaar/Circle Created with python_avatars Hola! Peter Camilleri says:

    50 videos is too much, but it would be nice to continue pointing out useful bits like this.

Leave a Reply

Your email address will not be published. Required fields are marked *