2018-08-16 06:08 PM
void TIM5_IRQHandler(void)
{
/* USER CODE BEGIN TIM5_IRQn 0 */
printTIM5 = 1; //checks in main loop if set, then resets to zero and prints
if(__HAL_TIM_GET_ITSTATUS(&htim5, TIM_IT_UPDATE))
{
__HAL_TIM_CLEAR_IT(&htim5, TIM_IT_UPDATE);
if(counter == 22)
{
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_4);
}
counter++;
}
}
When I start Timer 4 after reaching counter equal to 22 (counter = 22), the interrupt of Timer 5 is no longer executed because I do no longer get the printf("TIM5") message. Why is that? What could be the reason? I am just confused right now...
IT Flags are cleared using the MXCube generated funtions (HAL_TIM_IRQHandler(&htim4);)
Thanks in advance
2018-08-16 06:18 PM
please don't print in an interrupt.
maybe toggle an IO pin.
you are inside the timer5 interrupt..
after 22 cycles, you trigger the PWM.
probably better to initialise the PWM once at startup and then adjust the duty cycle inside the interrupt.
I started my timer overflow ( period) to 1mS = 1KHz PWM period.
//read period timer value
int Period1KHz = htim1.Instance->ARR;
// set duty cycle
htim1.Instance->CCR2 = (Period1KHz / 2); // half the period is 50% duty cycle
2018-08-16 06:20 PM
if you want to print in an interrupt, you have to set a flag in the interrupt and a worker thread has to check the flag and send the printf.
2018-08-16 11:54 PM
While printf() in interrupt is a no-no, here the problem also may be in timer4 ISR (if any) exhausting mcu resources (e.g. by not clearing its status flags thus repeatedly executed infinitely), or falling into a fault.
JW