# Monte Carlo Simulation using LTspice with Step by Step Tutorials

LTspice is a very good circuit simulation tool for electronic circuits. Thanks for Linear Technology for sharing such a nice tool. In this article I will teach Monte Carlo Simulation using LTspice with Step by Step Tutorials. Monte carlo is an analysis method used by design engineer to increase the robustness and reliability of their products. It is all about tolerances.

Our circuit model in this monte carlo simulation  is a comparator as shown in Figure 1 below. Let all resistor tolerances equal to 3%. We will use 5% as the tolerance of V4.

Figure 1

## Defining the Circuit Operation

The circuit is a comparator. The output will be zero if the value of Vref is higher than Vin+. The output is high or equal Vcc otherwise. In this tutorial we will find out what is the voltage range of Vin wherein the output changes state from low to high. I mentioned voltage range because we are dealing here with tolerances. Initially the output is low because Vcc is already stable before the level of Vin starts to rise. We can simulate this using DC sweep command. We are going to sweep the level of Vin from 0V to 20V and observe the voltage range when the output changes state.

## Monte Carlo Simulation using LTspice Step by Step Tutorials

### Step 1. Open LTspice Software

We will start the Monte Carlo Simulation using LTspice by of course opening your LTspice software. If you don’t have one yet, click here to download . Once the program is running, start or open a new schematic.

### Step 2. Start Placing Components

If you are a 100% naive on LTspice, consider reading this post.

Get the supplies V3 and V4 from

Another way to display above window is by clicking “F2” in your keyboard.

Get the resistors here

Or by simply typing letter “R” from your keyboard.

Get the opamp here

Double click opamps to select specific device.

To put a net name such as Vcc, Vin and Vout, click icon below and type the name.

Another approach to put a net name is by pressing “F4” in your keyboard.

### Step 3. Arrange and Wire the Circuit

Click this to draw a wire and start connecting components.

Another method is to press “F3”. To put a ground, click the symbol on the right of the wire symbol above.

### Step 4. Changing Component Label

You can change component label if you want to by right clicking on the default component name and then encode a new name then OK. Do not include space.

### Step 5. Setting the Component Values

For V4 the value is 5V with 5% tolerance. To put this on the circuit right click on the V4 value which is “V” by default. In LTSpice the component value is always below the label by default. After you right click, type this

{mc(5,tola)} and click OK.

Do the same method to resistors. At this time use “tolb”. By the way, tola and tolb are just the name we use to represent the tolerances. You can change these if you want, just don’t include space.

R595 : {mc(2.49k,tolb)}

R598 : {mc(13k,tolb)}

R596 : {mc(4.7k,tolb)}

R597 : {mc(1.5k,tolb)}

R594 : {mc(30k,tolb)}

R599 : {mc(4.7k,tolb)}

### Step 6. Define Spice Directive

Spice directive is the one making the execution. In order for the variable “tola” to become functional we will make a spice directive for it. To do so press letter “T” on the keyboard and below window will show.

Tick “Spice directive” and type the command

.param tola=0.05

Click OK.

Do the same method for “tolb” and click OK thereafter.

.param tolb=0.03

Then make another spice directive to execute a monte carlo run as below

.step param run 1 100 1

The above syntax means that we are going to run the simulation for 100 times with starting point at 1 and the increment is 1.

We already created three spice directives for the tolerances and the monte carlo run. Next is to setup the DC sweep command.

### Step 7. Setup the DC Sweep Command

Since we want to know the values when the output turns to high, we are going to run a DC sweep of the value of V3. To setup a DC sweep, go to “Simulate” then “Edit Simulation Command”

Follow below window then click OK right after.

With the above setting, we are about to run a DC sweep from 0V to 20V with a voltage increment of 0.1V. The source we are going to sweep is V3 which is labeled Vin in the schematic.

### Step 8. Run the Simulation

After all the settings and configurations are done, you are now ready to run the simulation. To do so, go to “Simulate” then “Run”

Or click this

This is the result

You can run also a transient command. To do so, go to “Simulate” then “Edit Simulation Command” then select “Transient”. Follow below data.

1. Brian Dohler says:

Great article, which has potential to be very useful. Couple of questions, of course.
1. How does one interpret the results? If I build 100 circuits, these are my likely “realistic” bounds? Is it possible to expand on this to 1000 or 10000 without actually running the simulation that many times?
2. Can this method be expanded on to include the input offset voltage on the comparator? How does it work with more complex components?
3. Can this method work with different distributions?

2. Edward Pongracz-Bartha says:

Can the resistors and other passive components have different tolerances? Also, do you get to do tolerance with diodes and LEDs?

1. electronicsbeliever says:

Yes, they can have different tolerances…you can model diodes are voltage drop and then you can put tolerance.

3. Edward Pongracz-Bartha says:

I appreciate knowing that each component can have its own tolerance.

4. Thanh says:

How can you tell from figure 19 which Monte Carlo wave corresponds to a component tolerance?

5. Amrita Dikshit says:

How can we do montecarlo simulation if we have MOSFETs instead of resistors??

6. SLP says:

I tried this circuit, It didnot work. I had to change the value of resistor R595 to 5k. Then it worked. Could t=you please explain.

This site uses Akismet to reduce spam. Learn how your comment data is processed.