Explore KiCad 8.0's powerful simulation features: learn, simulate, and build circuits effortlessly.

Make Simulation On Kicad 8.0 : My Favorite Tool - Chauchat Eymeric
Make Simulation On Kicad 8.0 : My Favorite Tool - Chauchat Eymeric

I'm thrilled to share my simulation library on KiCad with you today. Yes, simulations are possible on this fantastic software! Let's explore this together.

Introduction

KiCad is a favorite among electronic enthusiasts for various projects, ranging from microcontroller boards to PCB antennas and even 8-bit computers. Although it might not be widely recognized for its simulation capabilities in forums, this open-source software actually boasts remarkable simulation features!

In this article, I'll explore how KiCad manages simulation and its capabilities. I'll also offer tips on finding simulation models online and share my personal KiCad library, which includes example projects for each component.

For this article, I am using KiCad Version 8.0.0, release build.

KiCad as a Simulation Tool?

KiCad supports a range of simulators, including LTSpice, PSpice, and HSpice. What does this entail? Essentially, KiCad can run nearly every standard simulation model available from manufacturers. In my experience, most of these models are PSpice models.

Let’s Dive into KiCad’s Simulation Features

The Schematic editor is where the magic happens. Here, we can define various types of components:

  • Simulated electrical components (e.g., your favorite OpAmp, resistors, capacitors, inductors)
  • Non-simulated electrical components (e.g., decoupling capacitors, connectors)
  • Simulation components (e.g., simulation ground, voltage sources)

To configure the behavior of each component in your schematic, go to the Attributes section in the Symbol property panel by pressing the ‘E’ key while selecting a component:

Symbol Properties - KiCAD 8 

Symbol Properties - KiCAD 8

  • Simulated electrical component: nothing ticked
  • Non-simulated electrical component: Exclude from simulation ticked
  • Simulation component: Exclude from BoM and board ticked

A Component Example: The Potentiometer

Consider this scenario: You want to incorporate a varistor or potentiometer into your circuit to set a precise voltage threshold. While these components are relatively simple, they do have specific parameters. Exploring their behavior within KiCad’s simulation environment is a great way to understand how KiCad performs circuit analysis and validation.

schematic we have a voltage source (Simulation component) and our Trimmer resistor

In our schematic, we have a voltage source (Simulation component) and a Trimmer resistor. Let's delve into the simulation parameters for the Trimmer resistor (accessible via the component properties).

How Kicad interpret this component for the simulation
How Kicad interpret this component for the simulation

In the Model section, KiCad uses the component model VARYSTOR from a SPICE file named VARYSTOR.lib. This model includes two parameters, Rtot=1k and Part=0.5. Upon examining the pin assignment, it is clear that each pin is correctly assigned to its corresponding symbol pin. For a trimmer resistor, the Wiper pin represents the variable output of our potentiometer, ensuring proper symbol configuration.

In-Schematic Parameter Setup

Notice that our model has two parameters, Rtot and Part. Typically, KiCad stores these parameters in the Simulation Model Editor. However, we can link these parameters to allow direct modification in the schematic editor, as shown in the first picture.

In-Schematic Parameter Setup

You need to add a field called Sim.Params with the different parameters separated by space, formatted like this: name=value.

Diving into Spice Coding

Crafting this model myself provides valuable insights into its operation! Spice code stands out from other coding languages; each line delineates a component with its type, name, connections, and function.

For a comprehensive understanding of Spice, it's best to explore manufacturer libraries and Spice manuals to uncover the multitude of possibilities it offers. However, it seems there's a scarcity of resources available online for learning Spice programming…

Now, let's delve into Varystor.lib:

<p>.SUBCKT VARYSTOR CCW Wiper CW Rtot = 10e3 Part = 0.5
*I define a sub component called VARYSTOR with CCW Wiper CW as connection and base parameter value Rtot = 10e3 and Part=0.5
R1 CCW Wiper {Rtot*Part}
* I put a Resistance called R1 between CCW and Wiper of Value Rtot*Part
R2 CW Wiper {Rtot * (1-Part)}
* I put a Resistance called R2 between CW and Wiper of Value Rtot*(1-Part)
.ENDS
* end of the sub component definition</p>

In KiCad, I've opted for the subcomponent VARYSTOR to depict the actual model of my component.

When acquiring a Spice model from a manufacturer, it's common to have to construct a subcircuit (subckt) with the correct pin arrangement and the requisite number of channels. For instance, if you're seeking a model of a quad OpAmp, you might only locate a 1-channel model in the PSpice library. In such instances, you would need to generate a 4-channel subcomponent to faithfully represent it:

.SUBCKT TLV9062_Mono IN+ VEE IN- OUT Vcc
*I define a sub component called TLV9062_Mono with IN+ VEE IN- OUT Vcc as connection
XU1A IN+ IN- Vcc VEE OUT TLV9062
*I put a component called XU1A that have connection IN+ IN- Vcc VEE OUT and follows the behavior of the (sub)component TLV9062
.ENDS

.SUBCKT TLV9062_Dual OUT1 IN1- IN1+ VEE IN2+ IN2- OUT2 Vcc
*I define a sub component called TLV9062_Dual with OUT1 IN1- IN1+ VEE IN2+ IN2- OUT2 Vcc as connection
XU1A IN1+ IN1- Vcc VEE OUT1 TLV9062
*I put a component called XU1A that have connection IN1+ IN1- Vcc VEE OUT1 and follows the behavior of the (sub)component TLV9062
XU1B IN2+ IN2- Vcc VEE OUT2 TLV9062
*I put a component called XU1B that have connection IN2+ IN2- Vcc VEE OUT2 and follows the behavior of the (sub)component TLV9062
.ENDS

.SUBCKT TLV9062_Quad OUT1 IN1- IN1+ VEE IN2+ IN2- OUT2 OUT3 IN3- IN3+ Vcc IN4+ IN4- OUT4  
XU1A IN1+ IN1- Vcc VEE OUT1 TLV9062
XU1B IN2+ IN2- Vcc VEE OUT2 TLV9062
XU1C IN3+ IN3- Vcc VEE OUT3 TLV9062
XU1D IN4+ IN4- Vcc VEE OUT4 TLV9062
.ENDS;

Simulation Panel

With your circuit complete, it's time to initiate the simulation. To begin, open the simulator panel, accessible from the Inspect tab.

Simulation Panel

Before running the simulation, it's crucial to configure your simulation environment in the Simulation Command menu. Here, you can select from various simulation presets. For FSAE boards, my preference is transient simulations, which track the circuit's behavior over time. Ensure you choose the appropriate compatibility mode; PSpice and LTSpice modes are typically suitable for most simulations.

Once configured, simply click 'Run' to start the simulation. You can then monitor different signals by using the Probe tool to click on the wires in the schematic.

Spice Simulator

To conduct further analysis, you have the option of saving all data in a CSV file for thorough examination. Alternatively, within KiCad, you can use cursors to inspect signals directly by simply clicking on the signal where you wish to place a cursor.

Building Your Own Library

In this section, I'll offer some advice on building a library or selecting components for your project. While I'll delve deeper into this topic in a dedicated article later, here are a few helpful tips:

For hobbyists, it's advisable not to go lower than 0603 resistor/capacitor sizes to avoid difficulties. Consider purchasing a set of resistors and capacitors as it simplifies the process. Utilize SMD LEDs for their brightness, affordability, and versatility. Focus on a few common component packages such as SOIC, SOT-23, SC70, and TSSOP. Only buy components that are in stock and not marked as End of Production. 2.54mm pitch connectors are quite common, while THT connectors offer more robustness. Opt for high-end voltage regulators to withstand mistakes and prevent damage from short circuits. Refer to the Typical Application section in datasheets to avoid errors. Finding Symbols and Spice Models

Symbols for KiCad components can typically be found using specialized search engines like Component Search Engine and SnapMagic. If your component isn't available in these resources, it may be uncommon, requiring you to explore alternative options.

Finding Spice models can be trickier. Generally, components like Mosfets and OpAmps are available on the manufacturer's website, sometimes in less accessible areas. For transient simulations, highly precise models may not always be necessary, so general models like D-Latch and NE555 can suffice.

Formatting Your Library

After selecting and importing symbols into your library, ensure consistency across all components. Check fields such as Datasheet, Manufacturer_Part_Number, Mouser Part Number, and correct PSpice simulation input/output.

My Library

Introducing my Simulation library for KiCad, packed with simulations for standard and highly useful components! The library includes components like Comparators, OpAmps, D-Latch, Diodes, Resistors, Capacitors, logic gates, transistors, and more.

Example Simulation Files

I've prepared example files for various components and use cases, including Buffer OpAmp, Comparator, D-latch initialization, Pspice Initial Condition, SCS Dual Comparator, and Trimmer resistor.

Installation Instructions

To get started, simply download the archive and import the symbol library (Basic_SPICE.kicad_sym) and the footprint library (Basic.pretty). Set up custom paths in preferences for smooth simulation and correct 3D display.

Annexes

I'm working on another library for non-simulated components (Basic_UTIL) and have included helpful internet resources in the help folder. Eventually, everything will be stored on GitHub for easy access.

Download Link

You can download the latest version of my library from the provided link.

Download Here

source

Next Post Previous Post
No Comment
Add Comment
comment url