jeffsteels/awesome

A 2-layer PCB for balancing a 5-cell battery pack using four coupled-inductor flyback stages with MOSFETs, Schottky diodes, capacitors, bias resistors, and protected six-tap connections.

Version
0.0.1
License
unset
Stars
0

Use with the tscircuit CLI

tsci is the tscircuit CLI. Install it with npm install -g tscircuit.

tsci clone jeffsteels/awesome  # download the package files into ./awesome
tsci add jeffsteels/awesome    # add it to your project as @tsci/jeffsteels.awesome

In a cloned or new (tsci init) project: tsci dev starts a local preview, tsci build outputs Circuit JSON, and tsci push publishes to tscircuit.com.

index.tsx

PCBPCB preview for index.tsx
SchematicSchematic preview for index.tsx
import React from "react"

/*
 * Universal 5S Battery Balancer
 * Schematic Organization — Version 3 (Fully Connected Flyback Netlist)
 *
 * PCB: 112 x 64 mm, 2 layers
 * Four repeated balancing stages
 * Six battery taps: B0 through B5
 */

type StageProps = {
  index: number
  x: number
  y: number
  netLow: string
  netMid: string
  netHigh: string
}

const BridgeStage5S = ({
  index,
  x,
  y,
  netLow,
  netMid,
  netHigh,
}: StageProps) => {
  const n = index + 1

  // Arrange the schematic in a 2 x 2 grid.
  const sx = index % 2 === 0 ? -34 : 34
  const sy = index < 2 ? 29 : -27
  const section = `STAGE_${n}`

  return (
    <React.Fragment>

      {/* Custom coupled-inductor placeholder */}
      <chip
        name={`L${n}`}
        pcbX={x}
        pcbY={y + 11}
        schX={sx}
        schY={sy + 13}
        schSectionName={section}
        pinLabels={{
          pin1: "P1_DOT",
          pin2: "P1_END",
          pin3: "P2_DOT",
          pin4: "P2_END",
        }}
        schPinArrangement={{
          leftSide: {
            direction: "top-to-bottom",
            pins: ["P1_DOT", "P2_DOT"],
          },
          rightSide: {
            direction: "top-to-bottom",
            pins: ["P1_END", "P2_END"],
          },
        }}
        footprint={
          <footprint>
            <smtpad
              portHints={["pin1"]}
              pcbX="-4.5mm"
              pcbY="4.5mm"
              width="3mm"
              height="3mm"
              shape="rect"
            />
            <smtpad
              portHints={["pin2"]}
              pcbX="4.5mm"
              pcbY="4.5mm"
              width="3mm"
              height="3mm"
              shape="rect"
            />
            <smtpad
              portHints={["pin3"]}
              pcbX="-4.5mm"
              pcbY="-4.5mm"
              width="3mm"
              height="3mm"
              shape="rect"
            />
            <smtpad
              portHints={["pin4"]}
              pcbX="4.5mm"
              pcbY="-4.5mm"
              width="3mm"
              height="3mm"
              shape="rect"
            />
          </footprint>
        }
      />

      {/* Power MOSFET placeholders */}
      <chip
        name={`Q${n}_A`}
        footprint="soic8"
        pcbX={x - 5.5}
        pcbY={y - 3}
        schX={sx - 9}
        schY={sy - 1}
        schSectionName={section}
      />

      <chip
        name={`Q${n}_B`}
        footprint="soic8"
        pcbX={x + 5.5}
        pcbY={y - 3}
        schX={sx + 9}
        schY={sy - 1}
        schSectionName={section}
      />

      {/* Schottky diodes */}
      <diode
        name={`D${n}_A`}
        footprint="sma"
        pcbX={x - 5.5}
        pcbY={y - 10}
        schX={sx - 16}
        schY={sy - 11}
        schSectionName={section}
      />

      <diode
        name={`D${n}_B`}
        footprint="sma"
        pcbX={x + 5.5}
        pcbY={y - 10}
        schX={sx + 16}
        schY={sy - 11}
        schSectionName={section}
      />

      {/* Capacitors */}
      <capacitor
        name={`C${n}_A`}
        capacitance="10uF"
        footprint="0805"
        pcbX={x - 8}
        pcbY={y + 3}
        schX={sx - 16}
        schY={sy + 12}
        schSectionName={section}
      />

      <capacitor
        name={`C${n}_B`}
        capacitance="10uF"
        footprint="0805"
        pcbX={x + 8}
        pcbY={y + 3}
        schX={sx + 16}
        schY={sy + 12}
        schSectionName={section}
      />

      {/* Bias resistors */}
      <resistor
        name={`R${n}_A`}
        resistance="10k"
        footprint="0805"
        pcbX={x - 2.5}
        pcbY={y - 16}
        schX={sx - 9}
        schY={sy - 19}
        schSectionName={section}
      />

      <resistor
        name={`R${n}_B`}
        resistance="10k"
        footprint="0805"
        pcbX={x + 2.5}
        pcbY={y - 16}
        schX={sx + 9}
        schY={sy - 19}
        schSectionName={section}
      />

      {/* --- Electrical Net Connections (Closing the Flyback Loops) --- */}

      {/* Capacitor cell rail connections */}
      <trace from={`.C${n}_A > .pin1`} to={netLow} />
      <trace from={`.C${n}_A > .pin2`} to={netMid} />
      <trace from={`.C${n}_B > .pin1`} to={netMid} />
      <trace from={`.C${n}_B > .pin2`} to={netHigh} />

      {/* Coupled inductor winding connections */}
      <trace from={`.L${n} > .P1_DOT`} to={netLow} />
      <trace from={`.L${n} > .P1_END`} to={`.Q${n}_A > .pin5`} />
      <trace from={`.L${n} > .P2_DOT`} to={netMid} />
      <trace from={`.L${n} > .P2_END`} to={`.Q${n}_B > .pin5`} />

      {/* Snubber / Clamp Diode connections */}
      <trace from={`.D${n}_A > .pin1`} to={netLow} />
      <trace from={`.D${n}_A > .pin2`} to={`.Q${n}_A > .pin5`} />
      <trace from={`.D${n}_B > .pin1`} to={netMid} />
      <trace from={`.D${n}_B > .pin2`} to={`.Q${n}_B > .pin5`} />

      {/* Gate bias resistor tying */}
      <trace from={`.R${n}_A > .pin1`} to={`.Q${n}_A > .pin1`} />
      <trace from={`.R${n}_A > .pin2`} to={netLow} />
      <trace from={`.R${n}_B > .pin1`} to={`.Q${n}_B > .pin1`} />
      <trace from={`.R${n}_B > .pin2`} to={netMid} />

    </React.Fragment>
  )
}

export default function Universal5SBalancer() {
  const stages = [0, 1, 2, 3]
  const tapPins = [0, 1, 2, 3, 4, 5]

  return (
    <board
      width="112mm"
      height="64mm"
      layers={2}
      autorouter="auto-local"
    >

      {/* Labeled schematic sections */}
      <schematicsection
        name="STAGE_1"
        displayName="Stage 1 — B0 / B1 / B2"
      />

      <schematicsection
        name="STAGE_2"
        displayName="Stage 2 — B1 / B2 / B3"
      />

      <schematicsection
        name="STAGE_3"
        displayName="Stage 3 — B2 / B3 / B4"
      />

      <schematicsection
        name="STAGE_4"
        displayName="Stage 4 — B3 / B4 / B5"
      />

      <schematicsection
        name="TAPS"
        displayName="Battery connector and tap resistors"
      />

      {/* Battery connector */}
      <pinheader
        name="J1_CELLS"
        pinCount={6}
        pitch="2.5mm"
        pcbX={0}
        pcbY={-26}
        schX={0}
        schY={-82}
        schSectionName="TAPS"
      />

      {/* Tap resistors / fuses */}
      {tapPins.map((i) => (
        <React.Fragment key={`fuse-${i}`}>

          <resistor
            name={`F${i + 1}`}
            resistance="0.02ohm"
            footprint="1812"
            pcbX={-27.5 + i * 11}
            pcbY={-19.5}
            schX={-30 + i * 12}
            schY={-63}
            schSectionName="TAPS"
          />

          <trace
            from={`.J1_CELLS > .pin${i + 1}`}
            to={`.F${i + 1} > .pin1`}
          />

          <trace
            from={`.F${i + 1} > .pin2`}
            to={`net.B${i}`}
          />

        </React.Fragment>
      ))}

      {/* Four organized balancing stages */}
      {stages.map((i) => (
        <BridgeStage5S
          key={`stage-${i}`}
          index={i}
          x={-36 + i * 24}
          y={3.5}
          netLow={`net.B${i}`}
          netMid={`net.B${i + 1}`}
          netHigh={`net.B${i + 2}`}
        />
      ))}

    </board>
  )
}