We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I don't know if the title is correct. This is the first time I use interrupt handlers. My problem is that I am trying to configure capture for one axis (axis 1) using PB8, TIM4, Channel3.
This is my code:
void TIM4_Config() { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); /* TIM4 channel 3 pin (PB8) configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_TIM4); TIM_ICInitTypeDef TIM_ICInitStructure; TIM_ICInitStructure.TIM_Channel = TIM_Channel_3; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = 84 - 1; TIM_ICInitStructure.TIM_ICFilter = 0x0; TIM_ICInit(TIM4, &TIM_ICInitStructure); irq_attach(STM32_IRQ_TIM4, handlerTimer4); up_prioritize_irq(STM32_IRQ_TIM4, 1); up_enable_irq(STM32_IRQ_TIM4); TIM_ITConfig(TIM4, TIM_IT_CC3, ENABLE); /* TIM enable counter */ TIM_Cmd(TIM4, ENABLE); } int handlerTimer4(int i, void* c) { if (TIM_GetITStatus(TIM4, TIM_IT_CC3) != RESET) { TIM_ClearITPendingBit(TIM4, TIM_IT_CC3); ++count; value = TIM_GetCapture3(TIM4); device_->GetCurrentPosition(OfaAxisEnum::OFA_Z, currentPosition); } else { TIM_ClearITPendingBit(TIM4, TIM_IT_CC3); } TIM_ClearFlag(TIM4, TIM_FLAG_CC3) ; }
The thing is that the handler gets called (I put a breakpoint inside the handler), but I am doing the capture setup inside a motion command. So the handler gets called while doing the motion, but I thing it will get stuck inside the handler because the motion doesnt happend.
I did the same thing(same code, except I changed timer, channel, and GPIO) for another axis (axis 0) using PI0, TIM5, Channel4, and it worked well.
Anyone has an idea what my problem could be ? I can't figure it out, the setup I guess should be ok if the handler its called.
TIM_ICInitStructure.TIM_ICPrescaler = 84 - 1;
Sorry that doesn't work like that, needs to be TIM_ICPSC_DIV[1,2,4,8] to decimate the input pulses.
If you want a time base of 1MHz, then program it as such.
Consider also how long it's in the function you call.
Hi,
Yeah, I should change TIM_ICInitStructure.TIM_ICPrescaler. I forgot those values there, but they worked for timer 5. Weird.
Also, what do you mean by checking how long is in the function I call ?
Thanks for the response.
Lots of interresting things can handle when an interrupt handler is too slow. The ISR might accidentally acknowledge the next interrupt.
In your case, you have a function call:
device_->GetCurrentPosition(OfaAxisEnum::OFA_Z, currentPosition);
that might possibly be slow compared to the tick frequency of the timer.
oops - should have written "can happen". Not sure how I managed "can handle"...