Pins & Power

The Pin object represents the pin/leg/lead/ball of a component. When pins carry power information, typeCAD checks voltage levels and current draw for compatibility — that's the power-aware system, and Power is how a source or consumer enters it.

class

Pin

One pin of a component. Two access styles: numeric for simple parts, named for complex ones. An optional powerInfo object makes the pin power-aware.

Example first

numeric.ts
import { Resistor } from '@typecad/pcb';
let r1 = new Resistor({ value: '1kohm' });

r1.pin(1);      // first pin
r1.pin(2);      // second pin

Numeric access — component.pin(n)

Use for simple components like passives where pin numbers are straightforward.

Named access — component.PINNAME

Use for complex components (ICs, connectors) with a generated .ts file where Pin objects are defined:

named.ts
import { ATtiny85_20S } from './ATtiny85_20S';
let u1 = new ATtiny85_20S();

u1.VCC      // power pin (internally pin 8)
u1.GND      // ground pin (internally pin 4)
u1.PB0      // GPIO pin PB0

pin (config) this.pin(number, { type, powerInfo }): Pin

ParameterTypeUnits / valuesDescription
typestringKiCAD typee.g. 'power_in', 'power_out', 'bidirectional' — used by ERC
powerInfoobject—Optional — enables voltage and current compatibility checks

The powerInfo properties:

PropertyMeaning
minimum_voltageVolts the pin can tolerate (minimum)
maximum_voltageVolts the pin can tolerate (maximum)
currentMaximum current the pin can handle (A)

With data present, typeCAD checks that connected pins have compatible voltage levels and current draw — errors or warnings when the voltage is too high or the draw too much:

pin-config.ts
VCC = this.pin(8, { type: 'power_in', powerInfo: {
  minimum_voltage: -0.5,
  maximum_voltage: 6,
  current: 0.2,
}});
class

Power

Extra information used for ERC (pin types), voltage compatibility checks, and automatic trace width calculation. A Power object represents a physical set of pins, not an abstract concept of power or ground.

Example first

coin-cell.ts
import { Component, Power } from '@typecad/pcb';

let bt1 = new Component({ footprint: 'Battery:BatteryHolder_Keystone_3008_1x2450' });
let coin_cell = new Power({
    power: bt1.pin(1),  // Pin 1 is the positive terminal → type set to 'power_out'
    gnd: bt1.pin(2),    // Pin 2 is the ground terminal → type set to 'power_in'
    voltage: 3.7,       // Nominal voltage
    current: 0.5,       // Current capacity
    direction: 'output' // This is a power source (default)
});

Options

OptionTypeDescription
powerPinPin that supplies power
gndPinPin that supplies ground
voltagenumberVolts
currentnumberCurrent capacity
direction'output' | 'input''output' (default) for power sources, 'input' for power consumers

How pin types are set

When a Power object is created, pin types are set automatically for ERC — the gnd pin is always power_in, regardless of direction:

directionpower pin typegnd pin type
direction: outputpower_outpower_in
direction: inputpower_inpower_in

voltage and current propagate to the pins' powerInfo, used by ERC for voltage checks and by the routing system for trace width calculation.

Shared ground pins

Voltage regulators often have power inputs and outputs sharing one ground pin. Since gnd is always power_in, this typically works without conflict; override the pin type manually if ERC needs it:

regulator.ts
// U1 is a voltage regulator, pin 2 is shared ground
let vin = new Power({ power: U1.pin(1), gnd: U1.pin(2), voltage: 5, direction: 'input' });
let vout = new Power({ power: U1.pin(3), gnd: U1.pin(2), voltage: 3.3, direction: 'output' });

Input Power

An input Power specifies the power requirements of a component or sub-circuit — commonly passed into reusable packages so users can connect a suitable source:

package-power.ts
// 'vin' is an input Power object passed as a parameter
typecad.net(vin.power, U1.VCC);
typecad.net(vin.gnd, U1.GND);

A package can check the incoming voltage as well:

voltage-check.ts
if (vin.voltage != 3.3) {
    throw new Error('Voltage must be 3.3v');
}
© 2026 typeCAD — code-defined electronics github