<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" footprint="0402" />
</subcircuit>
<subcircuit name="subcircuit2" schX={2}>
<resistor name="R2" resistance="1k" footprint="0402" />
</subcircuit>
<trace from=".subcircuit1 .R1 .pin1" to=".subcircuit2 .R2 .pin1" />
</board>
)
Exposed ports on a standalone schematic
Export a root <subcircuit /> with exposedNets to draw its public terminals
on a boundary, wired to the internal circuit. This example adapts the real
CC2340R5 reference design
with 13 exports for power, ground, reset, SWD, and GPIOs.
import Cc2340R5Contents, { exportedNets } from "./cc2340r5"
export default () => (
<subcircuit
name="CC2340R5"
exposedNets={exportedNets}
schPinArrangement={{
leftSide: { pins: exportedNets, direction: "top-to-bottom" },
}}
schMaxTraceDistance={20}
schStyle={{ defaultPassiveSize: "md", defaultCapacitorOrientation: "vertical" }}
>
<Cc2340R5Contents />
</subcircuit>
)
schPinArrangement controls terminal sides and ordering; core places and routes
them automatically. Render the subcircuit directly, without a <board /> wrapper.
You can also export individual pins using direct <port /> children.
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" footprint="0402" />
</subcircuit>
<subcircuit name="subcircuit2" schX={2}>
<resistor name="R1" resistance="1k" footprint="0402" />
</subcircuit>
<trace from=".subcircuit1 .R1 .pin1" to=".subcircuit2 .R1 .pin1" />
</board>
)
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">
<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.