Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion docs/advanced/spice-simulation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This component configures and enables the analog simulation for the board.
| ------------- | ------ | ----------------------------------------------------- |
| `duration` | number | The total duration of the simulation (e.g., in seconds). |
| `timePerStep` | number | The time interval between simulation steps (e.g., in seconds). |
| `spiceEngine` | string | The SPICE engine to use (e.g., `"ngspice"`). |
| `spiceEngine` | string | The SPICE engine to use. Can be `"spicey"` (default) or `"ngspice"`. |

Example:

Expand Down Expand Up @@ -153,3 +153,66 @@ export default () => (
`} />

The simulation results would show the output voltage across `R1` successfully "boosted" compared to the 5V input from `V1`. The specific output voltage depends on the duty cycle of the MOSFET driver `V2` and the component values.

## Example: RC Charging Circuit

Here's an example of an RC circuit that forms a voltage divider with a capacitor. This also functions as a low-pass filter. Since no `spiceEngine` is specified in `<analogsimulation />`, it uses the default `spicey` engine. Voltage probes are placed at the input and output to observe the charging behavior.

<CircuitPreview
defaultView="schematic"
showSimulationGraph={true}
code={`
export default () => (
<board width={16} height={16} schMaxTraceDistance={5}>
<voltagesource
name="V1"
voltage="5V"
schX={-4}
schY={1}
schRotation={270}
/>
<resistor
name="R1"
resistance="1k"
footprint="0402"
schX={-1}
schY={4}
pcbX={4}
pcbY={4}
/>
<resistor
name="R2"
resistance="2k"
footprint="0402"
schX={3}
schY={3}
schRotation={270}
pcbX={-4}
pcbY={-4}
/>
<capacitor
name="C1"
capacitance="10uF"
footprint="0402"
schX={2}
schY={1.5}
pcbX={0}
pcbY={-2}
/>

<trace from={".V1 > .pin1"} to={".R1 > .pin1"} />
<trace from={".R1 > .pin2"} to={".R2 > .pin1"} />
<trace from={".R1 > .pin2"} to={".C1 > .pin1"} />
<trace from={".V1 > .pin2"} to={"net.GND"} />
<trace from={".R2 > .pin2"} to={"net.GND"} />
<trace from={".C1 > .pin2"} to={"net.GND"} />

<voltageprobe connectsTo={".R1 > .pin1"} />
<voltageprobe connectsTo={".R1 > .pin2"} />

<analogsimulation duration={100} timePerStep={1} />
</board>
)
`} />

The simulation results will show the voltage at the junction of `R1`, `R2`, and `C1` charging towards the Thevenin equivalent voltage of the R1-R2 divider.