krishnax12/tlv3601-evm-recreation

Complete TI TLV3601EVM reference circuit with TLV3601/TLV3603 assembly options, Matchpack schematic, and a new autorouted four-layer PCB. Not TI's original artwork or hardware validated. Preview builds from the verified local native export; regenerating TSX requires local outline-keepout support. See reference.json.

Version
0.0.5
License
unset
Stars
0

Use with the tscircuit CLI

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

tsci clone krishnax12/tlv3601-evm-recreation  # download the package files into ./tlv3601-evm-recreation
tsci add krishnax12/tlv3601-evm-recreation    # add it to your project as @tsci/krishnax12.tlv3601-evm-recreation

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.

tests/evm.test.ts

import { expect, test } from "bun:test"
import type { AnyCircuitElement, PcbCopperPourBRep } from "circuit-json"
import { analyzeSchematicPlacement } from "@tscircuit/circuit-json-schematic-placement-analysis/analysis"
import type { ComparatorDevice } from "../components/comparator"

const readCircuit = (device: ComparatorDevice): Promise<AnyCircuitElement[]> =>
  Bun.file(`${import.meta.dir}/../outputs/${device}.circuit.json`).json()

function getComponent(circuitJson: AnyCircuitElement[], name: string) {
  const component = circuitJson.find(
    (element) => element.type === "source_component" && element.name === name,
  )
  if (!component || component.type !== "source_component")
    throw new Error(`Missing component ${name}`)
  return component
}

function getPort(
  circuitJson: AnyCircuitElement[],
  { componentName, pinNumber }: { componentName: string; pinNumber: number },
) {
  const component = getComponent(circuitJson, componentName)
  const port = circuitJson.find(
    (element) =>
      element.type === "source_port" &&
      element.source_component_id === component.source_component_id &&
      element.pin_number === pinNumber,
  )
  if (!port || port.type !== "source_port")
    throw new Error(`Missing port ${componentName}.pin${pinNumber}`)
  return port
}

function expectPortOnNet(
  circuitJson: AnyCircuitElement[],
  connection: { componentName: string; pinNumber: number; netName: string },
) {
  const net = circuitJson.find(
    (element) =>
      element.type === "source_net" && element.name === connection.netName,
  )
  if (!net || net.type !== "source_net")
    throw new Error(`Missing net ${connection.netName}`)
  expect(net.subcircuit_connectivity_map_key).toBeDefined()
  expect(getPort(circuitJson, connection).subcircuit_connectivity_map_key).toBe(
    net.subcircuit_connectivity_map_key,
  )
}

for (const device of ["tlv3601", "tlv3603"] as const) {
  test(`${device}: complete EVM circuit matches TI SNOU183 Figure 8-1`, async () => {
    const circuitJson = await readCircuit(device)
    const comparatorName = device === "tlv3601" ? "U2" : "U1"
    const expectedNames = [
      comparatorName,
      ...Array.from({ length: 10 }, (_, index) => `J${index + 1}`),
      ...Array.from({ length: 8 }, (_, index) => `R${index + 1}`),
      ...Array.from({ length: 12 }, (_, index) => `C${index + 1}`),
      ...Array.from({ length: 3 }, (_, index) => `TP${index + 1}`),
    ]
    expect(
      circuitJson
        .filter((element) => element.type === "source_component")
        .map((component) => component.name)
        .sort(),
    ).toEqual(expectedNames.sort())

    const resistorNets = [
      ["IN_P_FEED", "IN_P"],
      ["IN_N_FEED", "IN_N"],
      ["IN_P_SENSE", "IN_P"],
      ["IN_N_SENSE", "IN_N"],
      ["IN_P", "IN_N"],
      ["IN_P", "OUT"],
      ["LE_HYST", "HYST_RAIL"],
      ["OUT", "OUT_ATTENUATED"],
    ]
    for (const [resistorIndex, nets] of resistorNets.entries()) {
      for (const [pinIndex, netName] of nets.entries()) {
        expectPortOnNet(circuitJson, {
          componentName: `R${resistorIndex + 1}`,
          pinNumber: pinIndex + 1,
          netName,
        })
      }
    }
    const smaSignalNets = [
      "IN_P_FEED",
      "IN_N_FEED",
      "IN_P_SENSE",
      "IN_N_SENSE",
      "OUT_ATTENUATED",
      "LE_HYST",
      "LE_HYST",
    ]
    for (const [index, netName] of smaSignalNets.entries()) {
      expectPortOnNet(circuitJson, {
        componentName: `J${index + 1}`,
        pinNumber: 1,
        netName,
      })
      expectPortOnNet(circuitJson, {
        componentName: `J${index + 1}`,
        pinNumber: 2,
        netName: "GND",
      })
    }
    const comparatorNets =
      device === "tlv3601"
        ? ["OUT", "VEE", "IN_P", "IN_N", "VCC"]
        : ["OUT", "VEE", "IN_P", "IN_N", "LE_HYST", "VCC"]
    for (const [index, netName] of comparatorNets.entries()) {
      expectPortOnNet(circuitJson, {
        componentName: comparatorName,
        pinNumber: index + 1,
        netName,
      })
    }
    for (const [componentName, nets] of [
      ["J8", ["GND", "VEE"]],
      ["J9", ["VEE", "HYST_RAIL", "VCC"]],
      ["J10", ["OUT_ATTENUATED", "GND"]],
      ["TP1", ["VCC"]],
      ["TP2", ["VEE"]],
      ["TP3", ["GND"]],
    ] as const) {
      for (const [index, netName] of nets.entries()) {
        expectPortOnNet(circuitJson, {
          componentName,
          pinNumber: index + 1,
          netName,
        })
      }
    }
    for (const [bankIndex, nets] of [
      ["VCC", "GND"],
      ["VEE", "GND"],
      ["VCC", "VEE"],
    ].entries()) {
      for (let capacitorIndex = 0; capacitorIndex < 4; capacitorIndex++) {
        for (const [pinIndex, netName] of nets.entries()) {
          expectPortOnNet(circuitJson, {
            componentName: `C${bankIndex * 4 + capacitorIndex + 1}`,
            pinNumber: pinIndex + 1,
            netName,
          })
        }
      }
    }
    for (const [name, doNotPlace] of [
      ["R5", true],
      ["R6", true],
      ["R7", device === "tlv3601"],
    ] as const) {
      const component = getComponent(circuitJson, name)
      const pcbComponent = circuitJson.find(
        (element) =>
          element.type === "pcb_component" &&
          element.source_component_id === component.source_component_id,
      )
      if (!pcbComponent || pcbComponent.type !== "pcb_component")
        throw new Error(`Missing PCB component ${name}`)
      expect(pcbComponent.do_not_place).toBe(doNotPlace)
    }
  })

  test(`${device}: native footprints, Matchpack, autorouting, and local bypass`, async () => {
    const circuitJson = await readCircuit(device)
    expect(
      circuitJson.filter((element) => element.type.endsWith("_error")),
    ).toEqual([])
    expect(
      circuitJson
        .filter((element) => element.type.endsWith("_warning"))
        .map((warning) => warning.type),
    ).toEqual(["source_no_ground_pin_defined_warning"])
    const pads = circuitJson.filter(
      (
        element,
      ): element is Extract<AnyCircuitElement, { type: "pcb_smtpad" }> =>
        element.type === "pcb_smtpad" && Boolean(element.pcb_component_id),
    )
    expect(pads.length).toBeGreaterThan(0)
    expect(pads.every((pad) => Boolean(pad.pcb_port_id))).toBe(true)
    expect(
      circuitJson.filter(
        (element) => element.type === "pcb_smtpad" && !element.pcb_component_id,
      ),
    ).toHaveLength(6)
    const traces = circuitJson.filter((element) => element.type === "pcb_trace")
    expect(traces.length).toBeGreaterThan(0)
    expect(traces.every((trace) => trace.source_trace_id)).toBe(true)
    expect(
      circuitJson.filter((element) => element.type === "schematic_component"),
    ).toHaveLength(34)
    expect(analyzeSchematicPlacement(circuitJson).getIssues()).toEqual([])
    expect(
      circuitJson
        .filter((element) => element.type === "schematic_sheet")
        .map((sheet) => sheet.name),
    ).toEqual(["signals", "power", "hysteresis"])
    expect(
      circuitJson
        .filter((element) => element.type === "schematic_component")
        .every((component) => component.schematic_sheet_id),
    ).toBe(true)
    const pours = circuitJson.filter(
      (element): element is PcbCopperPourBRep =>
        element.type === "pcb_copper_pour" && element.shape === "brep",
    )
    expect(pours.map((pour) => pour.layer).sort()).toEqual(["bottom", "inner1"])
    const keepouts = circuitJson.filter(
      (element) => element.type === "pcb_keepout",
    )
    expect(keepouts).toHaveLength(0)
    const maximumBypassPadDistance = 2.5
    for (const [comparatorPin, capacitorPin] of [
      [device === "tlv3601" ? 5 : 6, 1],
      [2, 2],
    ]) {
      const comparatorPort = getPort(circuitJson, {
        componentName: device === "tlv3601" ? "U2" : "U1",
        pinNumber: comparatorPin,
      })
      const capacitorPort = getPort(circuitJson, {
        componentName: "C9",
        pinNumber: capacitorPin,
      })
      const comparatorPcbPort = circuitJson.find(
        (element) =>
          element.type === "pcb_port" &&
          element.source_port_id === comparatorPort.source_port_id,
      )
      const capacitorPcbPort = circuitJson.find(
        (element) =>
          element.type === "pcb_port" &&
          element.source_port_id === capacitorPort.source_port_id,
      )
      if (
        comparatorPcbPort?.type !== "pcb_port" ||
        capacitorPcbPort?.type !== "pcb_port"
      )
        throw new Error("Missing bypass PCB ports")
      expect(
        Math.hypot(
          comparatorPcbPort.x - capacitorPcbPort.x,
          comparatorPcbPort.y - capacitorPcbPort.y,
        ),
      ).toBeLessThan(maximumBypassPadDistance)
    }
    for (const courtyard of circuitJson.filter(
      (element) => element.type === "pcb_courtyard_outline",
    ))
      expect(courtyard.outline.length).toBeGreaterThanOrEqual(3)
    const solvers: string[] = await Bun.file(
      `${import.meta.dir}/../outputs/${device}.solvers.json`,
    ).json()
    expect(solvers).toContain("LayoutPipelineSolver")
    expect(
      solvers.filter((name) => name === "SchematicTracePipelineSolver"),
    ).toHaveLength(3)
    expect(
      solvers.some((name) => name.startsWith("AutoroutingPipelineSolver")),
    ).toBe(true)
  })
}