cancel
Showing results for 
Search instead for 
Did you mean: 

Timer 1 counter resets intermittently

SBADV.1
Associate II

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);

2 REPLIES 2
MM..1
Chief III

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.