Skip to main content
JA.1
Associate III
September 30, 2020
Solved

BLDC motor with hall sensor: Keep track of number of revolutions?

  • September 30, 2020
  • 6 replies
  • 2269 views

Hi there

I am using a B-G431B-ESC1 board with a BLDC motor with hall sensor.

The project is generated MC Workbench and is working just fine.

Now I need to know the number of revolutions that the motor have taken since it was started (for application purposes). Since the setup is with a hall sensor, this information must be available somewhere but I cannot find this information in the MC_Api.

Any ways to obtain this information?

This topic has been closed for replies.
Best answer by JA.1

If anybody else wants to know the number of revolutions of the motor here is my approach:

In the header file hall_speed_pos_fdbk.h:

  • Add to Includes section: #include "pmsm_motor_parameters.h"
  • Add to Defines section: #define STEPS_TO_REVOLUTION (2*POLE_PAIR_NUM*3)
  • Add to the struct HALL_Handle_t the following extra variables:
    • uint32_t RevolutionSteps;
    • uint32_t RevolutionCounter;

In the c file hall_speed_pos_fdbk.c:

  • Add in the function HALL_Clear(…):
    • pHandle->RevolutionSteps = 0;
    • This line resets the revolution counter so that only the number of revolutions from when the MC_StartMotor is called, is counted.
  • Add in the function HALL_TIMx_CC_IRQHandler(…):
    • Find this if-statement if (pHandle->Direction != PrevDirection) {…}
  • Add to the else part:
    • pHandle->RevolutionSteps++;
    • pHandle->RevolutionCounter = pHandle->RevolutionSteps / STEPS_TO_REVOLUTION;

Usage:

  • In your application, make sure to include mc_config.h.
  • Now you can access HALL_M1.RevolutionCounter, which contains the number of revolutions since the MC_StartMotor was called.

6 replies

JA.1
JA.1Author
Associate III
September 30, 2020

The IRQ interrupt handler on capture events is HALL_TIMx_CC_IRQHandler.

Do I need to implement my own logic for position count here, or am I missing an already implemented mechanism?

@DB.7ERGANTIN​ :)

cedric H
Technical Moderator
September 30, 2020

Hello,

"Since the setup is with a hall sensor, this information must be available somewhere but I cannot find this information in the MC_Api."

No, number of revolutions is not a useful information for the control algorithm. The information we use is just the time between two pulses.

So yes, you need to implement you own logic.

Regards

Cedric

DBE
ST Employee
September 30, 2020

​Hello,

If you want to monitor the number of revolutions since the start, then yes you have to implement your own logic. The purpose here is to compute the actual angle and speed that are used later on by the current and speed controller.

Best regards

JA.1
JA.1AuthorBest answer
Associate III
October 1, 2020

If anybody else wants to know the number of revolutions of the motor here is my approach:

In the header file hall_speed_pos_fdbk.h:

  • Add to Includes section: #include "pmsm_motor_parameters.h"
  • Add to Defines section: #define STEPS_TO_REVOLUTION (2*POLE_PAIR_NUM*3)
  • Add to the struct HALL_Handle_t the following extra variables:
    • uint32_t RevolutionSteps;
    • uint32_t RevolutionCounter;

In the c file hall_speed_pos_fdbk.c:

  • Add in the function HALL_Clear(…):
    • pHandle->RevolutionSteps = 0;
    • This line resets the revolution counter so that only the number of revolutions from when the MC_StartMotor is called, is counted.
  • Add in the function HALL_TIMx_CC_IRQHandler(…):
    • Find this if-statement if (pHandle->Direction != PrevDirection) {…}
  • Add to the else part:
    • pHandle->RevolutionSteps++;
    • pHandle->RevolutionCounter = pHandle->RevolutionSteps / STEPS_TO_REVOLUTION;

Usage:

  • In your application, make sure to include mc_config.h.
  • Now you can access HALL_M1.RevolutionCounter, which contains the number of revolutions since the MC_StartMotor was called.
Associate III
April 7, 2024

That was a great post JA.1. My problem was not the same as yours but your well thought out solution assisted me in solving my problem. 

Dario CUCCHI
Technical Moderator
October 8, 2020

Thanks @Community member​  for sharing your solution, very detailed and clear as well. I like it !

Keep it on :thumbs_up: :thumbs_up:

Laurent Ca...
Senior III
June 21, 2021

The question has been set only to the "STM32 Motor Control" topic (the question is only about the STM32 MC SDK). 

Best regards