Feelings of a BLDC Speed & Position Control

A project log for STM32 Blue pill IoT expansion boards

Expansion boards are designed to be easy to use in DIY IoT projects, low cost, reliable, saves the pain of cabling bread boards

WassimWassim 06/10/2017 at 18:260 Comments

Experimentation setup

Note on Safety:

Using a normal battery with experimental controller is dangerous and might lead to the test bench catching fire. Use either a fuse, a current limited power supply or a reliable controller.


The interesting part in this demo is not the revolution of turning a bldc for the first time, rather :

Open Loop Control : BLDC = Stepper motor

Control Parameters

Every new video or diagram about BLDC control allows me to understand something more, that's why, in spite of the number of documents and tutorials in the internet, why not add another simple view on this.


Sorry for placing source code as pictures but the source code plugin is so lame that the code is barely readable, so I keep the VSCode colors.

All the bldc magic is here. The angle is taken as an int to make it simpler, I'm not even using a proper unit as radions or degrees rather a 256/360° units so that it fits a 256 table where the sinus is porecessed once and stored as lookup.

PwmOut pwm1;

pwm1 = 1;
Well, that is good for an out of the box configuration and initialization. It does everything for you, from the cmsis HAL api calls to the calculation of which pins should be assigned to which alternate functions. It configures the pwm mode, all of that stack goes through the overload of that assignment operator which would have brought the function time from microsecond to millisecond.

That's why you see the direct usage of the registers which is around one instruction.



Once you control the speed and voltage simultaneously, you get a better feeling on when the motor stalls and misses steps, you can hold it and apply a higher voltage to see when it overcomes the torque applied. That is not science, but that is the experience that makes you comfortable to deal with the rest of the scientific formulas.

Next steps would be to look on a torque control loop, then maybe Back-EMF monitoring, designing a specific extension board for BLDC and meditate in front of Field Oriented Control videos. But what is sure is that for my plans of inverted pendulum mobile robot, this control is already enough.