AirMar P66 speed calculation problems

For general Flowcode discussion that does not belong in the other sections.
viktor_aust
Posts: 19
http://meble-kuchenne.info.pl
Joined: Fri May 17, 2024 1:04 am
Has thanked: 8 times
Been thanked: 3 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: 19
Joined: Fri May 17, 2024 1:04 am
Has thanked: 8 times
Been thanked: 3 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: 1826
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 153 times
Been thanked: 865 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

viktor_aust
Posts: 19
Joined: Fri May 17, 2024 1:04 am
Has thanked: 8 times
Been thanked: 3 times

Re: Duration measurement between two pulses

Post by viktor_aust »

The timed interval component question.
If I set the interval = 4 secods.
The attached to component macro will be called exactly at 4 seconds. Is not it?
What can I do in this macro?
Can I insert the loop and run it for 5 seconds?
Say, I have 4 seconds to calculate the speed.
If (for some reasons) the speed sensor is not working, etc, should I stop the timed interval component work?

mnfisher
Valued Contributor
Posts: 1826
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 153 times
Been thanked: 865 times

Re: Duration measurement between two pulses

Post by mnfisher »

Possibly - but I couldn't get the timed interval component to compile.

I got:
from D:\Projects\Flowcode\t1.c:20:
D:\Projects\Flowcode\t1.c:2433:3: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'

Error returned from [avr-gcc.exe]
So in theory - you could run a 'check' every 4s (though not for 5s!) - however - looking at the doc for the sensor - it generates a square wave at ~5.6 or 7.25 Hz (depending on model) with ~26000 pulses per nautical mile.
I would have an interrupt on this and count the number of pulses and keep a record of elapsed time - then rate (speed) is pulses / time - so for example, check this every 10s (or minute?). Acceleration requires measuring the rate of change of pulse frequency so is a little more involved.

So, personally, I would continually count pulses (using an interrupt handler) - and check the frequency at regular intervals - using either a timed interval (if you can get it to work) or some other way of measuring timed intervals (note - using a delay (10s) might be accurate enough for your purpose?)

Code: Select all

   loop
       .freq = pulses / 10   //  Calculate rate in Hz (assuming 10s interval)
       display_rate(.freq) // Calculate speed and display/record etc
       .total_pulses = .total_pulses + pulses // Keep a record of total distance travelled (in pulses?)
       pulses = 0   // Clear 10s pulse count
       delay 10s  //  Count pulses for another 10s
   end loop
There are other ways - for example using a RTC chip - which would give more accurate times and allow a record if speed at a given (correct?) time - which might be required for a vessel's log?

Martin

viktor_aust
Posts: 19
Joined: Fri May 17, 2024 1:04 am
Has thanked: 8 times
Been thanked: 3 times

Re: Duration measurement between two pulses

Post by viktor_aust »

Thanks.
The timed interval component works with FC11 (Nano). On board LED (B5) blinks on/off.
----------------------------------------
On the flowcode help web site I found:
Unfortunately there is a small simulation only
bug that is preventing the global variable within callback macro from updating, it all works on your embedded hardware.
The workaround (included within the example) for your own project is as follows.
First set up your timed interval component within properties along with the callback macro
Within the timed interval example, select the TimedInterval callback macro ,
then select the Built-in Function::Debug.PrintLn(" ")

----------------------
I tried to find on the www some info about the marine paddle wheel sensor.
I found the next: sensor can generate at speed of 1 knot freq = 4.8Hz.
What I cannot find is: who manufacter those paddle wheel sensors.
Are they the same? Etc.
--------------------
You wrote: sensor generates a pulses 5.6 to 7.25 Hz
Can you send me a link to information?

mnfisher
Valued Contributor
Posts: 1826
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 153 times
Been thanked: 865 times

Re: Duration measurement between two pulses

Post by mnfisher »

Struggled to find them again......

This gives the 26000, 7.25Hz http://www.ohmex.com/p66.pdf

There seems to be a 'fuller' datasheet - but only on scribd (and I didn't want a trial subscription)

Martin

mnfisher
Valued Contributor
Posts: 1826
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 153 times
Been thanked: 865 times

Re: Duration measurement between two pulses

Post by mnfisher »

and https://www.furunousa.com/-/media/sites ... _st650.pdf - which shows the 4.8/5.6Hz values - though this might be a different part - it looks to be the same as the Airmar replacement?

And the rate is per knot so if your boat is going at 20kts then 20 x 5.6.

viktor_aust
Posts: 19
Joined: Fri May 17, 2024 1:04 am
Has thanked: 8 times
Been thanked: 3 times

Re: AirMar P66 speed calculation problems

Post by viktor_aust »

Hi Martin
Many thanks again.
I was moving in a wrong direction.
----------------------------------------
After you stressed that different transducer sensors generate different number of pulses, I checked the AirMar P66 and s650 datasheets.
---------------------------------------
S650, ST650:
Pulse rate (with fins) 17,000 pulses per nautical mile (4.8Hz per knot)
Pulse rate (no fins) 20,000 pulses per n/mile

P66: Airmar P66 paddle wheel speed sensor typically produces 26,000 pulses per nautical mile.
• Pulse Rate: 26,000 pulses per nautical mile (p/nm).
• Frequency: Approximately 7.25 Hz per knot.
-------------------------------------
Example 1 for P66- Calculating speed in knots for one mile
If we counted 100 pulses per one second
If sensor outputs 26000 pulses per mile
If one knot = 1 nautical mile per hour
------------------------------------
speed = 100/26000 * 3600 = 13.8 knots
Where 1 hour = 60 minutes or 3600 seconds
------------------------------------
Looks like I have to change the post title and close this post as the title is wrong. Should be: AirMar P66 speed calculation problems
PS
I have to stress again Martin, this discussion with you was very valuable. The problem is solved. Thanks.

mnfisher
Valued Contributor
Posts: 1826
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 153 times
Been thanked: 865 times

Re: AirMar P66 speed calculation problems

Post by mnfisher »

Glad you are making headway again.

Let us know how the project goes!

Martin

Post Reply