cancel
Showing results for 
Search instead for 
Did you mean: 

HAL F4 six step commutation

b2527456
Associate II
Posted on November 11, 2014 at 13:28

Hello,

I have to port a BLDC motor control application, written using the old standard peripheral library, to the new HAL. The motor driver part was essentially based on the ''6step'' example code included in the std pheriph example folders.

I've tried to rewrite the commutation interrupt without breaking the HAL abstraction (using only exported function and avoid direct access o the registers) but it doesn't work. My question is: what is the correct approach to configure the timer OC(s) in the commutation interrupt using the new HAL?

Here's a portion the code of the new isr. I post only a case becouse the other five are similar. The new HAL dosen't export the old TIM_SelectOCxM(), TIM_CCxCmd() and TIM_CCxNCmd() command function so I've tried to replace it with new HAL functions.

case 2:

            /*  Channel1 */

            oc_config_struct.OCMode = TIM_OCMODE_PWM1;

            /* OC1: (phase A : Drive) */

            oc_config_struct.OCPolarity = TIM_OCPOLARITY_HIGH;

            HAL_TIM_PWM_ConfigChannel(htim, &oc_config_struct, TIM_CHANNEL_1);

            HAL_TIM_PWM_Start(htim, TIM_CHANNEL_1);

            /* OC1N: (NReset A : High (disable)) */

            HAL_TIMEx_PWMN_Stop(htim, TIM_CHANNEL_1);

            /*  Channel2 */

            oc_config_struct.OCMode = TIM_OCMODE_INACTIVE;

            /* OC2: (phase B : Sense (hi-Z)) */

            oc_config_struct.OCPolarity = TIM_OCPOLARITY_HIGH;

            HAL_TIM_OC_ConfigChannel(htim, &oc_config_struct, TIM_CHANNEL_2);

            HAL_TIM_OC_Start(htim, TIM_CHANNEL_2);

            /* OC2N: (NReset B : Low (enable)) */

            HAL_TIMEx_OCN_Start(htim, TIM_CHANNEL_2);

            /*  Channel3 */

            oc_config_struct.OCMode = TIM_OCMODE_PWM1;

            /* OC3: (phase C : NDrive) */

            oc_config_struct.OCPolarity = TIM_OCPOLARITY_LOW;

            HAL_TIM_PWM_ConfigChannel(htim, &oc_config_struct, TIM_CHANNEL_3);

            HAL_TIM_PWM_Start(htim, TIM_CHANNEL_3);

            /* OC3N: (NReset C : High (disable)) */

            HAL_TIMEx_PWMN_Stop(htim, TIM_CHANNEL_3);

            _step = 3;

            break;

#six-step
2 REPLIES 2
b2527456
Associate II
Posted on November 11, 2014 at 18:26

Solved, it works correctly. I've made a stupid mistake shadowing a structure with another one. Sorry :)

Posted on November 12, 2014 at 16:41

OK, perfect !

Thank you for your interset in our STM32Cube solution.

Cheers.

Heisenberg.