Free KiCad Filter Capacitor Layout Simulation
by Renato Panic in Circuits > Arduino
39 Views, 0 Favorites, 0 Comments
Free KiCad Filter Capacitor Layout Simulation
Simulating a simple capacitor in LTSpice, complete with its series inductance and capacitance, is straightforward. But when it comes to incorporating the PCB traces and surrounding environment, things can quickly turn into a nightmare! In this Instructable, we’ll take the leap into full 3D simulations to explore various capacitor layouts in detail.
By the end, you’ll discover which layout performs best—and the results might just surprise you. Have you heard of the anti-parallel layout style? Or do you know why 3-terminal capacitors excel? Let’s dive in and uncover the answers together!
Supplies
The amazing thing about using a simulation is that no physical supplies are needed. But you have to install some free software tools. With free i mean completely free, even for commercial use.
Please download following software tools - please use exactly the same versions as described, because for me even the slightest change of the software versions resulted in errors:
1) KiCad 6.0.11 - if you are a first time user please use KiCad 6 to avoid any dependency problems
2) FreeCAD 0.19.4 - please use version 0.19.4 to avoid any dependency problems.
3) openEMS v0.0.36 - here is a full tutorial on how to install it: openEMS installation tutorial
4) ParaView 5.12.0 - we will use this application to view our simulation results
Prepare Your KiCad Layouts
Download the KiCad projects from the google drive link.
The subfolder "_kicad-layouts" contains the layout files for KiCad.
If you can open the first KiCad layout with the simple parallel layout as shown in the screenshot, you are ready go to to the next step.
Open FreeCAD
Open Freecad and start the FreeCad to openEMS macro.
If you dont know what that macro is, you did not watch the installation tutorial yet, watch it here.
Import the 3D Model of Your KiCad Layout Into FreeCAD
1) Click on the button "KiCad PCB Import Tool"
2) Select the KiCad File and enable the checkmark "Fuse copper ..."
3) Click on "Import KiCad PCB". The import will now take a while, the report view will give you an "all done" message once the import is finished
Create the Input and Output Ports for the Simulation
We will simulate the filter effeciency using the scattering parameter S21. S21 basically just tells you how much of the input signal is reaching the output. openEMS will calculate everything automatically, so we dont need any formulas.
1) A Remark: I have set the copper thickness to 0.2mm to speed up the simulation, but you can of course set it to 35 micrometers (typical value for a 2 layer PCB) in the layer stack menu of KiCad.
2) This image shows you where you would change the layer thicknesses in KiCad
3) Change to the parts workbench
4) Create a cube (this will be the input port)
5) Resize it
6) Move it into place
7) Rename the cube to "portin"
8) Create a copy of portin and call the new object "portout"
9) Move portout into place
We now created the ports, lets go to the next step.
Cover the PCB With Air
3D simulations need a simulation boundary and also a defined material around the PCB.
We will place the PCB into a airbox, please perform following steps:
1) Create a new box
2) Rename the box to "air"
3) Resize and reposition it so it covers the PCB from all directions. On the top side keep some distance to the components (final dimensions are in the screenshot).
4) To see through the airbox, you can change the transparency as shown in the picture
Create the Capacitors C1 and C2
The next step is to create the capacitors. Unfortunately, in KiCad 6, this needs to be done manually. However, I’m working on a tutorial to semi-automate the process. If you’d like to stay updated, follow me on Instructables!
Here’s how to create the capacitors:
1) Create a box for the first capacitor
2) Rename it to C1
3) Resize the box to match the dimensions of an 0402 capacitor from the German manufacturer Würth Elektronik.
4) Move the box into position
5) Duplicate C1 to create the second capacitor and rename it "C2". Adjust the position and size of C2 as shown in the screenshot.
Note: There’s a small gap between the capacitors and the copper traces. This ensures only the ends of the capacitors connect to the copper, preventing the bottom from touching it.
6) To define a series resistance for the capacitors, split each capacitor into two parts, one representing the capacitor and the other the resistor. This means you have to create two additional boxes for each capacitor, resize and position them and then rename them as “C1-series-resistance” and “C2-series-resistance.”
And that’s it—your capacitors are now set up!
Connect the Capacitors to the Copper
Next, we need to connect the capacitors to the copper underneath. Just create a few more boxes to serve as the connections.
Change to Full Copper Vias
1) We will now change from standard vias to full copper vias. This step is not a must, but it enourmously speeds up the simulation. The reason for that is that vias typically are only 10 to 30 micrometers thick , requiring a very fine mesh, which slows down the simulation.
2) Expand the copper object named "coppers_drilled#F.Cu."
3) Select the two child objects.
4) Fuse them using the union button.
5) The resulting shape has some unwanted extensions. To remove these, create a new box.
6) Position the box to cover the extensions.
7) Select the fused object first, then the box (hold CLTR to select both), and click on "Cut".
8) And there you go—full copper vias are now ready!
Clean Up the Component Tree
1) Select the copper fuse and the pads and fuse them together.
2) Mark the copper fuse object and the PCB object and create a simple copy of them
3) Delete the objects marked in red and keep the ones marked in green
4) Ensure the final object tree matches the one shown in the screenshot. Only simple objects should remain—these are objects without any child components.
5) Don't forget to save the progress!
Setup the Simulation and Generate the Simulation Code
1) Restart the FreeCAD to openEMS macro
2) Navigate to the Grid Settings tab and setup the grid
3) In the Material Settings tab, add "air" to the materials list
4) Add "FR4" to the materials list
5) Go to the Excitation Settings tab and add a sine wave excitation of 100MHz
6) In the Port Settings tab, add the input port
7) Add an output port
8) Open the Lumped Parts tab and create two capacitors
9) Add two series resistances with a value of 40 mOhm, a typical series resistance for 0402 MLCC capacitors. As mentioned earlier, the inductance is indirectly defined by the capacitor’s shape, so a lumped inductor is unnecessary.
10) Make sure the electrical direction is set to the y direction!
11) This is how the lumped parts tab should be set up.
12) Go to the Simulation Params tab and change the number of timesteps to 1. I will later explain the reason for this value.
13) In the Object Assignments tab, assign all the components
14) Save the settings file
15) The settings file will be saved in ".ini" format.
16) Generate the MATLAB code
17) Confirm the popup that appears after the code generation is completed.
18) In the Processing tab, generate the S21 code and confirm the popup once the code generation is finished.
Run the Simulation Code
1) Go to the simulation output folder and open the MATLAB code with Octave. If you're unsure what Octave is, watch the tutorial video on how to install openEMS, which also covers how to install Octave and run the code.
2) Click on run
3) confirm the prompt with yes
4) close the 3D preview window
5) after a few seconds the output window will show you how many timesteps are needed to simulate 1 full sinewave. copy this value and paste it as the new number of timesteps, which we initially have set to 1.
6) run the code again, confirm the prompt with "yes" again, close the 3D preview again and wait for the simulation to finish.
7) This screenshot shows how the simulation window should look like once the simulation is finished.
8) Now open the S21 matlab code with Octave
9) set "save_plot_data" to 1. This will enable the creation of a ".csv" file after the S21 matlab code is finished running.
10) click on Run
11) Once the simulation is finished, a popup will be created with an empty graph. Dont worry and go to the next step.
12) go to the simulation output folder and open the csv file
13) In column B we finally have our S21 value for 100MHz. A value of -47dB means that at 100MHz, the input signal gets weakened by 47dB or by a factor of more than 200. If this is a lot or not really depends on the context.
14) I created a new excel sheet and inserted the first simulated value.
15) Now the only thing left is to repeat the simulation for other frequencies and create a new excel sheet with the summary of the results. This screenshot shows the final values for the parallel layout.
16) Create a graph from the values and you see the filtering effect over frequency. Attention: If you want to see the typical V shape, you have to set the x and y axis to logarithmic scale.
Simulation Result Comparison
After repeating the simulation for different layouts, you see following graph. Did you ever hear of the antiparallel capacitor layout with 90 degree rotation? Well at least based on the simulation it performs the best. A source on the internet claimed the same and now I finally did a simulation of it and came to the same conclusion.
Why Is a Simple Parallel Layout Peforming So Poorly
The main reason is that the fields around a trace expand into all directions. The image shows how the H-Field (magnetic field) progresses over time. As you can see the H-Field is filtered by the capacitor on one side, but some of the H-field can pass the capacitors relatively unhindered on the other side that I marked in red.
Why Is the Butterfly Capacitor Layout Performing Better
The shortest explanation is that it catches the fields that extend around the trace from both sides.
The image shows the electric field strength (E-Field) around the trace. The field is actually the strongest right inbetween the trace and the ground plane on both sides of the trace (see red circle in the center).
The second image shows a typical 3 terminal capacitors filtering characteristic. A 3-terminal capacitor is basically a butterfly layout in a single package, it is so good filtering high frequency noise as it shorts the high frequency fields to ground at both sides of a trace.
Why Is the Antiparallel Layout Performing Even Better?
A few sources on the web claim that the antiparallel layout improves filtering efficiency as it forces the current in both capacitors to flow in opposite directions. Opposite electric currents generate opposing magnetic fields, which cancel each other out to some extend. This means that it avoids common mode currents of building up.
I am also not yet sure how this helps in our specific scenario, so I will definetly post an update regarding this topic once I made some more simulations about how the high frequency current is flowing in the test circuits -> Are you already following me on Instructables?