cancel
Showing results for 
Search instead for 
Did you mean: 

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

JA.1
Associate III

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?

1 ACCEPTED SOLUTION

Accepted Solutions
JA.1
Associate III

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.

View solution in original post

7 REPLIES 7
JA.1
Associate III

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
ST Employee

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

​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

If you agree with my answer, please consider accepting it by clicking on 'Accept as solution'.
JA.1
Associate III

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.
Dario CUCCHI
ST Employee

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...
Lead II

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

Best regards

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.