ShiboSoftwareDev/nema8-20mm-dual-usbc-stepper-controller

A compact 4-layer USB‑C PD/data controller board using a CH32X035 MCU and TMC2209 driver to power and control a NEMA‑8 stepper motor, with 3.3‑V regulation, USB ESD/reverse-polarity/TVS protection, current sensing, and boot control.

Version
1.0.12
License
unset
Stars
0

scripts/search-step-prefix.mjs

import fs from "node:fs"
import { runAllRoutingChecks } from "@tscircuit/checks"

const base = JSON.parse(fs.readFileSync("dist/index/circuit.json", "utf8"))
  .filter((element) => !String(element.type).endsWith("error"))
const trace = base.find((element) => element.type === "pcb_trace" && element.pcb_trace_id === "source_net_20_0")
const start = trace.route[0]; const oldVia = trace.route[5]; const suffix = trace.route.slice(7)
const wire = (x, y, layer) => ({ route_type: "wire", x, y, layer, width: 0.15 })
const via = (x, y) => ({ route_type: "via", x, y, from_layer: "top", to_layer: "bottom", via_diameter: 0.45, via_hole_diameter: 0.3 })
const makeCircuit = (x, y, mode) => {
  const route = mode === 0
    ? [start, wire(x, start.y, "bottom"), wire(x, y, "bottom"), via(x, y), wire(x, y, "top"), wire(oldVia.x, oldVia.y, "top"), ...suffix]
    : [start, wire(start.x, y, "bottom"), wire(x, y, "bottom"), via(x, y), wire(x, y, "top"), wire(oldVia.x, oldVia.y, "top"), ...suffix]
  return base.map((element) => {
    if (element.type === "pcb_via" && element.pcb_via_id === "pcb_via_37") return { ...element, x, y }
    if (element.type === "pcb_trace" && element.pcb_trace_id === trace.pcb_trace_id) return { ...element, route }
    return element
  })
}

if (process.argv.length >= 4) {
  const errors = await runAllRoutingChecks(makeCircuit(Number(process.argv[2]), Number(process.argv[3]), Number(process.argv[4] ?? 0)))
  console.log(errors.length); console.log(errors.map((e) => e.message).join("\n")); process.exit(0)
}
let best = { count: Infinity }
for (let x = -6.2; x <= -3.0 + 1e-9; x += 0.2) for (let y = -3.4; y <= -1.8 + 1e-9; y += 0.2) for (let mode = 0; mode < 2; mode++) {
  const cx = Number(x.toFixed(3)); const cy = Number(y.toFixed(3)); const errors = await runAllRoutingChecks(makeCircuit(cx, cy, mode))
  if (errors.length < best.count) { best = { count: errors.length, x: cx, y: cy, mode, errors }; console.log("best", best.count, best.x, best.y, best.mode) }
  if (errors.length <= 6) { console.log(JSON.stringify({ count: errors.length, x: cx, y: cy, mode })); console.log(errors.map((e) => e.message).join("\n")); process.exit(0) }
}
console.log(JSON.stringify(best, null, 2))