2020-05-13 05:44 AM
Hi,
I am using input capture of Timer2 Ch1 in stm8s003f3(20 pin uC). I had configured the timer 2 and provided pulses in PD4 pin , but i am not getting interrupt in Timer2 interrupt handler.
void InitTimer2(void)
{
TIM2_DeInit();
CLK->PCKENR1 |= 0x20; //Enable Peripheral Clock Tim1
//GPIOD->DDR &= 0xF7;
//GPIOD->CR1 |= 0x08;
TIM2->IER |= 0x02; //0x02 //Capture1 interrupt enable
//TIM2->EGR |= 0x02;
TIM2->CCMR1 |= 0x01; // CC1 channel is configured as input
TIM2->CCER1 |= 0x01; //Enable capture
TIM2->PSCR |= 0x07; //16MHZ/128 = 125KHZ
TIM2->ARRH = 0;
TIM2->ARRL = 0xFF; //8us counter
TIM2->CR1 = 0x01;
}
INTERRUPT_HANDLER(TIM2_CAP_COM_IRQHandler, 14)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
TIM2->SR1 = 0;
Count0= TIM2->CCR1L;
if (Count0 > Count1)
{
Count = (unsigned int)(Count0 - Count1);
}
else if (Count0 < Count1)
{
//Count = (unsigned int)(Count0 + (0xFFFFFFFF - Count1) + 1);
var1 = (0xFF - Count1);
var1 += 1;
Count = (unsigned int)(Count0 + var1);
}
else if (Count0 == Count1)
{
Count = (unsigned int)(0);
}
Count1 = Count0;
}
what is the mistake i have done ?. Plz anyone support very urgent.