cancel
Showing results for 
Search instead for 
Did you mean: 

How to write a working program to control a BLDC motor using STM32CubeIDE. X-Nucleo-IHM08M1, Nucle-f401RE

Kamil Wroński
Associate III

As I wrote above I just need to learn how to write a working program to control a BLDC motor using STM32CubeIDE. It's a general question, but I do not need more. I am trying to do it by myself for months, but I have no idea how to write my code correctly. Doesn't matter what I write, my program doesn't work. In attachment I am sending my current code, which makes my motor spin with about 8900rpm.

1 ACCEPTED SOLUTION

Accepted Solutions
uomo motore
Associate III

Hi Kamil,

The default unit for the speed in the library is 0.1Hz which translates to 6RPM per count. So when you write 1500, the speed set in RPM is actually 1500 * 6 = 9000 RPM. The simplest way to write speed in RPM is by specifying it as RPM/6 in the API. For example: to run your motor at 1500RPM you can write MC_ProgramSpeedRampMotor1(1500/6, 1000);

Another important point is that this is a buffered command and is only executed once the state machine converges to FOC (MC_GetSTMStateMotor1() return value changes to 6 or RUN).

In case of sensorless operation, the 1000msec ramp would usually start sometime after 'Minimum startup output speed' specified in startup parameters (The point from where library tries to converge to FOC from open loop startup) whereas in case of physical sensors like HALL and Encoders, this ramp will usually be executed as soon as the MC_StartMotor1(); is executed.

So when using sensorless operation the actual ramp is from somewhere around the 'Minimum startup output speed' till the specified speed in 1000msec while in case of Hall/Encoder it will be from 0 to specified speed in 1000msec.

View solution in original post

3 REPLIES 3
uomo motore
Associate III

Hi Kamil,

The default unit for the speed in the library is 0.1Hz which translates to 6RPM per count. So when you write 1500, the speed set in RPM is actually 1500 * 6 = 9000 RPM. The simplest way to write speed in RPM is by specifying it as RPM/6 in the API. For example: to run your motor at 1500RPM you can write MC_ProgramSpeedRampMotor1(1500/6, 1000);

Another important point is that this is a buffered command and is only executed once the state machine converges to FOC (MC_GetSTMStateMotor1() return value changes to 6 or RUN).

In case of sensorless operation, the 1000msec ramp would usually start sometime after 'Minimum startup output speed' specified in startup parameters (The point from where library tries to converge to FOC from open loop startup) whereas in case of physical sensors like HALL and Encoders, this ramp will usually be executed as soon as the MC_StartMotor1(); is executed.

So when using sensorless operation the actual ramp is from somewhere around the 'Minimum startup output speed' till the specified speed in 1000msec while in case of Hall/Encoder it will be from 0 to specified speed in 1000msec.

Kamil Wroński
Associate III

Hi.

Thank you very much. I have got one more question. What I need to change/add in my code to control my motor using HAL sensors?

You need to configure the Hall sensor parameters in the workbench under Motor Parameters>Sensors section and in Speed Sensing select Hall sensors using the ST Motor Control Workbench GUI. As the change from sensorless to Hall sensors requires initialization of additional timer for the Hall signals, you need to use 'Generate' option and not 'Update' while modifying the project. On the hardware side just make sure that the motor U,V,W and the Hall sensor H1, H2, H3 signal connection sequences are correct.