Duration measurement between two pulses

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

Duration measurement between two pulses

Post by viktor_aust »

Hi
The duration between two pulses calculation question.
------------------------------------------------------------------
I have an AirMar P66 transducer.
Not a smart one, but the analogue one.
Has anybody read the paddle wheel speed from this transducer?
And maybe the depth sensor as well?
Thanks.

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

Re: Duration measurement between two pulses

Post by mnfisher »

Depending on the length of pulse - you might might able to use the capture and compare module of the MCU.

See viewtopic.php?t=3111&hilit=Pulse+measurement - though I've also posted code for AVR...

Martin

viktor_aust
Posts: 9
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 »

Thanks mnfisher
I was thinking to stay away from c-code for a while.
I am not sure if I can.
---
Some suggest to set the Timer1 (Atmega328) to 1024 prescaler.
16 MHz / 1024 = 15625 Hz.
1/15625 = 0.000064 seconds
65536 * 0.000064 = 4.19 seconds.
Where 4.19 is the Timer1 overflow duration (is it?)
-----------

The boat speed = 1 / (4.19 * Period (in seconds)
If the found time (period) between two pulses = 4.7s
Speed = 1 / (4.19 * 4.7) = 0.05 knots.
------------

Look like the above method constantly compares the reference time (4.19s)
to the found duration between two pulses.

-------------
I am not sure what is better:
1- use the c-code for Timer1 (Atmega328). I think timer1 has outputs PB1 and PB2. When B1 or B2 changes the state, the interrupt macro saves the time
value between pulses. This value is used to calculate the boat speed.
2- Use the flowcode two timer components. Set the timer1 to count 4.19s. During that time the interrupt triggers the timer2 component to measure the
duration between two pulses.
After that I can use the formula: The boat speed = 1 / (4.19 * Period (in seconds)
Any suggestions?
Thanks.

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

Re: Duration measurement between two pulses

Post by mnfisher »

If the time interval is ~4s - then record the start time on one interrupt, the end on the next (using a timer component to get the time on ms (or us)) and calculate the difference.
Should be able to avoid C.
I can do a small example if needed?

Martin

viktor_aust
Posts: 9
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 »

Would be good. Thanks.

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

Re: Duration measurement between two pulses

Post by mnfisher »

Hi Viktor,

A simple example - I've assumed that you want to measure the time the pulse is HIGH - but the same can be applied to a LOW signal. The very simple test signal generator - gives equal time HIGH and LOW (here 2s) - though this isn't necessarily the case (and the measurement 'ignores' the time LOW).

I had a bit of an issue with the timer component - see bugs :-( but using TMR0 seems to give reliable results (using TMR2 - 16016ms!). The 2s 'pulse' shows as 2016ms - there is some loop overhead for the pulse generator (for the loop and pin toggle)

Martin
Attachments
pulse_328p.fcfx
(14.83 KiB) Downloaded 10 times
pulse_gen.fcfx
(7.65 KiB) Downloaded 10 times

viktor_aust
Posts: 9
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 »

Many thanks mnfisher.
Will post results shortly.

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

Re: Duration measurement between two pulses

Post by mnfisher »

Will be interesting to hear how it goes!

viktor_aust
Posts: 9
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 »

What I have to do - I need to use the created by Timer1 time as the reference value and calculate the time duration between the two pulses from the paddle wheel from P-66. The more I think about it the clear I see the need to use c-code. I am busy right now with the different projects. Not sure when I will be able to finish this one. I hoped that someone did some work with the marine analogue transducer. All good. Thanks.

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

Re: Duration measurement between two pulses

Post by mnfisher »

Just looking at the AirMar P66 transducer data - and looks like the speed reading is given by pulse frequency (~5.6Hz at 1knot for example). So rather than measuring the pulse length - measuring the number of pulses over a given period might be an easier option? So count rising edges over 10s (or more - I've no idea how quickly you need to read this - but 56 pulses/10s is easily readable?). Alternatively you should be able to calculate an instantaneous frequency from a single pulse and a little maths?
None of this should need C code.
Depth measurements seem to be a different kettle of fish?

Let us know when you can work on it - I'm sure someone will help out.....

Martin

Post Reply