seveibar/nema17-stepper-motor-driver-tmc2209-usb-pd

RP2040-based USB-C PD stepper-motor controller with TMC2209 drive, AS5600 position feedback, TMP102 thermal shutdown, current/voltage telemetry, RGB status LED, and protected buzzer alarm circuitry.

Version
0.2.0
License
unset
Stars
0

index.circuit.tsx

PCBPCB preview for index.circuit.tsx
SchematicSchematic preview for index.circuit.tsx
import { TelemetrySection } from "./schematic/TelemetrySection";
import { FeedbackSection } from "./schematic/FeedbackSection";
import { savedRouting } from "./routing/saved-routing";
import nema17Outline from "./mechanical/nema17-outline.json";
import { ControllerSections } from "./schematic/ControllerSections";
import {
	MotorDriverController,
	MotorDriverControlTraces,
	MotorDriverGroundTraces,
	MotorDriverPassives,
	MotorDriverPowerTraces,
	MotorDriverPrimaryGroundTraces,
	MotorDriverSenseAndControlTraces,
} from "./schematic/MotorDriverCoreSection";
import {
	MotorOutputConnectors,
	MotorOutputTraces,
} from "./schematic/MotorOutputsSection";
import {
	MotorPowerFilteringComponents,
	MotorPowerFilteringGroundTrace,
	MotorPowerFilteringSupplyTrace,
} from "./schematic/MotorPowerFilteringSection";
import {
	MotorPowerPdConnectorGroundTraces,
	MotorPowerPdControllers,
	MotorPowerPdInputTraces,
	MotorPowerPdPassives,
	MotorPowerPdPrimaryGroundTrace,
	MotorPowerPdProtocolTraces,
	MotorPowerPdSupportGroundTraces,
} from "./schematic/MotorPowerPdNegotiationSection";
import { SchematicSheets } from "./schematic/SchematicSheets";
import { ThermalProtectionComponents, ThermalProtectionTraces } from "./schematic/ThermalProtectionSection";

export default function Rp2040MotorController({
	routingDisabled = false,
  useSavedRouting = true,
}: {
	routingDisabled?: boolean;
  useSavedRouting?: boolean;
} = {}) {
	return (
    <board
      routingDisabled={routingDisabled}
			layers={4}
      thickness="1.6mm"
			outline={nema17Outline}
			minViaHoleDiameter="0.3mm"
      minViaPadDiameter="0.45mm"
			autorouterEffortLevel="2x"
			autorouterVersion="beta_pipeline7"
			autorouter={{
				local: true,
        algorithmFn: useSavedRouting ? savedRouting : undefined,
				
				groupMode: "subcircuit",
			}}
		>
			<net name="GND" />
			{/* Explicit net names keep labels consistent across the MCU subcircuit and sheets. */}
			<net name="TMC_STEP" connectsTo=".MCU > .U1 > .GPIO18" />
			<net name="TMC_DIR" connectsTo=".MCU > .U1 > .GPIO19" />
			<net name="TMC_TX" connectsTo=".MCU > .U1 > .GPIO20" />
			<net name="MCU_ENABLE" connectsTo=".MCU > .U1 > .GPIO22" />
			<net name="TEMP_OK" connectsTo=".MCU > .U1 > .GPIO24" />
			<net name="TEMP_SDA" connectsTo=".MCU > .U1 > .GPIO26_ADC0" />
			<net name="TEMP_SCL" connectsTo=".MCU > .U1 > .GPIO27_ADC1" />
			<SchematicSheets />

			<group pcbX={-5.625} pcbY={-8.25}>
				<ControllerSections />
				<MotorDriverController />
				<MotorPowerPdControllers />
				<MotorOutputConnectors />
				<MotorPowerFilteringComponents />
				<MotorPowerPdPassives />
				<MotorDriverPassives />
				<ThermalProtectionComponents />

				<MotorDriverControlTraces />
				<MotorPowerPdInputTraces />
				<MotorPowerFilteringSupplyTrace />
				<MotorPowerPdProtocolTraces />
				<MotorDriverPowerTraces />
				<MotorDriverPrimaryGroundTraces />
				<MotorPowerPdPrimaryGroundTrace />
				<MotorPowerPdConnectorGroundTraces />
				<MotorPowerFilteringGroundTrace />
				<MotorPowerPdSupportGroundTraces />
				<MotorDriverGroundTraces />
				<MotorOutputTraces />
				<MotorDriverSenseAndControlTraces />
				<ThermalProtectionTraces />
			</group>

			<copperpour
				name="GND_TOP"
				layer="top"
				connectsTo="net.GND"
				clearance="0.2mm"
				padMargin="0.2mm"
				traceMargin="0.2mm"
				boardEdgeMargin="0.3mm"
				coveredWithSolderMask
			/>
			<copperpour
				name="GND_BOTTOM"
				layer="bottom"
				connectsTo="net.GND"
				clearance="0.2mm"
				padMargin="0.2mm"
				traceMargin="0.2mm"
				boardEdgeMargin="0.3mm"
				coveredWithSolderMask
			/>

			<group pcbX={0} pcbY={0} schX={0} schY={0}>
        {[-15.5,15.5].flatMap(x => [-15.5,15.5].map(y => (
          <group key={`${x}:${y}`} pcbX={0} pcbY={0} schX={0} schY={0}>
            <chip name={`MH${(x > 0 ? 2 : 0) + (y > 0 ? 1 : 0) + 1}`} pcbX={x} pcbY={y} schSheetName="motor_power" schX={x > 0 ? 11 : 8} schY={y > 0 ? -4 : -6}
              pinLabels={{pin1:["GND"]}} connections={{pin1:"net.GND"}}
              footprint={<footprint><platedhole portHints={["pin1"]} shape="circle" holeDiameter="3.3mm" outerDiameter="5.6mm" /></footprint>} />
          </group>
        )))}
        <silkscreentext text="RP2040 TMC2209" pcbX={0} pcbY={20} fontSize="0.8mm" />
      </group>
			{/* Explicit source joins also give the MCU sheet the same net labels. */}
			<trace name="LABEL_STEP" from=".MCU > .U1 > .GPIO18" to="net.TMC_STEP" schDisplayLabel="TMC_STEP" />
			<trace name="LABEL_DIR" from=".MCU > .U1 > .GPIO19" to="net.TMC_DIR" schDisplayLabel="TMC_DIR" />
			<trace name="LABEL_TX" from=".MCU > .U1 > .GPIO20" to="net.TMC_TX" schDisplayLabel="TMC_TX" />
			<trace name="LABEL_ENABLE" from=".MCU > .U1 > .GPIO22" to="net.MCU_ENABLE" schDisplayLabel="MCU_ENABLE" />
			<trace name="LABEL_TEMP_OK" from=".MCU > .U1 > .GPIO24" to="net.TEMP_OK" schDisplayLabel="TEMP_OK" />
			<trace name="LABEL_TEMP_SDA" from=".MCU > .U1 > .GPIO26_ADC0" to="net.TEMP_SDA" schDisplayLabel="TEMP_SDA" />
			<trace name="LABEL_TEMP_SCL" from=".MCU > .U1 > .GPIO27_ADC1" to="net.TEMP_SCL" schDisplayLabel="TEMP_SCL" />
      <FeedbackSection />
      <TelemetrySection />
		</board>
	);
}