2024-04-09 10:55 AM - edited 2024-04-09 09:36 PM
My input capture interrupt is fired over and over again. But when i put a breakpoint in the interrupt, and resume from it, it does not happen anymore.
Timer setup:
// TIM 3 Inputs (Pedal rot - PB5 / Torc PWM - PB1)
my_GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_1;
my_GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
my_GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(GPIOB, &my_GPIO_InitStruct);
GPIOB->AFR[0] |= ( GPIO_AFRL_AFSEL1_1 | // AF2 (all)
GPIO_AFRL_AFSEL5_1);
__disable_irq();
__HAL_RCC_TIM3_CLK_ENABLE();
SET_BIT( TIM3->CCMR1, TIM_CCMR1_CC2S_0);
SET_BIT( TIM3->CCMR2, TIM_CCMR2_CC4S_0); // channel is configured as input, tim_ic1 is mapped on tim_ti1, etc...
// TODO: filter??
SET_BIT( TIM3->CCER, TIM_CCER_CC2E |
TIM_CCER_CC2NP |
TIM_CCER_CC2P |
TIM_CCER_CC4E |
TIM_CCER_CC4NP |
TIM_CCER_CC4P); // capture enable and Rising and falling edge
// TISEL default input channels
SET_BIT( TIM3->DIER, TIM_DIER_CC2IE | TIM_DIER_CC4IE); // enable interrupt on signal
SET_BIT( TIM3->CR1, TIM_CR1_CEN); // enable counter timer 3
NVIC_EnableIRQ(TIM3_IRQn); // enable global interrupt
SET_BIT(TIM3->EGR, TIM_EGR_CC2G); //force interrupt
__enable_irq();
Interrupt:
void TIM3_IRQHandler(){
GPIOC->BSRR = (uint32_t) GPIO_PIN_3;
if(READ_BIT(TIM3->SR, TIM_SR_CC4IF)){ // Torc PWM interrupt on CH4
unsigned long captValue = TIM3->CCR4; // read Capture register (resets interrupt flag)
unsigned long lastRisingEdge = 0;
unsigned long lastFallingEdge = 0;
if(READ_BIT(GPIOB->IDR, GPIO_PIN_1)){ // Rising edge
pwmDuty = (lastFallingEdge - lastRisingEdge) / (captValue - lastRisingEdge);
lastRisingEdge = captValue;
}
else{ // Falling edge
lastFallingEdge = captValue;
}
}
// if(READ_BIT(TIM3->SR, TIM_SR_CC2IF)){ // Pedal rotation
//
//
// }
SET_BIT(TIM3->SR, 0xFFFFFFFF);//TIM_SR_CC2IF | TIM_SR_CC4IF); // Clear any int flags
delayMicroseconds(1);
GPIOC->BRR = (uint32_t) GPIO_PIN_3;
}
.I checked the pin, which is not floating nor receiving any relevant noise.
Solved! Go to Solution.
2024-04-09 09:53 PM
Still it is very strange, that after a resume of the debugger, the interrupt was not fired anymore. Furthermore it is even more strange, that i can not reproduce this issue after the next morning. I think there might be a little bug in the "de"-bugger. It also wont upload now anymore.