cancel
Showing results for 
Search instead for 
Did you mean: 

Taking time in microsecond without using interrupts

oli
Associate II
Posted on January 08, 2015 at 13:37

Hello

I'm looking for a solution to get the time between to input signals in microsecond resolution.

But I do not want to use an interrupt counting up all microseconds.

Is there a convenient solution / method?

#stm32f4
9 REPLIES 9
Posted on January 08, 2015 at 14:37

Isn't this the typical task for Timer Capture?

JW
Posted on January 08, 2015 at 14:42

In hardware TIM Input Capture, in software use a free running counter, ideally at 32-bit one.

For processor level ticks there's DWT_CYCCNT, for something you can divide to 1MHz (or whatever) a 32-bit TIMx->CNT

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Systick%20Delay%20functions&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx&currentviews=29]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2fSystick%20Delay%20functions&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https%3A%2F%2Fmy.st.com%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FAllItems.aspx¤tviews=29
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
oli
Associate II
Posted on January 08, 2015 at 20:06

Yes, but there are just two 32 bit timers and I need some more measuring a longer period between the input signals.

Posted on January 08, 2015 at 20:44

Yes, but there are just two 32 bit timers and I need some more measuring a longer period between the input signals.

Not much I can do about the silicon, for software solutions you'd just need one. Don't each have 4 channel latches?

For hardware they share a synchronous clock, so you can still capture with fine granularity with the 16-bit ones, and then figure the rollover.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 09, 2015 at 08:03

There are 4 captures per timer in the 32-bit timers.

16-bit timers can be chained and then captured simultaneously by connecting the same input signal to both timers' input, although there may be some work needed to figure out the exact behaviour if the capture occurs at around the master's rollover.

JW

oli
Associate II
Posted on January 09, 2015 at 11:34

I'm using six inputs for input capture (pwm) and six outputs for pwm. All independent at one time.

Posted on January 09, 2015 at 13:19

Yes PWM Input would need one timer per ''channel'' as it resets the timer and uses channels 1 and 2 of the timer for period and duty. 16-bit timers would be quite adequate for 50 Hz signals, absent a description of the nature of the signals you're using.

For straight Input Capture mode the timer does not reset, and you can time stamp the edges, two 32-bit timers with 4 channels would support 8 unique inputs. A 32-bit timer clocked a 1 MHz would rollover in ~4295 seconds, at 84 MHz ~51 seconds. You'd take delta measurements to compute frequency and duty.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
oli
Associate II
Posted on January 09, 2015 at 17:01

This could be a way to solve the requirement. Thanks. It may take some time for my next answer. Thanks.

oli
Associate II
Posted on June 18, 2015 at 12:54

The solution I've found to use microsecond resolution on 16 bit timers is to use the update event irq.

Each time when the CNT overflows an UEV is generated. This irq get caught and a separate 32bit variable gets incremented by 0x00010000.

Beware that the UEV can be caused by other conditions.