cancel
Showing results for 
Search instead for 
Did you mean: 

How to properly disable PWM on ST32L431?

Alex.Ag.
Associate II

I found that when after calling HAL_TIM_PWM_DeInit() the power consumption of the device is higher than it was before HAL_TIM_PWM_Init() called. The few investigations lead me to the fact that I need to reset ARR register to default value to reduce the consumption. So I started with:

void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim)

{

htim->Instance->ARR = ~0;

}

And Ok, the sequence

HAL_TIM_PWM_Init(&htim);

HAL_TIM_PWM_DeInit(&htim);

now works. Can't get the same result with

HAL_TIM_PWM_Init(&htim);

HAL_TIM_PWM_ConfigChannel(&htim, &sConfig, TIM_CHANNEL_1);

HAL_TIM_PWM_DeInit(&htim);

I don't even Start and Stop for now to reduce side effects.

For now my HAL_TIM_PWM_MspDeInit() looks like this:

void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim)

{

htim->Instance->CCER = 0;

htim->Instance->PSC = 0;

htim->Instance->ARR = ~0;

htim->Instance->CCMR1 = 0;

htim->Instance->CCR1 = 0;

htim->Instance->CR1 = 0;

htim->Instance->CR2 = 0;

}

So I reset all the registers that previous calls affected but the power consumption still high. Either something prevent device from sleeping or timer module still consume lot of power in sleep. I need to solve it somehow, but run out of ideas.

1 REPLY 1
Alex.Ag.
Associate II

False alarm, the cause is somewhere else in my code. Sorry.