Skip to main content
Associate II
November 29, 2025
Question

problem running BLDC motor on STEVAL-ESC002V1using 6Step_lib function.

  • November 29, 2025
  • 1 reply
  • 180 views

Hello Folks,
I am facing an issue while controlling a BLDC motor using the STEVAL-ESC002V1 board. ST provides a reference firmware for this board which includes the 6Step Library for motor control. The firmware exposes functions such as:

  • MC_StartMotor()

  • MC_StopMotor()

  • MC_Set_Speed()

According to the documentation, these APIs should allow setting and controlling the motor speed.
I had paste the code which is written by me in main while loop. (For Reference)
ISSUE:
1. when the val(ADC value) goes above the 300, still the MC_StartMotor(), is not getting enable. Motor didn't run.
2. If I make changes into my code, delete by everything in the while loop and just try to run the motor at 10000rpm, by function MC_StartMotor() and MC_Set_Speed(10000).
As result of it as motor make a sound and vibration, not working smoothly.


hey it would be helpful to me, if someone help me to resolve this issue.

/* Includes ------------------------------------------------------------------*/
#include "main_32F0.h"
#include "6Step_Lib.h"
#include "MC_SixStep_param_7PP_3S_propeller.h"

/* Variables -----------------------------------------------------------------*/
extern SipMotorDriver_TypeDef STSPIN32F0MotorDriver;
extern TIM_HandleTypeDef IF_TIMx;
extern TIM_HandleTypeDef HF_TIMx;
extern TIM_HandleTypeDef LF_TIMx;
extern TIM_HandleTypeDef ZC_TIMx;
extern ADC_HandleTypeDef ADCx;
extern UART_HandleTypeDef huart;

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
#if defined(POTENTIOMETER)
static void MX_ADC_Init(void);
#endif
#if defined(ST_PWM_INTERFACE)
static void MX_IF_TIMx_Init(void);
#endif
static void MX_HF_TIMx_Init(void);
static void MX_LF_TIMx_Init(void);
static void MX_ZC_TIMx_Init(void);
#if defined(UART_COMM)
static void MX_UART_Init(void);
#endif

uint32_t val=0;
uint16_t adc;
uint32_t target_speed=0;


int32_t map_function(int32_t val, int32_t min_pot, int32_t max_pot, int32_t min_motor, int32_t max_motor);

uint16_t Read_ADC_PA6(void)
{
 HAL_ADC_Start(&ADCx);
 HAL_ADC_PollForConversion(&ADCx,20);
 return HAL_ADC_GetValue(&ADCx);
}
static uint32_t speed=0;
SIXSTEP_Base_InitTypeDef SixStep_Parameter;


uint8_t motor_status=0;


void run_motor(void)
{
 val= Read_ADC_PA6();
 target_speed=map_function(val,0,4040,0,20000);
 //target_speed= 4 * target_speed;
 target_speed =target_speed /1000;
 target_speed =target_speed *1000;

 if(speed < target_speed)
 {
 speed = speed +1000;
 MC_Set_Speed(speed);
 }
 else if(speed > target_speed)
 {
 speed = speed -1000;
 MC_Set_Speed(speed);
 }
 
}


int32_t map_function(int32_t val, int32_t min_pot, int32_t max_pot, int32_t min_motor, int32_t max_motor)
{

 return (val - min_pot) * (max_motor - min_motor) / (max_pot - min_pot) + min_pot;
}

uint32_t rpm_val=0;
 int main(void)
{

 /* MCU Configuration----------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();

 /* Configure the system clock */
 SystemClock_Config();

 /* Initialize all configured peripherals */
 MX_GPIO_Init();
#if (defined(POTENTIOMETER)||defined(CURRENT_SENSE_ADC)||defined(VBUS_SENSE_ADC)||defined(TEMP_SENSE_ADC))
 MX_ADC_Init();
#endif
#if defined(ST_PWM_INTERFACE) 
 MX_IF_TIMx_Init();
#endif
 MX_LF_TIMx_Init();
 MX_HF_TIMx_Init();
 MX_ZC_TIMx_Init();
#if defined(UART_COMM)
 MX_UART_Init();
#endif

 /* **************************************************************************** 
 ============================================================================== 
 ###### This function initializes 6-Step lib ######
 ============================================================================== 
 **************************************************************************** */ 
 MC_SixStep_INIT(); 
 MC_StartMotor();

 /****************************************************************************/
 
 /* Infinite loop */
 while (1)
 {
/*! **************************************************************************
 ============================================================================== 
 ###### How to use the 6Step FW Example project ######
 ============================================================================== 
 This workspace contains the middleware layer with Motor Control library to 
 drive a motor connected on STEVAL-ESC002V1 board performing a 6-step control
 algorithm allowing the motor speed regulation through PWM interface or UART 
 commands.
 The 6-step algorithm is voltage mode sensorless.
 
 A list of APIs in 6Step_Lib.h is provided to send user command to the 6Step
 library, for instance:
 
 (#) MC_StartMotor() -> Start the motor
 
 (#) MC_StoptMotor() -> Stop the motor
 
 (#) MC_Set_Speed(...) -> Set the new motor speed
 
 The MC_SixStep_param_32F0.h contains the files names of the MC parameters
 files. The user can add its own parameter file using one of the existing file
 as an example.
 
 ============================================================================== 
 ###### USER SPACE ######
 ============================================================================== 
 *****************************************************************************/ 

 
 //MC_Set_Speed(7000);
 rpm_val=MC_GetMechSpeedRPM();
 val=Read_ADC_PA6();
 if(val <300)
 {
 MC_StopMotor();
 
 }
 else if(val>300)
 {
 if(speed < 5000)
 {
 speed = speed +1000;
 MC_Set_Speed(speed);
 }
 HAL_Delay(800);
 while(1)
 {
 if(rpm_val <=5000)
 {
 run_motor();
 val= Read_ADC_PA6();
 if(val <300)
 {
 MC_StopMotor();
 break;
 }
 }
 }
 }
 }
}

 

1 reply

Senior III
November 29, 2025

You made the code complicated, my suggestion would be based on a switch / or any other interface, run the motor at fixed rpm and stop on button press. Once it starts running you can add ADC code.