top of page
circuit.jpg

I began learning EE through Khan Academy followed by constant experimentation designing various circuits in a circuit simulator, including basic Tesla coils and different DC-DC switching converters. Later, I learned to design PCBs to have my circuits manufactured, including a CNC control board for an electrochemical CNC machine I created for the science fair. This lead me to create my own analog circuit simulator capable of simulating circuits with linear, passive components.

Background

    This project was strongly inspired by the Falstad Circuit Simulator, which is reflected in the UI design. I wrote the matrix​ library for this project myself, and initially derived all of the math myself from the manual node voltage method, although I later updated the way resistors work slightly to make them more efficient after reading about the way Falstad handles them.

​

    The circuit simulator I created is based on the node voltage method of circuit analysis. A circuit is modeled as a collection of nodes, where each node has a voltage, and a current flowing into it. A matrix describing a linear system of equations is constructed which converts from node voltages to node currents. Since the node currents are known and the node voltages are unknown, this matrix is inverted using Gaussian elimination. Components are added by adding rules to this system of equations.

​

Here is a video showing the simulator in operation:​​

Components

If equations don't load properly reload the page.

​​Resistors

Resistors work by adding the difference in voltage between the two nodes the resistor is connected to divided by the resistance to current flowing into and out of the nodes the resistor is connected to.

`i_1 = -(V_1-V_2)`

`i_2 = (V_1-V_2)`

​​

Voltage Sources

Voltage sources have their own rules, similar to a node, where the known value is the source voltage and the unknown value is the source current. The source voltage is equal to the difference between the voltages of the nodes the source is connected to, and the source current is added to the currents of the nodes it is connected to.

`V_s = V_1-V_2`

`i_1 = -i_s`

`i_2 = i_s`

​

Current Sources

Current sources add and subtract the source current from the nodes the source is connected to.

`i_1 = -i_s`

`i_2 = i_s`

​

Inductors

Inductors are modeled using a resistor and current source in parallel. After every time step, the current through the resistor multiplied by 2 is added to the inductor current. If the assumption is made that the current changes at a constant rate during the time step, the average change in current will be proportional to the voltage across the inductor. This matches the behavior of a resistor. The total change in current will be twice the average change in current which is why the resistor current is multiplied by two. This method allows the change in inductor current to be taken into account in the linear solver, which allows circuits like LC circuits to run stably without gaining or losing energy.

`i_R = V_R/R`

`i_L -> i_L + 2i_R`

Approximates

`i_{L} = 1/L \int V_L dt`​

​

Capacitors

Capacitors were originally modeled using a voltage source and resistor in series, where the resistor models the voltage change during the time step. I later changed this after I realized that a voltage source and resistor in series has an equivalent current source and resistor in parallel. Using a current source and resistor reduces the number of unknowns in the system of equations which improves performance.

 

The source current is determined by the capacitor voltage. When the circuit updates, the voltage of the capacitor is changed by the difference between the actual voltage across the capacitor in the circuit and the unloaded capacitor voltage.

`i_C = V_C/R`

`V_C -> V_C + 2(V_RC - V_C)`

Approximates

`V_{C} = 1/C \int V_L dt`​

​​

Source Code

Source code can be found here: https://github.com/lmarsbrown/CircuitSolver

bottom of page