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-vcp-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_30_0")
const start = trace.route[0]
const suffix = trace.route.slice(7)
const oldVia = trace.route[5]
const wire = (x, y, layer, width = 0.1) => ({ route_type: "wire", x, y, layer, width })
const via = (x, y) => ({
route_type: "via", x, y, from_layer: "inner2", to_layer: "top",
via_diameter: 0.45, via_hole_diameter: 0.3,
})
const makeCircuit = (x, y, mode) => {
const prefix = mode === 0
? [{ ...start, width: 0.1 }, wire(x, start.y, "top"), wire(x, y, "top"), via(x, y), wire(x, y, "inner2"), wire(oldVia.x, oldVia.y, "inner2")]
: [{ ...start, width: 0.1 }, wire(start.x, y, "top"), wire(x, y, "top"), via(x, y), wire(x, y, "inner2"), wire(oldVia.x, oldVia.y, "inner2")]
return base.map((element) => {
if (element.type === "pcb_via" && element.pcb_via_id === "pcb_via_9") return { ...element, x, y }
if (element.type === "pcb_trace" && element.pcb_trace_id === "source_net_30_0") {
return { ...element, route: [...prefix, ...suffix] }
}
return element
})
}
let best = { count: Infinity }
if (process.argv.length >= 4) {
const x = Number(process.argv[2]); const y = Number(process.argv[3]); const mode = Number(process.argv[4] ?? 0)
const errors = await runAllRoutingChecks(makeCircuit(x, y, mode))
console.log(errors.length)
console.log(errors.map((e) => e.message).join("\n"))
process.exit(0)
}
for (let x = -1.5; x <= 1.5 + 1e-9; x += 0.2) {
for (let y = 1.2; y <= 3.6 + 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))