cancel
Showing results for 
Search instead for 
Did you mean: 

X-CUBE-SPN1 problem with L6474: delayed step motor action after speed change

Central SUPPORT
Senior II

I'm using L6474h with X-CUBE-SPN1 Version 1.10.0. I think there is a bug with the X-CUBE-SPN1 library.

Step motor movement is delayed for a few seconds if the speed is adjusted more than two times (x2) of the previous speed. There is no problem if the speed changes less than or equal to two times.

I think the problem is with the states at backside in the library. You can try any stepping configuration. Problem is always same.

BSP_MotorControl_SetMaxSpeed(0,400); 
BSP_MotorControl_SetMinSpeed(0,200); 
BSP_MotorControl_Move(0,FORWARD,200); 
BSP_MotorControl_WaitWhileActive(0);
 
 // Speed is increased more than 2x times then
 // The following movement starts after 1-2 seconds. 
// Below; write 800 instead of 1000, and 400 instead of 500, then there is no delay. 
 
BSP_MotorControl_SetMaxSpeed(0,1000); // If this is 800(less than x2 times of previos speed then works fine 
BSP_MotorControl_SetMinSpeed(0,500);  // If this is 400(less than x2 times of previous speed then works fine  
BSP_MotorControl_Move(0,FORWARD,200); 
BSP_MotorControl_WaitWhileActive(0);

NOTE: This question and answer originated from a customer support case which was handled by us. We regularly review support cases and add any helpful ones here for all to benefit from.

1 ACCEPTED SOLUTION

Accepted Solutions
Central SUPPORT
Senior II

Please find below a fix to the reported issue.

In file: x_nucleo_ihm01a1_stm32f4xx.c

Patch the following functions as highlighted in BOLD:

void L6474_Board_Pwm1SetFreq(uint16_t newFreq)

{

 uint32_t sysFreq = HAL_RCC_GetSysClockFreq();

 uint32_t period = (sysFreq/ (TIMER_PRESCALER * BSP_MOTOR_CONTROL_BOARD_PWM1_FREQ_RESCALER * (uint32_t)newFreq)) - 1;

 if (period <  __HAL_TIM_GET_COUNTER(&hTimPwm1))

 { 

    __HAL_TIM_SET_COUNTER(&hTimPwm1, 0);

 }

   __HAL_TIM_SetAutoreload(&hTimPwm1, period);

void L6474_Board_Pwm2SetFreq(uint16_t newFreq)

{

 uint32_t sysFreq = HAL_RCC_GetSysClockFreq();

 uint32_t period = (sysFreq/ (TIMER_PRESCALER * BSP_MOTOR_CONTROL_BOARD_PWM2_FREQ_RESCALER * (uint32_t)newFreq)) - 1;

 if (period <  __HAL_TIM_GET_COUNTER(&hTimPwm2))

 { 

    __HAL_TIM_SET_COUNTER(&hTimPwm2, 0);

 }

void L6474_Board_Pwm3SetFreq(uint16_t newFreq)

{

 uint32_t sysFreq = HAL_RCC_GetSysClockFreq();

 /* Double the frequency as the SW is generated by SW */

 uint32_t period = (sysFreq/ (TIMER_PRESCALER * BSP_MOTOR_CONTROL_BOARD_PWM3_FREQ_RESCALER * (uint32_t)newFreq)) - 1;

 if (period <  __HAL_TIM_GET_COUNTER(&hTimPwm3))

 { 

    __HAL_TIM_SET_COUNTER(&hTimPwm3, 0);

 }

IMPORTANT NOTE: Problem applies to X-CUBE-SPN1 version 1.10.0. (or less) and might have been corrected in the meantime. Please double-check version numbers and make sure to download and use the latest version from st.com

View solution in original post

1 REPLY 1
Central SUPPORT
Senior II

Please find below a fix to the reported issue.

In file: x_nucleo_ihm01a1_stm32f4xx.c

Patch the following functions as highlighted in BOLD:

void L6474_Board_Pwm1SetFreq(uint16_t newFreq)

{

 uint32_t sysFreq = HAL_RCC_GetSysClockFreq();

 uint32_t period = (sysFreq/ (TIMER_PRESCALER * BSP_MOTOR_CONTROL_BOARD_PWM1_FREQ_RESCALER * (uint32_t)newFreq)) - 1;

 if (period <  __HAL_TIM_GET_COUNTER(&hTimPwm1))

 { 

    __HAL_TIM_SET_COUNTER(&hTimPwm1, 0);

 }

   __HAL_TIM_SetAutoreload(&hTimPwm1, period);

void L6474_Board_Pwm2SetFreq(uint16_t newFreq)

{

 uint32_t sysFreq = HAL_RCC_GetSysClockFreq();

 uint32_t period = (sysFreq/ (TIMER_PRESCALER * BSP_MOTOR_CONTROL_BOARD_PWM2_FREQ_RESCALER * (uint32_t)newFreq)) - 1;

 if (period <  __HAL_TIM_GET_COUNTER(&hTimPwm2))

 { 

    __HAL_TIM_SET_COUNTER(&hTimPwm2, 0);

 }

void L6474_Board_Pwm3SetFreq(uint16_t newFreq)

{

 uint32_t sysFreq = HAL_RCC_GetSysClockFreq();

 /* Double the frequency as the SW is generated by SW */

 uint32_t period = (sysFreq/ (TIMER_PRESCALER * BSP_MOTOR_CONTROL_BOARD_PWM3_FREQ_RESCALER * (uint32_t)newFreq)) - 1;

 if (period <  __HAL_TIM_GET_COUNTER(&hTimPwm3))

 { 

    __HAL_TIM_SET_COUNTER(&hTimPwm3, 0);

 }

IMPORTANT NOTE: Problem applies to X-CUBE-SPN1 version 1.10.0. (or less) and might have been corrected in the meantime. Please double-check version numbers and make sure to download and use the latest version from st.com