Skip to main content

<subcircuit />

Overview

A <subcircuit /> is a powerful organizational element in tscircuit that represents a collection of elements that are tightly coupled. Subcircuits are often used for a small functional block, such as a voltage regulator.

Within a subcircuit, you can have a custom autorouter or isolated nets from the larger circuits. You can also re-use reference designators. Your subcircuit is essentially isolated from other subcircuits.

export default () => (
<board width="10mm" height="10mm">
<subcircuit name="subcircuit1" schX={-2}>
<resistor name="R1" resistance="1k" />
</subcircuit>
<subcircuit name="subcircuit2" schX={2}>
<resistor name="R2" resistance="1k" />
</subcircuit>
<trace from=".subcircuit1 .R1 .pin1" to=".subcircuit2 .R2 .pin1" />
</board>
)
Schematic Circuit Preview

Reuse Reference Designators

Reusing reference designators is typically considered a bad practice, but in tscircuit reference designators are intelligently prefixed prior to being written on the silkscreen. This means that you can design your subcircuits without worrying about whether or not a reference designator has been previously used.

Within a subcircuit, you'll never select inside of another subcircuit without explicitly specifying the subcircuit name in a selector. This means you never need to worry about other R1 or C1 selectors from other subcircuits, they will not be selected unless you explicitly include a subcircuit selector e.g. .somesubcircuit .R1

export default () => (
<board width="10mm" height="10mm">
<subcircuit name="subcircuit1" schX={-2}>
<resistor name="R1" resistance="1k" />
</subcircuit>
<subcircuit name="subcircuit2" schX={2}>
<resistor name="R1" resistance="1k" />
</subcircuit>
<trace from=".subcircuit1 .R1 .pin1" to=".subcircuit2 .R1 .pin1" />
</board>
)
Schematic Circuit Preview

Configuring the Autorouter

Subcircuits can have a custom autorouter configuration. This will be inherited by any children subcircuits.

To specify a custom autorouter configuration, just set the autorouter property on a <subcircuit /> element.

<subcircuit autorouter="auto-cloud">
<resistor name="R1" resistance="1k" footprint="0402" />
<resistor name="R2" resistance="1k" footprint="0402" />
{/* ... */}
</subcircuit>

Specifying custom autorouter settings for subcircuits can be extremely useful when you have a tricky section of components that have special requirements.

Read more about the autorouter prop here.