Duration measurement between two pulses

For general Flowcode discussion that does not belong in the other sections.
viktor_aust
Posts: 11
http://meble-kuchenne.info.pl
Joined: Fri May 17, 2024 1:04 am
Has thanked: 5 times
Been thanked: 2 times

Re: Duration measurement between two pulses

Post by viktor_aust »

Hi Martin.
I found on www a few weeks back
------------------------------------------
Two ways to measure the flow rate
• Count the number of pulses in a known time period.
• Time the period between two pulses.
The first is easy and accurate but the more accurate you make it, the fewer measurements you make.
The second is difficult and will usually require a hardware timer but returns results fast.
Don't try to mix them by doing the second and then averaging; that just gives you the worst of both approaches.
When you need a known time period, don't try to wait for exactly 1 second (or ten seconds, or whatever).
Wait for around the right time, but use the clock-time to get the actual time that you waited. Also only read the clock and the counter once, and clear the counter close to when you do the reading or you will miss pulses.

Time-of-day jumps by an hour twice a year.
That will really screw up your measurements.
It can also jump by a few seconds if it is being corrected by NTP.
A clock with insufficient resolution will create jitter in your measurements.
Integers sometimes overflow; if you are reading the number of milliseconds since boot in a 32 bit word it will overflow after 50 days.
That's a nasty bug to find; it took Microsoft five years to recognise it.
------------------------------
Depth measurements
I have a few choices to work with PGA460, PGA460-Q1.
To buy a development board or to make one.
After I finish with the speed project, I will move (have no idea when) to the PGA460, PGA460-Q1 project.

viktor_aust
Posts: 11
Joined: Fri May 17, 2024 1:04 am
Has thanked: 5 times
Been thanked: 2 times

Re: Duration measurement between two pulses

Post by viktor_aust »

Hi
Is it possible to use the timed interval component with start-stop timer?
If I start the timed interval component and run it for 4 seconds
If during that time the interrupt pin detect the raising edge of the pulse N1 and I start the counting timer
If during that counting time the interrupt pin detect the raising edge of the pulse N2 and I stop the counting, save milliseconds
Wait for the end of interval component (4 seconds).
Do the calculations.
Will it work?
Say, if the timed interval component uses Timer1 (Mega) and start-stop timer use the Timer1?

mnfisher
Valued Contributor
Posts: 1791
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 151 times
Been thanked: 847 times

Re: Duration measurement between two pulses

Post by mnfisher »

Possibly - but I;m not sure I see what extra information you'd get by doing so?

I would either modify the above code to record the time for every (say) 100 pulses OR record the number of pulses over a given interval?

Martin

Post Reply