How to Simulate Your Circuits

It can be a lot of work designing a circuit. Especially since you have to measure several different points at a time and you may need to quickly change out components. The quickest way to do this with a real circuit is perhaps with a breadboard. There is a faster way though, and that is computer simulation. A simulation allows you to quickly fine tune your circuit, and I’d say that it’s the easiest way to start making a circuit. So stay tuned, and I’ll show you a few different ways to get started with simulation. Let’s dive in.

Falstad

The easiest simulator to get started with is the Falstad circuit simulator. Go to Falstad.com and click on the circuit simulator link. Feel free to click on the full screen version if you’d perfer a full-screen experience. There will be an example circuit already running. Feel free to modify it or delete it.

Building your circuit is really quite easy. Go to the draw tab and find whichever component you need. For example, if we want to test ohm’s law, we can get a voltage source and ground from the ‘Inputs and Sources’ menu. Then we can get a resistor from the ‘Passive Components’ menu. To measure your circuit, either hover your mouse over the component and read from the bottom right corner or get a voltmeter and ammeter from the ‘Outputs and Labels’ menu. As you can see, the circuit correctly simulates this voltage divider with half the input voltage.

Let’s try building something more complicated. Place an op-amp in a non-inverting configuration and place an AC voltage source on the input. If you don’t what that means, watch my previous two op-amp videos for a better understanding. Let’s give the op-amp a gain of 10x by using a 1k and a 9k resistor. Make the AC voltage source have a max voltage of one. Now, let’s right-click on the voltage source and click on ‘view in new scope’. And as you can see, you now have a virtual oscilloscope. Now right click on the bit of wire on the output of the op-amp and view it in a scope. As you can see, the output voltage is 10 times larger than the input, just as it should be.

There is a lot more that you can do with this simulator. The oscilloscopes have a lot of options, and I recommend looking through them all to understand what you can do. There are also several more components, including everything from transistors all the way up to basic digital logic blocks. There are also example circuits that you can look through and get inspiration from.

So what do I think of the Falstad simulator? Well, I really like it. I use it myself to quickly put together and test an idea that I might have. It does fall a bit short to the more powerful tools though. It lacks some functionality that I will demonstrate in the next section. It can also be difficult to properly model a specific part that you’d like to use in Falstad, and you’re kind of stuck with the components that the simulator gives you. If you’re new to circuit simulation, you should try this one out. Especially since don’t even have to download anything!

SPICE

Let’s talk about the beast that is SPICE. SPICE stands for Simulation Program with Integrated Circuit Emphasis. SPICE is an old program that is the engine behind many of the world’s best circuit simulators. Under the hood SPICE is simply a netlist, and you can use a program such as ngspice to write these nets out. This is a bit impractical though, and it’d be better to visually see your circuits. The next two programs are versions of SPICE with good frontends.

LTSPICE

LTSPICE is probably one of the most popular circuit simulators. It’s completely free to download from analog.com. It’ll seem a bit ugly the first time that you see it, but you’ll get used to it. It’s also worth noting that there was recently an update to LTSPICE. That’s why you’ll find a visual difference between your version and videos made with the old version. They did improve the user experience quite a bit, and they fixed the keyboard shortcuts. For example, before the update placing a wire was the F3 key and now it’s the W key. If you don’t like the new look and feel of things, feel free to go into the settings and revert the toolbar, keybinds, and the background image to legacy. It’s all a matter of preference anyway.

Enough talk about preferences and let’s get to the point. Make a new schematic so that we can do the basic Ohm’s law test. Grab two resistors, a voltage source, and ground. Place them all in the shape of a voltage divider. Right click on the components to change their values. For example, right click on the voltage source to give it a value. Do the same with the resistors. Now let’s try testing our circuit.

Click on the simulate menu and go to configure analysis. The default menu you’ll see is the transient analysis tab. This type of analysis let’s you see the activity in the circuit over time. Set the stop time to ten microseconds. When you click OK, you’ll get to place this text. This is a SPICE directive, and it’s basically a command that you send to the backend SPICE program. Either way, let’s run the analysis by clicking on the green arrow. An oscilloscope window will appear at the top half of your screen. At this point you can probe around your circuit. Click in the middle of your voltage divider and you should see half of your voltage supply on the readout. If you’d like to see the current through the resistors, click on the edge of one of them to get this current probe.

Since this is a completely DC circuit, you can also try using the DC operating point analysis as well. The output isn’t as nice to read as the scope, but it’s an option if you’d like to know what the DC component of your circuit is. This leads quite nicely into the next kind of DC analysis, which is the DC sweep. Basically, a DC sweep will increment through all of the DC values that you specify at your increment. For this example, set the start voltage to zero and the stop voltage to 10. Set the increment to 100m. And, of course, our voltage source is V1. Now let’s run our analysis and select the middle of our voltage divider. You’ll see that the horizontal axis is now the voltage on the voltage source. And you’ll also see that our measured voltage is half of what the voltage source is. This kind of analysis is useful when you need to understand the behavior of your circuit over a range of voltages.

While DC is interesting, let’s really show the power of LTSPICE and do some AC analysis. For this, we are going to remove the current circuit and instead replace it with a low pass filter. Use a resistor and a capacitor for this. Make the resistor 2.2k and the capacitor 1nF. To get an AC voltage source, simply click on our old DC voltage source and click on advanced. Here, you can select the SINE function from the list. Give it a DC offset of 1 volt, an amplitude of 5 volts, and a frequency of 100kHz. Ncycles is simply the number of times you want the sine wave to happen. Since we don’t want the since wave to stop, just set this to a big number. Leave the other entries blank.

Configure your analysis and change it back to transient. This time make the stop time 50us. Run the simulation and probe the AC voltage source and the output of the low pass filter. You should hopefully see the original sine wave along with a smaller and phase shifted sine wave. This transient analysis is definetly useful, but there is still a lot more that we can do.

An AC analysis is basically a sweep of the frequency of an AC signal and it measures the gain vs frequency. To set it up, first go to your voltage source and fill in a one in the AC amplitude box. This will configure your voltage source to be swept for the AC analysis mode. Next, configure your analysis to the AC analysis. At this point, you can choose the type of sweep. An octave sweep will divide the analysis into factors of 2. For example, the analysis will go through 1Hz, 2Hz, 4Hz, 8Hz, etc. A decade sweep will do the same thing but with a power of ten, so 1Hz, 10Hz, 100Hz, etc. A linear sweep will just go through the entire frequency range. And a list is where you can specify which frequencies you want by hand.

I’ll go with a decade sweep since it is the most natural combination with a logarithmic axis. I went with 50 points per decade so that we have a good amount of data. The starting frequency is 100mHz and the ending frequency is 10MHz. Use the Meg suffix for this purpose. Click OK and run the analysis. Probe the output and you will see this plot. You can call this type of plot a Bode plot, where the output gain is a function of input frequency. You’ll also notice the phase shift that is marked as the dotted line. Let’s find the cutoff point of this low pass filter. Remember, the cutoff point for any filter is when the output gain is -3dB. To assist in finding this, simply click on the label to enable the cursors. Drag them until you read just about -3dB on the magnitude in the pop-up menu.

You should see that at -3dB, the frequency is 32.6kHz and the phase shift is -45 degrees. This is exactly what we should expect from a filter like this. Now, this was a very basic circuit and analysis, but let’s try examining a more complicated circuit. To build the following circuit you’ll need to know a couple of things. First, you can select every component you need from the component menu. For example, we will use npn and pnp transistors, as well as a current source. Second, you can select specific parts to model with the transistors by right clicking on them. I selected the 2n3904 and the 2n3906 since they are the transistors that I might use in an actual project.

With that I’ve built up a discrete op-amp of sorts, and it’s configured with a non-inverting gain of two. If you want to know how I came up with this circuit, please watch my previous op-amp video. Either way, hopefully you can still follow this analysis. In the transient anaylsis, you can clearly see how it gains correctly this 200Hz signal. What about at other frequencies? Well, let’s go to the AC analysis mode to find out. Let’s analyze all the way up to 100MHz. And wow, we can see that the gain remains a constant 6dB (which is the same as a voltage gain of two) all the way until something like 200kHz. One of the limiting factors of the gain currently is the compensating capacitor.

It would be great if we could test different capacitor values to see how it affects our frequency response. To do this, we can use a step directive. Press ’s’ or this button to bring up the spice directive menu. Type in this directive here: .step param C 1p 100p 10p. After you place it you can now right click on it to get a cleaner menu for it. This basically steps a variable C through the values 1p to 100p in 10p increments. Now we need to assign this variable C to our capacitor. To do this, simply replace the 30pF value with the C wrapped in curly braces. Now when you run the simulation, you’ll see several different colored lines, with each one representing a simulation in which a different capacitance value was used. To make things a bit cleaner, remove the phase shift lines by right clicking on the axis and clicking don’t plot this.

If you want to look at a specific line, simply right click and go to View > Select Steps and choose which lines you’d like to focus on. For example, we can focus on the 1pF line, which is the green one. But let’s go back to this plot with every line on it. As you can see, increasing the capacitance decreases the maximum frequency. The tradeoff is that too low of a capacitance will make the amplifier unstable at higher frequencies, as you can see by the increased gain on the green line.

You can use this step directive for any other component as well, so keep it in mind. Overall, I’d say that LTspice is an amazing tool that you can use to analyze and simulate circuits. It’s free and is very popular, so there is a lot of support online that you can use. A drawback could be that the user interface is a bit dated, but you can get used to that.

PSPICE (for TI)

Now, like I mentioned earlier, there are several different ways in which you can use SPICE. LTspice was the analog devices version. TI offers a version themself with the TI version of PSpice. The TI version of PSpice is free, but it comes with the limitation that you are limited to only probing three connections if any non-TI parts are used. The regular version of PSpice doesn’t have this limitation, but it isn’t free either. To download it, simply go to the page on TI’s website and request it. You will have to make an account.

Anyway, let me show you the basics of Pspice. First, create a new project and make it blank so that you can understand how to design a circuit from scratch. Since we are using a TI focused version of spice, let’s use a TI part. In the search bar, look for ‘828’. From here, select the OPAx828. This is one of TI’s op-amps. Using this op-amp, we are going to make an integrator circuit. First, place your resistors. You can find them by going to Place > PSpice Component. We are going to need to make a voltage divider on the non-inverting input. For the inverting input, simply place one to the side. Afterwards, place a capacitor from the inverting input to the output. You can find the capacitor in the same place as the resistor. The resistor divider should have both resistors as 1k. The other resistor should be 47k and the capacitor should be 10nF.

Now we need some voltage sources. They are in Place > PSpice Component > Source > Voltage Source. We need one DC source and one Pulse source. The DC source will be the op-amp’s power supply. Make it 5V. Press ‘g’ to get your ground label. Place it on your voltage sources and the op-amp. Now go to the side bar and click on net alias. This will allow you to connect two points by name. Name this net ‘VDD’ and place it on your voltage source and on the op-amp. The pulse source is basically how you can make a square wave. Make V1 0 volts and V2 5 volts. Leave TD blank, since it’s simply a delay. TR and TF are your rise and fall times. Set them both to 1us. Set PW to 49us. This is basically how long your signal will remain HIGH for. Finally, set PER to 100us. PER is the period of the pulse. To wrap things up, select the voltage probe at the top and probe the output of the op-amp. The probe is how you will see your signal in the simulation.

To start a simulation go to the PSpice tab and click on ‘New Simulation Profile’. Give it a name and press create. By default, it will be configured as a transient simulation, which is what we want. Make the simulation run for 10ms and press OK. To run our simulation, go to PSpice and Run. A new window will pop-up with your simulation. If it’s your first time running an analysis, it might take a little while longer to set things up. If you placed your voltage probe properly, you should see this pattern on the screen. If not, go back to your schematic and double click on the probe. To zoom in on a later part of the simulation, click and drag the rectangle over where you’d like to see, then click the zoom area button.

Add another probe to take a look at your input signal. As you can see, it’s a square wave. This means that our circuit works as intended since an integrated square wave is a triangle wave. Take’s take a look at the spectral makeup of these signals. Click on the FFT button at the top. As you can see, the input square wave has several harmonics beyond the 10kHz mark. But if we zoom in on the triangle wave, we will find that all of the harmonics have been greatly diminished. This is because an integrator has the same effect as a low-pass filter. But we aren’t just stuck with an FFT plot, go and edit your simulation settings.

Change the analysis type from transient to AC Sweep. Make a logarithmic sweep and set it to decade. The starting frequency should be 1Hz and the ending frequency should be 10MHz. Run 50 points per decade. Delete the pulse source and change it to an AC souce. Make the DC offset 2.5 volts to match the non-inverting input of the op-amp. Give the input a net label called Vin and delete the voltage probes. Now you are good to run the simulation.

When the simulation window opens, go to Trace > Add Trace. In the trace expression, type this: DB( V(Out) / V(Vin) ). Make sure that the label names match what you have in your schematic. When you plot it, you will see a typical Bode plot. And in typical low-pass filter fashion, the gain of the circuit drops as frequency increases.

That should be enough to get you started with PSpice. As you could see from my demonstration, it takes a lot of setup to get it working, especially compared to LTspice. PSpice is a big program, and I say that in both a good and a bad way. It’s big in a good way since it is well suited for making large projects since it allows for organization of parameters and multiple schematic pages. It’s big in a bad way since, well, it’s a bit bloated. Things are slow, both in terms of loading everything and also clicking all of the buttons needed to get a simulation up and running. One annoying thing that I haven’t shown in the video: PSpice has this habit of having the simulating component crashing, and the only way to fix it I’ve found is to just restart the whole program. As you might think, it got really annoying.

Should you use PSpice? Well, I’d say if you are planning to make a project centered around TI parts, then yes, considering that you are using the free version.

Well, that should just about cover it for circuit simulation. If you’ve enjoyed this video, please consider subscribing so that you can see my future videos. Also visit my buymeacoffee page. With your support I can keep making these videos. I’d like to take a moment to thank Mr. devNull, Cognisent and Mark for being channel supporters. You make these videos possible. Thanks for watching, have a good one!

 Share!