PCB Assembly Challenges
flux
JLCPCB Pick-and-place
| Designator | Layer | Rotation | Mid X | Mid Y |
|---|---|---|---|---|
| C1 | Top | 0 | -3.6mm | -23mm |
| C2 | Top | 0 | 8.75mm | 29.25mm |
| C3 | Bottom | 0 | 9.5mm | 16.85mm |
| C4 | Bottom | 0 | 11mm | 13.9mm |
| C5 | Bottom | 90 | 13.6mm | 15.7mm |
| C6 | Top | 180 | 8.7mm | 26.1mm |
| C7 | Top | 180 | 12.35mm | 26.1mm |
| C8 | Top | 90 | 3.925mm | 8.62mm |
| C9 | Bottom | 180 | -5.7mm | 9mm |
| C10 | Bottom | 270 | 13.25mm | 24.4mm |
| C11 | Bottom | 90 | 10.9mm | 20mm |
| C12 | Bottom | 0 | 12.8mm | 30mm |
| C13 | Bottom | 0 | 12.975mm | 9.5mm |
| C14 | Bottom | 90 | 13.2mm | 4.5mm |
| C15 | Bottom | 0 | 10.8mm | 2mm |
| C16 | Bottom | 90 | 10.3mm | 4.6mm |
| C17 | Bottom | 0 | -11.4mm | -9mm |
| C18 | Bottom | 0 | -6.8mm | -9mm |
| C19 | Bottom | 0 | -1.7mm | -9mm |
| C20 | Bottom | 0 | 2.9mm | -9mm |
| C21 | Bottom | 0 | 7.5mm | -9mm |
| C22 | Bottom | 0 | 12.2mm | -9mm |
| C23 | Bottom | 0 | -10.8mm | -13mm |
| C24 | Bottom | 270 | -6.8mm | -13mm |
| C25 | Bottom | 90 | -2mm | -13mm |
| C26 | Bottom | 0 | 3mm | -13mm |
| C27 | Bottom | 180 | -12mm | 1mm |
| C28 | Bottom | 0 | 6.2mm | -1mm |
| C29 | Bottom | 270 | -5.5mm | 1mm |
| C30 | Bottom | 90 | -2mm | 1mm |
| C31 | Bottom | 0 | 1.5mm | 1mm |
| C32 | Top | 0 | 4.1mm | 5.5mm |
| C33 | Bottom | 0 | 10.5mm | -5.3mm |
| C34 | Bottom | 0 | 7.8mm | 3.2mm |
| C35 | Top | 90 | 7.2mm | 16.6mm |
| C36 | Bottom | 90 | 11.95mm | 16.5mm |
| D1 | Top | 180 | -9.2mm | -14mm |
| D2 | Top | 180 | -9.2mm | -7mm |
| D3 | Top | 180 | 2mm | -14mm |
| D4 | Top | 180 | 2mm | -7mm |
| D5 | Top | 180 | 6.3mm | -28.2mm |
| F1 | Top | 270 | 12.25mm | -22.2mm |
| J1 | Top | 0 | 9mm | -41.67mm |
| J2 | Top | 0 | 10.57mm | 36mm |
| L1 | Top | 0 | 10.8mm | 21.6mm |
| L2 | Top | 0 | -7mm | 4mm |
| LED1 | Top | 0 | -0.8mm | 32.7mm |
| LED2 | Top | 0 | 2.7mm | 32.7mm |
| Q1 | Top | 0 | 11.53mm | -0.6mm |
| Q2 | Top | 0 | 10.83mm | -8mm |
| R1 | Bottom | 180 | 10mm | 8.6mm |
| R2 | Bottom | 0 | -1mm | 9.5mm |
| R3 | Bottom | 90 | 12.9mm | 20.7mm |
| R4 | Bottom | 0 | -0.8mm | 34.6mm |
| R5 | Bottom | 0 | 5.5mm | 10mm |
| R6 | Bottom | 180 | 13mm | 7mm |
| R7 | Bottom | 0 | 12.4mm | 11.3mm |
| R8 | Bottom | 0 | 2mm | 10mm |
| R9 | Bottom | 0 | 5.5mm | -4.6mm |
| R10 | Bottom | 270 | 8mm | -4.6mm |
| R11 | Bottom | 270 | 11mm | -1mm |
| R12 | Bottom | 0 | -12.5mm | -5mm |
| R13 | Bottom | 180 | -9mm | -5mm |
| R14 | Bottom | 0 | -5.5mm | -5mm |
| R15 | Bottom | 0 | -2mm | -5mm |
| R16 | Top | 0 | -8.8mm | 32.3mm |
| R17 | Top | 0 | 4.3mm | 34.6mm |
| R18 | Bottom | 90 | 10.05mm | 10.9mm |
| R19 | Bottom | 0 | 8.45mm | 10.9mm |
| R20 | Bottom | 0 | 11.5mm | 6.85mm |
| U1 | Top | 180 | 10.1mm | 7.15mm |
| U2 | Top | 90 | 1.2mm | 5.5mm |
| U3 | Top | 0 | 10.8mm | 16mm |
| U4 | Top | 0 | -3.4mm | 21.03mm |
| U5 | Top | 180 | 3mm | 1mm |
Failed to load 3D model
Table
| Function | ESP32 GPIO | Schematic net | Direction | Notes |
|---|---|---|---|---|
| DCC waveform | GPIO25 | DCC_SIG | Output | Drives DRV8873 EN/IN1 and U2 inverter input. Use RMT peripheral for accurate DCC timing. |
| DCC inverted | n/a | DCC_SIGN | Output via U2 | 74LVC1G04 generates complement into DRV8873 PH/IN2. |
| H-bridge sleep | GPIO26 | DRV_SLEEP | Output | Hardware pulldown keeps bridge asleep at boot; drive HIGH after init. |
| H-bridge fault | GPIO27 | DRV_FAULT | Input pullup | DRV8873 nFAULT, active-low open drain with 10 kΩ pull-up. |
| Current sense | GPIO36 / SENSOR_VP | ISENSE | ADC input | DRV8873 IPROPI1/2 summed through 820 Ω to GND. Approx V = I_highside_sum/1100*820. |
| UART0 RX | GPIO3 / RXD0 | UART_RXD0 | Input | External USB-UART TX connects here through J3. |
| UART0 TX | GPIO1 / TXD0 | UART_TXD0 | Output | External USB-UART RX connects here through J3. |
| Boot strap | GPIO0 | BOOT_IO0 | Input | Pull low during reset for UART download mode. |
| Enable/reset | EN | EN | Input | 10 kΩ pull-up and 1 µF RC delay; J3 can reset module. |
Ini
[env:esp32dev] platform = espressif32 board = esp32dev framework = arduino monitor_speed = 115200 upload_speed = 921600 lib_deps = links2004/WebSockets@^2.6.1
Cpp
#include <Arduino.h> #include <WiFi.h> #include <WebSocketsClient.h> #include "driver/rmt.h" // Pin definitions from schematic #define DCC_SIG_PIN 25 #define DRV_SLEEP_PIN 26 #define DRV_FAULT_PIN 27 #define ISENSE_ADC_PIN 36 #define BOOT_PIN 0 // WiFi / WiThrottle placeholders const char* WIFI_SSID = "YOUR_SSID"; const char* WIFI_PASSWORD = "YOUR_PASSWORD"; const char* JMRI_HOST = "192.168.1.10"; const uint16_t JMRI_PORT = 12090; WebSocketsClient ws; // DRV8873 current sense: IPROPI ~= I_HS / 1100, R = 820 ohm. constexpr float ADC_REF_V = 3.3f; constexpr int ADC_MAX = 4095; constexpr float IPROPI_R_OHMS = 820.0f; constexpr float IPROPI_RATIO = 1100.0f; constexpr float OVERCURRENT_A = 5.5f; void bridgeSleep(bool asleep) { digitalWrite(DRV_SLEEP_PIN, asleep ? LOW : HIGH); } float readBridgeCurrentAmps() { int raw = analogRead(ISENSE_ADC_PIN); float volts = (raw * ADC_REF_V) / ADC_MAX; return (volts / IPROPI_R_OHMS) * IPROPI_RATIO; } void checkFaults() { bool fault = digitalRead(DRV_FAULT_PIN) == LOW; float currentA = readBridgeCurrentAmps(); if (fault || currentA > OVERCURRENT_A) { bridgeSleep(true); Serial.printf("Bridge disabled: fault=%d current=%.2f A\n", fault, currentA); } } void initDccRmt() { rmt_config_t config = {}; config.rmt_mode = RMT_MODE_TX; config.channel = RMT_CHANNEL_0; config.gpio_num = (gpio_num_t)DCC_SIG_PIN; config.clk_div = 80; // 1 us ticks from 80 MHz APB config.mem_block_num = 1; config.tx_config.loop_en = false; config.tx_config.carrier_en = false; config.tx_config.idle_output_en = true; config.tx_config.idle_level = RMT_IDLE_LEVEL_LOW; rmt_config(&config); rmt_driver_install(config.channel, 0, 0); } void sendDccPreambleDemo() { // Demo only: produces several DCC '1' bits, each half-bit ~58 us. rmt_item32_t items[16]; for (int i = 0; i < 16; i++) { items[i].level0 = 1; items[i].duration0 = 58; items[i].level1 = 0; items[i].duration1 = 58; } rmt_write_items(RMT_CHANNEL_0, items, 16, true); } void wsEvent(WStype_t type, uint8_t* payload, size_t length) { switch (type) { case WStype_CONNECTED: Serial.println("Connected to JMRI/WebSocket placeholder"); break; case WStype_TEXT: Serial.printf("JMRI message: %.*s\n", (int)length, payload); // TODO: parse WiThrottle protocol and convert speed/function packets to DCC packets. break; case WStype_DISCONNECTED: Serial.println("JMRI disconnected"); break; default: break; } } void initWiFi() { WiFi.mode(WIFI_STA); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.print("Connecting WiFi"); for (int i = 0; i < 40 && WiFi.status() != WL_CONNECTED; i++) { delay(250); Serial.print('.'); } Serial.println(); if (WiFi.status() == WL_CONNECTED) { Serial.printf("WiFi connected: %s\n", WiFi.localIP().toString().c_str()); } else { Serial.println("WiFi not connected; DCC demo still available over serial."); } } void setup() { Serial.begin(115200); delay(200); Serial.println("TMCC WiFi DCC 5A module firmware starting"); pinMode(DRV_SLEEP_PIN, OUTPUT); bridgeSleep(true); // keep H-bridge off during setup pinMode(DRV_FAULT_PIN, INPUT_PULLUP); pinMode(DCC_SIG_PIN, OUTPUT); digitalWrite(DCC_SIG_PIN, LOW); analogReadResolution(12); analogSetPinAttenuation(ISENSE_ADC_PIN, ADC_11db); initDccRmt(); initWiFi(); ws.begin(JMRI_HOST, JMRI_PORT, "/"); ws.onEvent(wsEvent); ws.setReconnectInterval(5000); bridgeSleep(false); // enable DRV8873 after GPIO/RMT are stable } void loop() { ws.loop(); checkFaults(); static uint32_t lastDemo = 0; if (millis() - lastDemo > 1000) { lastDemo = millis(); sendDccPreambleDemo(); Serial.printf("Current estimate: %.2f A\n", readBridgeCurrentAmps()); } }
platformio.ini above and place the source in src/main.cpp.pio runpio run -t uploadpio device monitorPlatform & Toolchain
Pin Mapping
Dependencies & Project Setup
Complete Firmware Source
Build & Flash Instructions
Open Firmware Items