Duration measurement between two pulses

For general Flowcode discussion that does not belong in the other sections.
Post Reply
viktor_aust
Posts: 8
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: 1783
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 150 times
Been thanked: 843 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: 8
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: 1783
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 150 times
Been thanked: 843 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: 8
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: 1783
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 150 times
Been thanked: 843 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 5 times
pulse_gen.fcfx
(7.65 KiB) Downloaded 5 times

viktor_aust
Posts: 8
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.

Post Reply