STM32 ESC PCB Design Requirements
Here are the requirements of this project that I’ve listed down in the following categories before starting to design or select any part of the BOM.
Power Requirements
- 12VDC input & Handle up to 30A continuous (360W)
- RPP (Reverse Polarity Protection) + TVS For The DC Input
- Bulk Capacitors Bank For The DC-Link Voltage
- 3.3V DC-DC Buck Converter (Logic Supply)
- Power Logic Supply Over USB if No DC Input Exists
Gate Driver & Inverter Requirements
- 3-Phase Half-Bridge Smart Gate Driver
- 3-Phase Inverter That Consists of 6x MOSFETs (Low Rdson, High Id)
Measurements For Motor Control
- Dual-Shunt Phase Current Measurement
- DC-Link Voltage & Battery Voltage Measurement
- DC Current (Battery Current) Measurement
- Inverter Bridge Temperature Measurement
- 3-Phase Voltages Measurement
- 3-Phase BEMF Zero-Crossing Detection
Microcontroller & Auxiliaries
- STM32G4 Motor Control Microcontroller
- USB 2.0 Full Speed (Data Transfer to GUI on PC)
- Onboard Buttons & Indicator LEDs
- NVM (8kB I2C EEPROM)
- Aux. UART Port
- Aux. ADC Input
DeepDrive v1.0 STM32 ESC Hardware HLD
At this stage, we can easily come up with a first draft for the whole system’s HLD (High-Level Design) that indicates the system’s hardware design breakdown for smaller HW blocks and their interfaces. This will facilitate the process of design and BOM selection.
Vital components can also be selected by the end of the HLD draft. After we’ve decided on the number of hardware interfaces needed (ADC channels, UARTs, IO pins, etc). So we can select the microcontroller part more specifically and also the smart gate driver & inverter bridge’s MOSFETs.
The BOM selection process will still be ongoing but it starts here at the HLD stage and will continue until the end of the footprints assignment, where we’ll be ready to start the PCB layout and routing. Before starting the PCB layout and routing, the BOM selection process must be complete and pretty much stable. Any change in the BOM afterward will take more time to accommodate going back and forth from PCB<->Schematic.
Here is the HLD of the DeepDrive v1.0 project.
STM32 ESC Schematic Design Diagram
Let’s now move to the most interesting part of the project, which is designing the circuits needed to complete the HLD (high-level design). We’ll go through the HW blocks mentioned in the HLD one at a time and discuss how to implement them and justify the design decisions that I’ve made during the design process.
For a more in-depth demonstration, it’s highly recommended to check out the project’s YouTube video as I go through the design decisions that I’ve made in this project with a bit more elaboration and explanation.
1. DC PWR In + RPP (Reverse Polarity Protection)
Here is the DC voltage input section of the ESC schematic design. There is a TVS diode that kicks in whenever the voltage goes beyond 30v, despite the fact that our input port is 12VDC. This is because the ESC will be switching an inductive load (BLDC/PMSM motor), so it’s expected to dump energy back into the supply while breaking or in fault conditions.
An inductor is also present on the DC input line for that purpose, to resist the back energy from the motor to protect my uni-directional power supply (regenerative breaking is not supported in this ESC design). The inductor helps also in reducing inrush current during power up that happens due to the large DC-Link voltage capacitors bank.
2. Logic Supply (DC-DC Buck Converter)
We need to step down the 12v DC input voltage to 3.3v in order to supply the STM32 core as well as various logic elements and measurement circuits across the board. Supporting up to 4.5A is definitely overkill compared to the actual needs of the project, this will be optimized in the upcoming revision of the board.
An LDO could have been used instead to reduce the BOM cost significantly and the switching noise of the buck converter. However, stepping down a 12VDC to 3.3v will generate a significant power loss (heat).
3. Gate Driver + 3PH Inverter Bridge + RC Snubbers
I’ve decided to go for a Ti DRV8302 smart gate driver which I’ve been using in other designs and motor control ECUs. It costs only 3US$ in the JLCPCB parts library, which is a very good value for money as far as I know.
The DRV8302 gives us the basic hardware fault detection that we’d expect from a smart gate driver as well as internal 2x current sensing op-amps with Vref/2 offset voltage built-in. It’s got a HW programmable deadtime, overcurrent detection, and op-amp gain. It’s also a built-in buck converter that I could have used instead of what I’ve built earlier but I’ll do this optimization in the next revision I believe.
4. Phase Current Measurement (Dual Shunt)
For the 3-phase current measurement, I’ve decided to go for a dual shunt configuration. It’s very easy to implement in software and it doesn’t cost very much in terms of hardware needed. Here is a summarized comparison between all 3 different configurations that you may encounter while studying this subject.
Triple Shunt: This is obviously the most expensive solution among all while being the easiest to implement in software. The third shunt resistor is actually redundant if you’re going to code the current reconstruction equation by yourself as I’ll demonstrate hereafter in the dual shunt method.
Dual Shunt: This is the most balanced option among all in terms of cost and ease of implementation in software. You can easily read 2x phase currents using the dual shunt configuration and reconstruct the third phase current using the equation ( iU + iV + iW = 0 ).
Single Shunt: This is obviously the cheapest solution of all. However, it’s way more complex to set up the ADC triggering to get the reading of the shunt resistor’s channel at the correct moment to get iU & iV, then you can reconstruct the iW phase current. It also forces you to complicate the SVM switching sequence in order to mitigate blind zones (where PWM edges overlap each other).
5. BEMF (Back EMF Sensing) + PHV Measurement
For sensorless FOC control, we need to measure the phase voltages & BEMF. This can be simply achieved by creating the 3x voltage divider networks shown in the schematic design below. However, the BEMF measurement is relative to the motor’s neutral point. In many 3-phase motors, you may not have access to the N-line (only 3 wires UVW).
That’s why we should also construct the star network of resistors shown below in order to create a virtual neutral point that can be used to find the absolute BEMF voltages and also for the BEMF ZCD (zero-crossing detection).
By taking the virtual neutral point and any floating phase voltage (BEMF) and feeding both signals to a comparator, we’ll end up having a back-EMF zero-crossing detector.
6. ZCD (3x Zero-Crossing Detectors)
As discussed in the previous section, we’ll feed all 3x phase voltages & the virtual neutral point to 3x comparators to achieve zero-crossing detection for the three phases’ BEMF. Which is crucial for BLDC’s six-step commutation drive.
The 3x ZCD output digital signals will go to external interrupt pins on the STM32G4 microcontroller.
7. DC Current Measurement
The DC current measurement is required to calculate the input electric power which can be useful for implementing software power-limiting algorithms. And it can be extremely useful in IPD (initial position detection) algorithms. IPD is a very important feature in many motor drive systems, so we need to have an accurate DC current measurement circuitry.
Here’s my design decision for the DC current measurement. I’ve decided to use the RPP MOSFET’s characteristic internal resistance (Rdson) as a current sensor. I’ve connected the RPP MOSFET’s drain and source pins to the differential amplifier shown below.
This should “theoretically” work fine for low current measurements. As the current goes higher, the MOSFET’s temperature increases, and the (Rdson) increases consequently (almost linearly). This can be compensated for in software but I’ll do some tests and maybe post a YouTube video about the whole topic and show you the test results.
The initial test shows a 2mv output while 0.026mA is drawn by the whole ECU from the power supply. Given that the differential amp gain is 44.4, then the measured VDS across the RPP MOSFET is 45μv. At room temperature & VGS=12v, then the Rdson is expected to be 1.8mΩ.
8. VBAT & DC-Link Voltage Measurement
To be able to measure the battery input DC voltage & the DC-Link voltage, we need to step it down within the 3.3v range of the microcontroller’s ADC. And this can be easily achieved using a voltage divider network as you can see in the schematic design below. Just add a filtering capacitor and you’re all set up and ready to go.
9. Temperature Measurement
Measuring the inverter bridge MOSFETs’ temperature is extremely important for an ESC motor control system. It enables us to protect the output driver stage from thermal runaway and make sure the MOSFETs are operating in the SOA (safe operating area).
Temperature measurement makes it possible for us to implement thermal derating algorithms to limit the motor’s speed or power according to a certain programmable trajectory of our choice. This can be a really useful feature to implement in your drive system.
Given that the logic supply 3.3v is very stable, we can simply use a resistor as a CCS (constant current source). And use it to bias the BJT in a diode configuration and measure the VBE voltage. The 33kΩ resistor pushes 100μA of current into the BJT, which means the BJT’s temperature coefficient is setting at around (-2.0mv/°C).
10. ADC Inputs Protection
To further protect the STM32 ADC input channels’ pins, we’ll use Schottky barrier diodes to clip the voltage if it exceeded Vdd(3.3v) at any point in time. This is done by using the dual Schottky diode BAT54C devices as shown in the schematic design below.
11. STM32G431 uC Circuitry (OSC / AVDD / SWD)
The core of this system is the STM32G431 microcontroller. We’ll connect an external oscillator (16MHz) to our microcontroller as well as some bypass capacitors, and a reset button.
We can easily connect the pin labels to the microcontroller in the schematic capture according to the project settings using the CubeMX project configurator. Enable all the needed hardware analog/digital peripherals and connect their pons accordingly.
12. USB 2.0 FS + ESD + PWR
In this project, I’ll use USB 2.0 Full-Speed for communication with a GUI application on the PC. This will be useful for motor commanding, monitoring, parameters detection & setting, calibration, and more.
I’ve added ESD protection for the USB lines and optional power to the microcontroller (logic supply only) in case the 12v DC supply is missing.
13. uC Aux (AIN / UART / BTNs / LEDs)
There are some auxiliary peripherals onboard for user-defined applications. Those are as follows:
- 2x Push Buttons
- 1x UART Port
- 1x AIN (Analog input)
- 3x LEDs
14. NVM (8kB I2C EEPROM)
There is an onboard NVM (non-volatile memory) chip which is an 8kB I2C EEPROM that can be used for storing data permanently. The data to be saved/retrieved from the NVM may be any or all of the following:
- Application Parameters
- Motor Parameters
- Calibration Parameters
- Fault Log