AnsweredAssumed Answered

STM32F103 - TIM1 PWM Interrupt not working?

Question asked by ReV Hulk on Apr 17, 2017
Latest reply on Apr 21, 2017 by ReV Hulk

Hi, I'm using STM32F103RBTx MCU and I generate my code using CubeMX (v4.20.1).

I need PWM output on 2 Pin: Timer1 - Channel 1 and Timer4 - Channel 4.

These 2 PWM signal is used to control 2 separated DC motors.

I configure them both with Internal Clock and selected the correct PWM Channel output.

 

In the Configuration Tab, I select the Prescaler & Counter Period for both timers (PWM Mode 1).

Since I need to use the interrupt to toggle some LEDs, so I enable only "TIM1 Update Interrupt" and "TIM4 Global Interrupt".

 

In my code, after the some initialization functions from HAL. I started each Timer with:

MX_TIM1_Init();
MX_TIM4_Init();

//.......

......//

 

HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_1);
HAL_TIM_PWM_Start_IT(&htim4, TIM_CHANNEL_4);

 

And with the Interrupt Handler, I used:

void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim){
      if (htim -> Instance == htim1.Instance){                         //Timer1-CH1
            HAL_GPIO_TogglePin(GPIOB, OP_LEDA_Pin);      //Toggle LEDA
      }else{                                                                              //Timer4-CH4
            HAL_GPIO_TogglePin(GPIOB, OP_LEDB_Pin);      //Toggle LEDB
      }
}

With my setup, both DC motors received its correct PWM signal. However, only LEDB toggles, LEDA doesn't.

When I debug, the pointer only stop inside htim4.Instance, which means Timer4 works as expected. But it just doesn't stop inside htim1.Instance. I don't know what I'm missing with Timer1?

 

Could anyone help me figure out what I did wrong?

Regards,

ReV.

Outcomes