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-controllerIn 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-v2-hardware.mjs
/** Independent checks against TI pin tables and the display/switch drawings.
* Supply a freshly compiled circuit; this is not a motor performance test.
*/
import {readFileSync,writeFileSync,mkdirSync} from 'node:fs'
import {createHash} from 'node:crypto'
const input=process.argv[2]
if(!input) throw new Error('Usage: bun scripts/check-v2-hardware.mjs <fresh circuit.json>')
const raw=readFileSync(input), c=JSON.parse(raw), failures=[]
const sources=c.filter(x=>x.type==='source_component')
const sourceNames=new Map(sources.map(x=>[x.source_component_id,x.name]))
const nets=new Map(c.filter(x=>x.type==='source_net').map(x=>[x.subcircuit_connectivity_map_key,x.name]))
const pins=new Map(c.filter(x=>x.type==='source_port').map(x=>[`${sourceNames.get(x.source_component_id)}.${x.pin_number}`,nets.get(x.subcircuit_connectivity_map_key)??null]))
const check=(ok,message)=>{if(!ok)failures.push(message)}
const expected={
// TI MCF8329A Table 5-1, REE package. VREG uses an external 3.3 V supply.
'U7.1':'GND','U7.2':'V3V3','U7.3':null,'U7.4':'GND','U7.5':'VMOTOR',
'U7.6':'MCF_CPL','U7.7':'MCF_CPH','U7.8':'MCF_GVDD',
'U7.9':'MCF_BSTA','U7.10':'PHASE_U','U7.11':'GHA','U7.12':'GLA',
'U7.13':'MCF_BSTB','U7.14':'PHASE_V','U7.15':'GHB','U7.16':'GLB',
'U7.17':'MCF_BSTC','U7.18':'PHASE_W','U7.19':'GHC','U7.20':'GLC',
'U7.21':'LS_RETURN','U7.22':'LS_RETURN','U7.23':'GND','U7.24':'MCF_DRVOFF',
'U7.25':'GND','U7.26':'MCF_AVDD','U7.27':'MOTOR_SPEED','U7.28':'MOTOR_FG',
'U7.29':'MCF_SDA','U7.30':'MCF_SCL','U7.31':'MCF_DIR','U7.32':'MCF_EXTCLK',
'U7.33':null,'U7.34':'MCF_BRAKE','U7.35':'MOTOR_FAULT_N','U7.36':'MCF_DVDD','U7.37':'GND',
// RP2040 GPIO and distinct bus assignments.
'U5.14':'KEY_UP_N','U5.15':'KEY_DOWN_N','U5.16':'KEY_OK_N','U5.17':'KEY_BACK_N',
'U5.18':'BUZZER_EN','U5.27':'UI_SDA','U5.28':'UI_SCL','U5.30':'TEMP_ALERT_N',
'U5.2':'MCF_SDA','U5.3':'MCF_SCL','U5.34':'PD_SDA','U5.35':'PD_SCL',
// SSD1309 panel pin table; TI / Nichicon / onsemi package pin tables.
"J21.1":"GND","J21.2":"GND","J21.3":"GND","J21.4":null,"J21.5":"OLED_VDD","J21.6":"OLED_VDD","J21.7":"GND","J21.8":"GND","J21.9":"OLED_RESET_N","J21.10":"GND","J21.11":"GND","J21.12":"GND","J21.13":"OLED_SCL","J21.14":"OLED_SDA","J21.15":"OLED_SDA","J21.16":"GND","J21.17":"GND","J21.18":"GND","J21.19":"GND","J21.20":"GND","J21.21":"OLED_IREF","J21.22":"OLED_VCOMH","J21.23":"OLED_VCC","J21.24":"GND","J21.25":"GND","J21.26":"GND",
"U18.1":"OLED_SW","U18.2":"GND","U18.3":"OLED_FB","U18.4":"OLED_POWER_EN","U18.5":"OLED_VCC","U18.6":"V3V3",
"U19.1":"V3V3","U19.2":"GND","U19.3":"V3V3","U19.4":null,"U19.5":"OLED_VDD_RAW",
"U20.1":"OLED_RESET_N","U20.2":"GND","U20.3":"OLED_HOLD_OK_N","U20.4":"OLED_RESET_CT","U20.5":"V3V3","U20.6":"OLED_VDD",
"U21.1":"GND","U21.2":"GND","U21.3":"OLED_RESET_N","U21.4":"OLED_POWER_REQUEST_N","U21.5":"GND","U21.6":"GND","U21.7":"GND","U21.8":"GND","U21.9":"GND","U21.10":"GND","U21.11":"GND","U21.12":"GND","U21.13":null,"U21.14":"OLED_SCL","U21.15":"OLED_SDA","U21.16":"OLED_VDD",
"U22.1":"OLED_CHARGE","U22.2":"GND","U22.3":"OLED_VDD","U22.4":null,"U22.5":"GND","U22.6":"OLED_VDD",
"U23.1":"OLED_VDD","U23.2":"OLED_SCL","U23.3":"OLED_SDA","U23.4":"GND","U23.5":"OLED_RESET_N","U23.6":"UI_SDA","U23.7":"UI_SCL","U23.8":"V3V3",
// U24 is the WSON-6 (DRV) package: 1 VDD, 2 SENSE, 3 CT (open), 4 MR, 5 GND, 6 RESET, 7 thermal pad (TI SBVS050 rev. K, page 4).
"U24.1":"OLED_VDD","U24.2":"OLED_READY_SENSE","U24.3":null,"U24.4":"OLED_VDD","U24.5":"GND","U24.6":"OLED_HOLD_OK_N","U24.7":"GND",
"Q16.1":"OLED_ENABLE_BASE","Q16.2":"OLED_VDD","Q16.3":"OLED_POWER_EN",
"R185.1":"OLED_VDD_RAW","R185.2":"OLED_CHARGE",
"R186.1":"OLED_VDD","R186.2":"OLED_HOLD_OK_N",
"R187.1":"OLED_VDD","R187.2":"OLED_RESET_CT",
"R188.1":"OLED_VDD","R188.2":"OLED_SCL",
"R189.1":"OLED_VDD","R189.2":"OLED_SDA",
"R190.1":"OLED_POWER_REQUEST_N","R190.2":"OLED_ENABLE_BASE",
"R191.1":"OLED_VDD","R191.2":"OLED_ENABLE_BASE",
"R192.1":"OLED_VDD","R192.2":"OLED_READY_SENSE","R193.1":"OLED_READY_SENSE","R193.2":"GND",
"C191.1":"OLED_VDD","C191.2":"GND",
"R184.1":"OLED_POWER_EN","R184.2":"GND",
"C196.1":"OLED_POWER_EN","C196.2":"GND",
"R150.1":"V3V3","R151.1":"V3V3",
'U13.1':'UI_SCL','U13.2':'GND','U13.3':'TEMP_ALERT_N','U13.4':'GND','U13.5':'V3V3','U13.6':'UI_SDA',
'Q8.1':'BUZZER_BASE','Q8.2':'GND','Q8.3':'BUZZER_LOW',
'D8.1':'BUZZER_LOW','D8.2':'V3V3',
'SW4.1':'GND','SW4.2':'POWER_SWITCH_EN','SW4.3':'POWER_ON_LEVEL',
'SW4.4':'GND','SW4.5':'REARM_RESET_N','SW4.6':null,
}
for(let i=0;i<4;i++){
const key=['UP','DOWN','OK','BACK'][i]
// KH-6X6X9.5H: diagonal pins 1/4 switch; 2/3 are unconnected solder anchors.
expected[`SW${5+i}.1`]=`KEY_${key}_N`;expected[`SW${5+i}.4`]='GND'
expected[`SW${5+i}.2`]=null;expected[`SW${5+i}.3`]=null
expected[`C${93+i}.1`]='VMOTOR';expected[`C${93+i}.2`]='GND'
}
for(const [pin,net] of Object.entries(expected))check(pins.has(pin)&&pins.get(pin)===net,`${pin}: expected ${net}, found ${pins.get(pin)}`)
for(const [name,mpn,lcsc] of [['U7','MCF8329A1IREER','C22399784'],['U18','TLV61046ADBVR','C464815'],['U20','TPS3808G33DBVR','C43698'],['U21','TCA9538PWR','C2652286'],['U22','LM66100DCKR','C2869734'],['U23','TCA9517ADGKR','C201698'],['U24','TPS3808G01DRVR','C477447'],['Q16','MMBT3906LT1G','C53444'],['J21','0.5K-HX-24PWB','C2919499'],['U19','TLV70030DDCR','C36463'],['U13','TMP102AIDRLR','C99269'],['SW4','SK-22D03-G080','C55166127'],['BZ1','HNB09A03','C96102'],...[93,94,95,96].map(n=>[`C${n}`,'EEUFR1H151','C542038'])]){
const s=sources.find(x=>x.name===name)
check(s?.manufacturer_part_number===mpn&&s?.supplier_part_numbers?.jlcpcb?.includes(lcsc),`${name}: BOM must be ${mpn}/${lcsc}`)
}
const pcb=name=>c.find(x=>x.type==='pcb_component'&&sourceNames.get(x.source_component_id)===name)
const outline=c.find(x=>x.type==='pcb_board')
check(outline.width===91&&outline.height===90,'V2 board must be 91 × 90 mm')
// Host mounting holes belong at the four corners, with a consistent 3.5 mm
// inset. The OLED's smaller module holes are checked separately below.
const hostHoles=c.filter(x=>x.type==='pcb_hole'&&!x.pcb_component_id)
const cornerPositions=[[-54.5,-23],[29.5,-23],[-54.5,60],[29.5,60]]
check(hostHoles.length===4&&cornerPositions.every(([x,y])=>hostHoles.some(h=>Math.abs(h.x-x)<1e-6&&Math.abs(h.y-y)<1e-6&&h.hole_diameter===3.2)), 'Host needs four 3.2 mm holes at the board corners')
const nav=['SW5','SW6','SW7','SW8'].map(pcb)
// 6x6 KH buttons: UP/DOWN/OK/BACK form one level row, left to right, on an 11 mm pitch.
check(nav.every(Boolean)&&nav.every(p=>Math.abs(p.center.y-nav[0].center.y)<1e-6)&&nav.every((p,i)=>i===0||Math.abs(p.center.x-nav[i-1].center.x-11)<1e-6), 'UP, DOWN, OK, BACK must form one level row in order on an 11 mm pitch')
check(nav.every(p=>p.center.y<51.35),'Navigation buttons must remain below the OLED')
check(pcb('RV1').center.x<-27.3-18.2&&pcb('RV1').center.y<60-3.2,'Speed dial must stay beside the display and below the upper-left corner hole')
check(pcb('SW4')?.rotation===270,'Side-actuated switch must retain 270° footprint rotation for OFF up / ON down')
for(const p of c.filter(x=>x.type==='pcb_component'&&sourceNames.has(x.source_component_id)))check(p.layer==='top',`${sourceNames.get(p.source_component_id)} must retain top-side assembly`)
// Connector is fully SMT; the bare display is an enclosure-mounted accessory.
const display=pcb('J21'), holes=c.filter(x=>x.type==='pcb_hole'&&x.pcb_component_id===display?.pcb_component_id)
check(holes.length===0,'Plug-in OLED must not add through-hole header or module holes')
const displayPads=c.filter(x=>x.type==='pcb_smtpad'&&x.pcb_component_id===display?.pcb_component_id)
check(displayPads.length===26,'J21 needs 24 contacts and two SMT anchors')
check(!sources.some(x=>x.name==='DISP1'),'Old through-hole display must be removed')
const sensor=pcb('U13'), sensorPads=c.filter(x=>x.type==='pcb_smtpad'&&x.pcb_component_id===sensor?.pcb_component_id)
check(sensorPads.length===6&&sensorPads.every(p=>Math.abs(p.width-0.67)<1e-6&&Math.abs(p.height-0.3)<1e-6),'TMP102 lands must match TI DRL0006A: 0.67 × 0.30 mm after 90° placement')
const sw=pcb('SW4'), swOrigin=sw?.footprint_origin
const switchCad=c.find(x=>x.type==='cad_component'&&x.pcb_component_id===sw?.pcb_component_id)
// No supplier model exists for the 8 mm lever; a JSCAD model follows the drawing.
check(!!switchCad?.model_glb_url&&switchCad?.rotation?.z===270,'SW4 CAD must use the SK-22D03-G080 coloured GLB model with the footprint rotation')
const swHoles=c.filter(x=>x.type==='pcb_plated_hole'&&x.pcb_component_id===sw?.pcb_component_id)
check(swHoles.length===8,'SK-22D03-G080 must have six contacts and two mounting legs')
for(const h of swHoles){
const pin=Number(h.port_hints.find(x=>/^pin\d+$/.test(x))?.slice(3))
if(pin>6)continue
const localX=({1:-2,2:0,3:2,4:-2,5:0,6:2})[pin]
const localY=pin<4?-1.249934:1.249934
check(swOrigin&&Math.abs(h.x-(swOrigin.x+localY))<2e-4&&Math.abs(h.y-(swOrigin.y-localX))<2e-4&&Math.abs(h.hole_diameter-.999998)<1e-6,`SW4.${pin}: 2.0 mm pitch, 2.5 mm row spacing, 1.0 mm drill`)
}
// Every pin stays on the PCB; only the plastic lever leaves the -X edge.
const board=c.find(x=>x.type==='pcb_board')
check(swHoles.every(h=>h.x-(h.outer_diameter??Math.max(h.outer_width,h.outer_height))/2-(board.center.x-board.width/2)>=.2),'SW4 pads keep 0.2 mm from the board edge')
// With the footprint at 270°, pins 1/4 (OFF contacts) are toward +Y.
const off=c.find(x=>x.type==='pcb_silkscreen_text'&&x.text==='OFF')
const on=c.find(x=>x.type==='pcb_silkscreen_text'&&x.text==='ON')
check(off?.anchor_position?.y>swOrigin?.y&&on?.anchor_position?.y<swOrigin?.y,'OFF / ON labels must match the contact ends')
for(const n of [93,94,95,96]){
const cap=sources.find(x=>x.name===`C${n}`)
check(Math.abs(cap?.capacitance-150e-6)<1e-10&&cap?.max_voltage_rating===50,`C${n}: reservoir must remain 150 µF / 50 V`)
}
// Component values supporting independent hardware shutdown, not only net names.
for(const [name,value] of [['R181',1000],['R182',68.1],['R183',100000],['R184',100000],['R185',15],['R186',100000],['R187',100000],['R188',4700],['R189',4700],['R190',10000],['R191',100000],['R192',54900],['R193',10000]])check(Math.abs((sources.find(x=>x.name===name)?.resistance??NaN)-value)<1e-6,`${name} resistance changed`)
const outputCap=sources.find(x=>x.name==='C183')
check(outputCap?.manufacturer_part_number==='CL31B475KAHNNNE'&&Math.abs(outputCap.capacitance-4.7e-6)<1e-12,'C183 must be the 4.7 uF / 25 V X7R output capacitor')
const hold=sources.find(x=>x.name==='C191')
check(hold?.manufacturer_part_number==='GVL0J332M1213'&&Math.abs(hold.capacitance-.0033)<1e-10&&hold.max_voltage_rating===6.3,'C191 must be the 3300 uF / 6.3 V reservoir')
check(!sources.some(x=>x.manufacturer_part_number?.startsWith('SC18IS606')),'OLED must remain native I2C without an SPI bridge')
const report={status:failures.length?'FAIL':'PASS',input,sha256:createHash('sha256').update(raw).digest('hex'),checkedPins:Object.keys(expected).length,failures}
mkdirSync('.tscircuit/checks',{recursive:true});writeFileSync('.tscircuit/checks/v2-hardware.json',JSON.stringify(report,null,2)+'\n')
console.log(JSON.stringify(report,null,2));process.exitCode=failures.length?1:0