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.

scripts/check-current-budget.py

"""Check compiled R142 and budget arithmetic. Does not certify current or heating."""
import hashlib,json,sys
from pathlib import Path
ROOT=Path(__file__).resolve().parent.parent
sys.path.insert(0,str(ROOT/'firmware'))
from power_policy import INPUT_LIMIT_MA,CONTRACT_MA

def calculate(spec,r142):
 nominal=spec['switchKcl']*spec['switchVcl']/r142
 accuracy=.14 if nominal>=1.6 else .20
 rt=spec['resistorInitialTolerance']+spec['resistorTemperatureAllowance']
 upper=nominal*(1+accuracy)/(1-rt);lower=nominal*(1-accuracy)/(1+rt)
 rows=[]
 for key,ma in spec['logicOutputAllocationMa'].items():
  voltage=int(key);input_v=spec['minimumBoardVbusMv'][key]/1000-spec['assumedLogicDiodeDropV']
  logic_a=spec['logicOutputV']*(ma+spec.get('encoderAuxiliaryAllocationMa',0)+spec.get('feedbackLogicAllocationMa',0)+spec.get('oledAuxiliaryAllocationMa',0))/1000/(spec['minimumAssumedConverterEfficiency']*input_v)+spec['directInputAllowanceMa']/1000
  rows.append({'profileMv':voltage,'logicInputAllowanceA':logic_a,'normalTotalInputA':logic_a+spec['provisionalMotorFeedCeilingMa'][key]/1000,
               'softwareHeadroomA':spec['contractMa']/1000-logic_a-spec['provisionalMotorFeedCeilingMa'][key]/1000,
               'motorFeedLeftByContractA':spec['contractMa']/1000-logic_a})
 fallback_oled_ma=spec.get('oledStandbyAllocationMa',0) if spec.get('oledRequiresPdContract') else spec.get('oledAuxiliaryAllocationMa',0)
 fallback_logic_ma=spec['logicOutputAllocationMa']['5000']+spec.get('encoderAuxiliaryAllocationMa',0)+spec.get('feedbackLogicAllocationMa',0)+fallback_oled_ma
 fallback_logic_a=spec['logicOutputV']*fallback_logic_ma/1000/(spec['minimumAssumedConverterEfficiency']*(spec['minimumBoardVbusMv']['5000']/1000-spec['assumedLogicDiodeDropV']))+spec['directInputAllowanceMa']/1000
 return {'r142Ohms':r142,'nominalMotorFeedLimitA':nominal,'illustrativeLimitMinimumA':lower,'illustrativeLimitMaximumA':upper,
         'hardwareLimitAboveContractA':lower-spec['contractMa']/1000,'resistorTotalToleranceUsed':rt,
         'resistorNominalDissipationW':spec['switchVcl']**2/r142,'profiles':rows,'fallbackLogicAllowanceA':fallback_logic_a,'fallbackOledAllowanceMa':fallback_oled_ma,'oledRequiresPdContract':spec.get('oledRequiresPdContract',False)}

def review(c,spec):
 parts={x['name']:x for x in c if x['type']=='source_component'};r=calculate(spec,parts['R142']['resistance']);fail=[]
 if r['r142Ohms']!=spec['r142Ohms']:fail.append('Compiled R142 disagrees with budget')
 if CONTRACT_MA!=spec['contractMa']:fail.append('PD contract disagrees with budget')
 if INPUT_LIMIT_MA!={int(k):v for k,v in spec['provisionalMotorFeedCeilingMa'].items()}:fail.append('Firmware helper ceilings disagree with budget')
 if any(row['normalTotalInputA']>=spec['contractMa']/1000 for row in r['profiles']):fail.append('Input allocation exceeds PD contract')
 # U11 must never be what caps the motor: even its lowest possible limit has to sit above the whole PD contract.
 if r['illustrativeLimitMinimumA']<=spec['contractMa']/1000:fail.append('U11 hardware limit can act inside the PD contract')
 if r['fallbackLogicAllowanceA']>=spec['fallbackMa']/1000:fail.append('Logic allocation exceeds fallback current')
 if max(INPUT_LIMIT_MA.values())/1000>=r['illustrativeLimitMinimumA']:fail.append('Normal ceiling reaches lower hardware-limit estimate')
 r['failures']=fail;r['status']=spec['status'];r['limitations']=spec['limitations'];return r

if __name__=='__main__':
 p=ROOT/'dist/index/circuit.json';raw=p.read_bytes();spec=json.loads((ROOT/'manufacturing/current-budget.json').read_text());r=review(json.loads(raw),spec)
 r['sha256']=hashlib.sha256(raw).hexdigest();r['previous1200OhmComparison']=calculate(spec,1200)
 (ROOT/'dist/current-budget-review.json').write_text(json.dumps(r,indent=2)+'\n');print(json.dumps(r,indent=2));sys.exit(bool(r['failures']))