cancel
Showing results for 
Search instead for 
Did you mean: 

Counting Rising Edge

mahmoud boroumand
Associate III
Posted on September 06, 2017 at 10:11

Hello 

I  use STDPERIPH_DRIVER .I want Counting a pulse and when it arrive to special number (100 Rising edge) I get an interrupt.How can i do that?

I do somthing like that 

TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;

TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;

TIM_ICInitStructure.TIM_ICFilter = 0x0;

TIM_ICInit(TIM3, &TIM_ICInitStructure);

TIM_ITConfig(TIM3, TIM_IT_CC4, ENABLE);

TIM_Cmd(TIM3, ENABLE);

void TIM3_IRQHandler(void)

{

if (TIM_GetITStatus(TIM3, TIM_IT_CC4) == SET)

{

TIM_ClearITPendingBit(TIM3, TIM_IT_CC4);

time_counter++;

if (time_counter == 100)

{

}

}

It work but when i use some mcu they wrok synchronization but after 7 or 8 hours they are not 

synchronization  and have  random delay between them.

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on September 06, 2017 at 10:44

Don't interrupt on every edge.

Use it as an external clock (TIMx_TS=0b101, TIMx_SMS=0x111), set TIMx_ARR to the required number of repetitions (you used 100 above) and then set interrupt to kick in upon update.

I don't use the 'libraries' so don't know how to do this using their functions, but 'external clock' should be a good starting point to search.

JW

View solution in original post

1 REPLY 1
Posted on September 06, 2017 at 10:44

Don't interrupt on every edge.

Use it as an external clock (TIMx_TS=0b101, TIMx_SMS=0x111), set TIMx_ARR to the required number of repetitions (you used 100 above) and then set interrupt to kick in upon update.

I don't use the 'libraries' so don't know how to do this using their functions, but 'external clock' should be a good starting point to search.

JW