Question
Capture Compare basic question
Posted on February 07, 2014 at 11:33
Hi Everybody,
I have a problem understanding the capture compare functionality.I want to use channel1 to fire an interrupt if a match between CCR and counter is detected. In this case, CCR1 is set to 0xFFF+1. So the interrupt should never rise, because the counter restarts at 0xFFF this works fine for the TIM_OCMode_Toggle initialized on Channel3. Why is the TIM_IT_CC1 interrupt raised each counter overflow?
http://guyvo-cortex.blogspot.de/2009/04/pulse-timers.html this guy describes how it works, but why do the interrupt rises when the pulse is higher than the counter counts?Can someone help me understanding this?
By the way, I'm using an STM32F4void
TIM_test(
void
)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_DeInit( TIM4 );
TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
TIM_TimeBaseStructure.TIM_Period =0xFFF;
TIM_TimeBaseStructure.TIM_Prescaler = 10000;
//((Prescaler/2)-1);
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
TIM_OCStructInit( &TIM_OCInitStructure );
TIM_OCInitStructure.TIM_OCMode =TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_Pulse = 0xFFF+1;
//When a match is found between the capture/compare register and the counter
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OC3Init(TIM4, &TIM_OCInitStructure);
TIM_OCStructInit( &TIM_OCInitStructure );
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_Pulse = 0xFFF+1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
TIM_ITConfig(TIM4,TIM_IT_CC1,ENABLE);
TIM_Cmd(TIM4, ENABLE);
}
#clive1 #capture-copmpare-stm32-tim