Skip to main content
SBADV.1
Associate
Question

Timer 1 counter resets intermittently

I want to use count external pulses count coming on Timer 1 channel 1 .

I wrote following code. the couter starts counting as I apply external pulses.

but the counter doesnot go upto 65535 value. it gets reset intermittently.

I want to use counter to count incoming pulses continuously and also want to use its overflow interrupt. My code is as below. Please advice me how can I resolve the issue.

GPIO_Init(GPIOC, GPIO_PIN_1,GPIO_MODE_IN_FL_NO_IT );

 TIM1_DeInit();

 TIM1_TIxExternalClockConfig(TIM1_TIXEXTERNALCLK1SOURCE_TI1,TIM1_ICPOLARITY_RISING, 0x00);//(TIM1_CH1)

 TIM1_Cmd(ENABLE);

    This topic has been closed for replies.

    2 replies

    MM..1
    Super User

    Im not expert for STM8, but maybe your MCU make watchdog resets and you see it as timer resets...

    SBrow.1
    Associate II

    maybe try calling

    TIM1_TimeBaseInit(0, TIM1_COUNTERMODE_UP, 65535, 1);

    That way you explicitly set the max count to 65535.