MustafaMulla29/rp2040-bldc-motor-controller

Hardware assembly metadata and PCB geometry for a controller board with a snap-off rotary-encoder section, plus four parallel 150 µF/50 V bulk electrolytic capacitors filtering the motor supply.

Version
2.0.40
License
unset
Stars
0

Use with the tscircuit CLI

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

tsci clone MustafaMulla29/rp2040-bldc-motor-controller  # download the package files into ./rp2040-bldc-motor-controller
tsci add MustafaMulla29/rp2040-bldc-motor-controller    # add it to your project as @tsci/MustafaMulla29.rp2040-bldc-motor-controller

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.

firmware/provision_pd.py

"""Run once from MicroPython REPL, powered by a 5 V-only USB host/supply.

Set SW4 OFF and disconnect the motor. Do not connect a PD-capable source until this
script succeeds and verify_pd_boot.py passes after complete power removal.
"""
from machine import Pin, ADC, I2C
from pd_nvm import NVM

Pin(2, Pin.OUT, value=0)
Pin(3, Pin.OUT, value=0)
bus = I2C(1, sda=Pin(22), scl=Pin(23), freq=100_000)

def millivolts(channel):
    return ADC(channel).read_u16() * 3300 * 235 // (65535 * 15)

if not 4400 <= millivolts(26) <= 5500 or millivolts(27) > 1000:
    raise OSError("Use 5 V-only USB power, with SW4 OFF")
nvm = NVM(bus)
# Preserve a per-device recovery copy before the first write; never overwrite it.
try:
    with open("pd-nvm-original.bin", "rb") as backup:
        if len(backup.read()) != 40:
            raise OSError("Existing NVM backup is incomplete")
except OSError as error:
    # ENOENT is the only acceptable reason for a missing backup.
    if error.args[0] != 2:
        raise
    with open("pd-nvm-original.bin", "wb") as backup:
        backup.write(nvm.read())
    import os
    os.sync()
changed = nvm.provision_9v()
print("NVM programmed and read back." if changed else "NVM already correct; no write needed.")
print("Remove ALL power. Reconnect 5 V-only USB, then run verify_pd_boot.py before power_manager.py.")