Motor control board Mk2
This is a continuation of the original STM32-powered motor control board.
The goals for this version are:
-
Make is smaller. The original one is 20x20mm and was targeted to fit into buildings (this one, to be precise). The new one is half the size and aimed to fit into vehicles in 1/87 scale like trucks and trailers. To achieve this, the board has these features:
-
does not have a linear regulator IC anymore. Battery power is directly supplied to MCU. The MCU is chosen to run directly on a single-cell Li-Ion battery. It is even 5V-capable, which is a rare thing among 32-bit MCUs, and ARM ones in particular. Running at higher voltage also gives headroom for LEDs voltage drop.
-
MCU is in QFN20 3x3mm package (while the previous STM32G0 was a legged TSSOP20).
-
PCB now has 4 layers instead of 2 (with higher tolerances and smaller features available for 4 layer PCBs).
-
DCC interface is removed (I never used it on 1st design anyway).
-
-
Increased the number of LED pins. The original board had around 3 outputs available for LEDs. The new one has 13 GPIOs routed out. Some of those conflict with motor control pins, so not every function can be used in parallel with motor.
-
Embedded current-limiting resistors for LED outputs. There are now 2 resistor networks, each with 4 resistors, so 8 LEDs can be connected directly.
-
Provides PWM to as many LED pins as possible (even when motors are used).
Control still comes in form of UART signals. It can also be changed to RC PPM by changing software (though this is not implemented as it was never needed). For logging (and potential functionality extension), UART TX pin is on the same header.
Programming happens via 1mm-spaced pads for pogo pins. A dedicted resin-printed holder is made for this. The technology was first tested on RC-BLE project.
A new MCU
For 4.2V compatibility, originally I planned to use newer-generation AVRs, but then decided to look into ARMs because of more advanced toolchains (mostly full C++ support in GCC) and more features in general.
Around that time there appeared articles about the cheapest general-purpose MCUs. First I read about WCH’s CH32V RISC-V MCUs, but then an article about Puya’s PY32 surfaced. The MCUs are very cheap (which is not particularly improtant for DIY), are compatible with STM32 to a large extent (which is rather important), and, most importantly for this project, can run from up to 5V.
As with STM32s, documentation is split into Datasheet and User Manual. (Pinout is best viewed in the datasheet, while register definitions and function descriptions are in user manual). In general, the documentation feels very much inspired by ST’s.
In terms of support, the manufacturer provides a decent datasheet in English (which is already generous for a chinese IC manufacturer), and SDK with examples, and it seems they have their own IDE and pached OpenOCD. There is OpenPuya effort to maintain an English documentation pages, a EEVBlog thread about the IC, and some github repositories with various information.
The PY32F003 MCU comes in surprisingly many pinout options. For example, there are 2 QFN20 options and whooping 7 TSSOP20 variants! They differ in what pins are routed out, because the sillicon has too many available pins for small packages. I carefully chose the QFN20 (3x3mm) variant with most timer outputs routed out, in addition to UART and SWD. Then I looked at available stock at LCSC, and chose PY32F003F18U6TR option. It has 64Kb flash and 8Kb of RAM, and it is quite sufficient for the task.
Useful links
PlatformIO platform and framework
I do most of my hobby development with PlatformIO, which of course is missing support for this MCU. So I developed PIO platform and framework for PY32F003, which are avilable here: https://github.com/positron96/platform-py32f0, https://github.com/positron96/framework-py32f0sdk. It includes all the code from py32f0-template above, so should support other ICs as well, I just never checked because I don’t have any.
v1.0
First version was sent to fabhouse in November 2024. It has 4 discrete H-bridges, DRV8837 (chosen for their small footprint and low price). Each H-bridge requires 2 PWM pins, so 8 PWM pins in total are occupied when motors are in use. 9 PWM pins are available on MCU package, leaving only 1 pin dedicated to LED outputs. To improve situation at least a tiny bit, the pinout is arranged in a way that motors occupy pins from the end (outputs 1 and 2 are shared with motor 4, etc), so if not all motors are used, free LED pins start from beginning.
In addition to current-limited GPIO outputs, the board also has a current-limited VCC to have an always-on output.
The PCB worked without problems, but there are things that could be improved, most notably the number of available PWM outputs. So v2 was developed.
v2.0
Latest version to date, it includes these new features:
-
Dual H-bridge with PWM/DIR control (DRV8835). To maximize PWM availability, motor drivers are controlled with PWM+DIR scheme instead of IN1/IN2, thus requiring only 1 PWM pin per motor (instead of 2 previously). As a result, 9 output pins are PWM-capable, and 5 of those are not shared with motors (so can be used in parallel with motors).
-
Optimized pinout, no current-limited always-on outputs anymore, all are GPIOs.
-
All GPIO pins on MCU are in use, even BOOT0 pin. Every pin possible is routed to a solderable PAD.
-
Castellated holes (for easier soldering of wires and make more space on PCB) The feature adds quite a lot to PCB cost, I only did it because I had a coupon, otherwise it isn’t necessary.
-
1 more bulk capacitor near motor outputs, both caps are moved to top of the board.
-
Has a power-on LED on board.
-
Theoretically should it should be easy to chop the motor part if only LEDs are needed (I added extra holes along the cut line).
-
Rounded edges!