cancel
Showing results for 
Search instead for 
Did you mean: 

How do I set up a timer to capture the period of a waveform, without using and interrupt?

km.1
Associate

Hi, I'm trying to capture the period of a waveform without using an interrupt as the frequency will be up to 100Khz and will impact the system operation.

Currently I have the timer set up with interrupt on negative edge and record the captured value and subtract them to find the period.

Looking at the timer diagram TIMx_CH1->TI1F_ED->TRC->TRGI, can this path be used to restart the timer on a specific edge and capture the time as well before it is reset?

i.e. normal capture timer input, but have the timer reset by the same pin so it will always read the period of the signal in the capture register and I don't need an interrupt to know what the period was.

Anyone done this and care to share how this is done?

Many thanks

1 REPLY 1

Read the "PWM Input" section of TIM chapter in RM - it basically describes the same thing you've said above.

Note that there's a small unspecified number of cycles between capture and reset, i.e. your readings will be systematically of by a small number (maybe 2 or so). This may or may not be a problem for your application. One way to cope with this is to avoid the timer reset and store the captured values in RAM using DMA, to be processed instead of in interrupt, at any convenient time later.

JW