cancel
Showing results for 
Search instead for 
Did you mean: 

Programing TIM2 in Input capture mode using STM8s003f3

Ajit Thorabale
Associate II
Posted on February 23, 2017 at 02:08

Hi

I am using 20 pin STM8s003f3 controller. I have programmed TIM2 channel 3(pin 10) in Input capture mode with capture to be made on falling edge detection on channel 3. I have enabled TIM2 capture/compare interrupt. I have also configured the option byte.

I am facing problem related to interrupt, there is no pulses or signals at channel input but still execution goes into the interrupt repeatedly. I am not getting what is problem.  Please see below TIM2 initialization and interrupt code.

   //TIM2 Initialization

    TIM2->PSCR = 0x04;     //Deviding incoming clock by 16 Fck_cnt = Fck_psc/(2^PSC[3:0]);

    TIM2->CCMR3 |= 0x01;  //CONFIGURING CHANNEL IN INPUT CAPTURE MODE

    TIM2->CCMR3 |= 0x10;  //INPUT SAMPLING UPTO TWO CLOCK CYCLES

    TIM2->CCER2 |= 0x02;  //SELECTING FALLING EDGE AS TRIGER SIGNAL

    TIM2->CCER2 |= 0x01; //ENABLED CAPTURE INPUT

    TIM2->IER |= 0x08;       //CAPTURE/COMPARE INTERRUPT IS ENABLED

    TIM2->CR1 |0x01;         //TIM2 ENABLED

INTERRUPT_HANDLER(TIM2_CAP_COM_IRQHandler, 14)

{

        GPIOD->ODR ^=0x10;  //Toggling PD4

        TIM2->SR1 &= 0xf7;    //clearing Capture flag

}

I am using STVD for program development. Thanks in advance.

0 REPLIES 0