Skip to main content
Built-in Elements

<analogsimulation />

Overview

<analogsimulation /> enables SPICE simulation for a <board /> and sets the simulation parameters, such as duration and time step. Place this element inside your board alongside sources and probes to generate simulation results.

If you're new to simulation workflows, check out the SPICE simulation guide for step-by-step examples.

Schematic Circuit Preview
export default () => (
<board routingDisabled>
<voltagesource name="V1" voltage="5V" />
<resistor name="R1" resistance="1k" />

<trace from=".V1 > .pin1" to=".R1 > .pin1" />
<trace from=".V1 > .pin2" to=".R1 > .pin2" />

<voltageprobe name="VP_IN" connectsTo=".V1 > .pin1" />
<voltageprobe name="VP_OUT" connectsTo=".R1 > .pin1" />

<analogsimulation duration="10ms" timePerStep="0.1ms" spiceEngine="ngspice" />
</board>
)

Properties

PropertyDescriptionExample
nameUser-facing experiment name. Use a unique name when defining multiple simulations."Startup"
durationTotal simulation time. Accepts numbers or time strings."10ms"
timePerStepTime interval between simulation steps."0.1ms"
spiceEngineSPICE engine to use. Typically "ngspice" or "spicey"."ngspice"
graphIndependentAxesGive each voltage or current graph channel its own automatically scaled axis.true

You can use <analogsimulation /> more than once in the same board. Each element creates an independent experiment with its own duration, time step, SPICE options, and result graphs.

Multiple simulations and group scope

Give each simulation a unique name. When more than one experiment is available, the simulation preview shows a selector for switching between its SVG results.

A simulation placed directly in the board collects probes throughout that board, including probes inside groups. A simulation inside a <group /> collects only the probes in its nearest containing group. The complete circuit is simulated in both cases; the group controls which result graphs are shown.

Schematic simulation preview: Root Fast
export default () => (
<board routingDisabled>
<voltagesource name="V1" voltage="5V" />
<resistor name="R1" resistance="1k" />
<resistor name="R2" resistance="2k" />
<resistor name="R3" resistance="3k" />

<trace from=".V1 > .pin1" to=".R1 > .pin1" />
<trace from=".R1 > .pin2" to=".R2 > .pin1" />
<trace from=".R2 > .pin2" to=".R3 > .pin1" />
<trace from=".R3 > .pin2" to=".V1 > .pin2" />

<voltageprobe name="ROOT_PROBE" connectsTo=".V1 > .pin1" />
<analogsimulation
name="Root Fast"
duration="1ms"
timePerStep="100us"
spiceEngine="ngspice"
/>
<analogsimulation
name="Root Slow"
duration="2ms"
timePerStep="200us"
spiceEngine="ngspice"
/>

<group name="first-stage">
<voltageprobe
name="FIRST_STAGE_PROBE"
connectsTo=".R1 > .pin2"
/>
<analogsimulation
name="Input Group"
duration="3ms"
timePerStep="300us"
spiceEngine="ngspice"
/>
</group>

<group name="second-stage">
<voltageprobe
name="SECOND_STAGE_PROBE"
connectsTo=".R2 > .pin2"
/>
<analogsimulation
name="Output Group"
duration="4ms"
timePerStep="400us"
spiceEngine="ngspice"
/>
</group>
</board>
)

Multi-axis scope display

Use graphIndependentAxes when a simulation graph contains signals with different units or very different ranges. tscircuit creates one colored axis per voltage or current channel and automatically chooses the center, offset, and scale from the simulated data.

You can optionally override a channel's display on the probe itself:

  • graphDisplayName sets the channel label.
  • graphCenter sets the measured voltage or current value at the channel center.
  • graphVerticalOffset moves that center up or down in measured units, such as "1V" or "1mA".
  • graphVoltagePerDiv sets volts per division for <voltageprobe />.
  • graphCurrentPerDiv sets amps per division for <ammeter />.
Schematic Circuit Preview
export default () => (
<board routingDisabled>
<voltagesource name="V1" voltage="5V" schX={-4} />
<ammeter
name="IIN"
color="#e05a00"
connections={{
pos: ".V1 > .pin1",
neg: ".R_LOAD > .pin1",
}}
/>
<resistor name="R_LOAD" resistance="1k" schX={2} />

<trace from=".R_LOAD > .pin2" to=".V1 > .pin2" />

<voltageprobe
name="VIN"
color="#315cff"
connectsTo=".IIN > .pos"
referenceTo=".V1 > .pin2"
/>

<analogsimulation
duration="4ms"
timePerStep="1ms"
spiceEngine="ngspice"
graphIndependentAxes
/>
</board>
)

For more end-to-end examples and best practices, we recommend reviewing the SPICE simulation guide.