This is the documentation for the latest (main) development branch of HPM SDK. If you are looking for the documentation of previous releases, use the drop-down menu on the left and select the desired version.

14.2. BLDC FOC Control

14.2.1. Overview

The bldc_foc project contains the speed control, position control, and sensorless speed control of DC brushless motors.

  • Use the FOC control algorithm

  • Sensorless control algorithm for SMO

14.2.2. Configurations

14.2.3. Code Options

  • Add sdk_compile_options("-mabi=ilp32f") to the project’s CMakeLists.txt to get a higher performance

  • Set #define MOTOR0_SMC_EN (0) /*enable sliding mode control*/ in bldc_foc.c to 1 to enable SMO.

Note

This code does not support any compilation optimization, please turn off compilation optimization

14.2.4. Running the demo

14.2.4.1. With sensor

The motor runs at a speed of 20r/s. The following data can be configured by serial console :

speed float, range +40~-40, unit r/s

pos int, (-4000, +4000) corresponds to (-360, +360) degrees

mode bool, 1- Speed mode 0- Position mode

  • Speed mode

    Enter the correct speed parameters with serial console.

  • Position mode

    Set the position of the motor’s shaft, then the motor’s shaft will be locked at the specified position

14.2.4.2. Sensorless

The motor runs at a speed of 20r/s. The following data can be configured by serial console :

speed float, range (-40, -5) and (5, +40), unit r/s

The serial console message is as follows:

Mode selection:
1. Location mode.
2. Speed mode.
Enter mode code:

Location mode, motor run, The location is: 0.
Input Location:
 10000

Location mode, motor run, The location is: 10000.
Input Location:

Mode selection:
0. Location mode.
1. Speed mode.
Enter mode code:
1
Speed mode, motor run, speed is: 20.000000.
Input speed:
10.5

Speed mode, motor run, speed is: 10.500000.
Input speed:

Warning

  • After the motor is powered on, it will first perform the “alignment” action. If the motor is disturbed at this time, it will produce a jitter.

  • Pay attention to the current size, when abnormalities occur, please cut off the power at any time

  • When entering values for speed and position, a line break is required as an end-of-entry flag