MustafaMulla29/rp2040-bldc-motor-controller-new

A USB‑C PD–powered RP2040 BLDC motor controller PCB with 3.3 V logic, MCT8329A sensorless commutation, three MOSFET half-bridges, protected power switching, USB data, controls, and motor connectors.

Version
0.3.82
License
unset
Stars
0

docs/connectors-and-firmware.md

# Connections and firmware

| Part | Connection / function |
|---|---|
| J19 PWR | USB-C PD source advertising the selected 5/9/15/20 V at ≥2 A; board requests 2 A, defaults to 9 V |
| J1 DATA | Computer USB data cable; communication and 5 V logic power only |
| J10/J11/J12 | U/V/W motor phases, each via one purchased 3.5 mm female / 4 mm male rigid adapter |
| SW4 | Motor power ON/OFF; OFF also clamps driver ARM |
| SW3 | ARM request button; firmware must require deliberate re-arm after faults |
| RV1 | Onboard speed request potentiometer |
| SW1 / SW2 | BOOTSEL / RESET |
| TP1–TP16 | Flat 1.5 mm SWD, PD, driver and bus probe pads with 2.5 mm courtyards; no purchased parts |

J8, J13, J15 and J16 are removed. No battery or external temperature probes are required.

## PD provisioning

Set SW4 OFF and disconnect the motor. Power J19 from a **5 V-only source** and connect J1 DATA to the computer. Run `firmware/provision_pd.py`, remove all power, reconnect the same 5 V-only sources and run `verify_pd_boot.py`. Only after successful cold-start verification attach a PD source. The factory-default STUSB4500 NVM must not be used unreviewed: it may contain higher-voltage profiles.

`power_manager.py` is PD-only diagnostic firmware that keeps SPEED and ARM low. It verifies the selected profiles and accepts `voltage 5`, `voltage 9`, `voltage 15` or `voltage 20` over the MicroPython USB DATA console. Set SW4 OFF, wait until VMOTOR is below 1 V, then enter the command. It requires 250 ms of a stable, matching explicit contract. Unsupported/missing profiles, I²C failures, fallback 5 V and an energized motor bus leave drive OFF. Runtime settings do not write NVM; cold power-up restores 9 V. Host tests cover invalid voltage, PD loss, mismatch, insufficient current, switch OFF, faults and overcurrent. Tests are not hardware measurements.

RP2040 GPIO0/1: MCT I2C; GPIO2: SPEED; GPIO3: ARM; GPIO4: nFAULT; GPIO5: FG; GPIO6: PD_OK2_N; GPIO8: ARM button; GPIO9: DATA VBUS detect; GPIO22/23: PD I2C; GPIO24: PD alert; GPIO25: LED. ADC26/27/28/29: input voltage / motor-bus voltage / input current / speed knob. GPIO7/12 are unused after charger removal.

Motor-specific MCT8329A configuration, usable motor-control firmware and USB commands remain to be completed and tested. Driver internal thermal shutdown does not establish external MOSFET temperature limits.

## Configurable revision and limits (trial, 16 October 2026)

STUSB4500 has three sink PDO slots, not four. PDO1 remains the mandatory 5 V / 0.5 A fallback; runtime PDO2 contains the selected 5, 9, 15 or 20 V / 2 A request. PDO3 is inactive and mirrors PDO2. POWER_OK2 and the existing hardware ARM clamp remain in use. The explicit 5 V PDO2 case must be verified on real STUSB4500 hardware: a Python bus model is not proof of its policy-engine negotiation. The manufacturer describes POWER_ONLY_ABOVE_5V in terms of an explicit PDO2/PDO3 contract, despite the bit's name.

RDO operating current must equal the 2 A request; RDO maximum current reports the source's capability and can be higher (for example, 3 A). Reject capability mismatch and an unverified voltage. A charger that lacks the requested profile is not silently treated as ready.

R11 and R30 are now 220 kΩ with 15 kΩ lower resistors. Both ADC conversions use 235/15, not 115/15. Calibrate the ADC reference and dividers with a meter before load testing. The input shunt measures the motor feed, not the always-on logic branch. Provisional motor-feed limits are 0.8 A at 5 V and 1.5 A at 9/15/20 V. They are input-current limits, not winding phase-current ratings. Logic/PD consumption must be measured and included in the 2 A source budget.

These limits are currently implemented only in the tested `motor_permitted()`
policy helper. The diagnostic console does not call it to control a motor: it
holds SPEED and ARM low throughout. A motor application must integrate the
calibrated voltage/current checks, driver configuration, user controls and fault
latching before these limits can be described as enforced during operation.

The original example motor stays on the assembly. Higher settings are for suitably rated motors and validated driver tuning; the connector diameter does not determine a motor's voltage rating. There is no continuous voltage slider and no automatic maximum-voltage selection.

5 V cannot deliver the same load through every compliant cable: USB Type-C permits up to 0.75 V cable-loop drop at a cable's rated current. Even a low-loss PCB cannot recover voltage already lost in the cable. The motor must stop before its supply falls below the driver's operating minimum. A regulated boost stage would be a different redesign if a guaranteed 5 V load across worst-case cables is required.

Sources: [STUSB4500](https://www.st.com/resource/en/datasheet/stusb4500.pdf),
[MCT8329A](https://www.ti.com/lit/ds/symlink/mct8329a.pdf),
[USB Type-C cable requirements, section 3.4.3](https://www.usb.org/sites/default/files/USB%20Type-C%20Spec%20R2.0%20-%20August%202019.pdf).