Measure Time

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
wayne millard
Posts: 234
Joined: Thu May 31, 2007 2:18 pm
Has thanked: 7 times
Been thanked: 12 times
Contact:

Measure Time

Post by wayne millard »

Hi team,

Is there any example of how to measure a time between two rising edges on RB0 interrupt.
From 0 - 20ms with a accuracy of 1us or better. i can us flowcode 5 or Arm 4.

Thanks,
Wayne :D

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Measure Time

Post by Benj »

Hi Wayne,

What I would do is on the first INT interrupt I would reset my count variable and set a timer interrupt going. On the second INT interrupt I would disable the timer interrupt.

With a normal PIC running at 19.6608MHz you can get a timer interrupt rate of 19200Hz which equates to 52us.

With a USB enabled PIC running at 48MHz you can get a timer interrupt rate of 16875Hz which equates to 21us.

With every timer interrupt you simply add 1 to your counter and then this is a multiplier for the delay shown above.

You could then use a C icon read the contents of the actual timer register and this would give you a result in 1/256th of the time resolution shown above. Add the two values together and you should have an accurate time reading.

Mikat
Posts: 258
Joined: Wed Nov 29, 2006 6:32 pm
Location: Finland
Has thanked: 7 times
Been thanked: 36 times
Contact:

Re: Measure Time

Post by Mikat »

Benj wrote:Hi Wayne,

What I would do is on the first INT interrupt I would reset my count variable and set a timer interrupt going. On the second INT interrupt I would disable the timer interrupt.

With a normal PIC running at 19.6608MHz you can get a timer interrupt rate of 19200Hz which equates to 52us.
Ben why you don't use timer1 or timer3 as a counter? That what I would do. I the rising edge int, first read the timer, and then reset it, that way I don't need to have very high frequency timer in macro running...
Like I use in my boat CAN bus rpm measuring:
First set the timer 1 at right count speed.
Then at the rb0 int read the tmr1hi and tmr1lo at the array
Write the tmr1hi and tmr1lo at 0
Then calc the moving average at the array values
Convert those values at 16bit
Divide proper value at the calculated 16bit timer value
And VOILA I have the exact rpm value..
And the timer1 rollover int can be used at discard too long pulses..
The benefit at that type counter is that it is quite lot "lighter" to MCU to run, the interrupt frequecy is only the frequency at measured pulses, and then all I need to do is the read and reset the timer values, all other calculations can be done just when needed at main loop...

Mika

Gary Freegard
Posts: 45
Joined: Mon Nov 07, 2011 6:36 pm
Has thanked: 1 time
Been thanked: 30 times
Contact:

Re: Measure Time

Post by Gary Freegard »

Hi Mika

You may find this link useful, hopefully
http://www.matrixmultimedia.com/mmforum ... =29&t=9088

Jan was having an issue with his code, I came up with two alternative methods for him and then eventually decided to solve the problem :D

Good luck

Gary

Post Reply