Dual Interrupt pulse counter and direction calculation.

Hi Guys

So I have been playing with a flow sensor for the last two weeks just reading the pulses with a interrupt. I now found out that this device has two pulses on two different wires one pulse is offset 90 degree from the other one. which ever pulse comes first determines the direction of flow in the pipe.

Image attached.

Can anyone suggest how to determine the direction from these two inputs? I thought of doing a if statement but if I just catch the wrong pulse first then the calculation will be off for the rest of the time.

Why not just google.

Mark

People Please understand the question is how to determine direction of flow by counting two pulses not how to read pulses

Rustie0125: People Please understand the question is how to determine direction of flow by counting two pulses not how to read pulses

You determine the direction by which pulse comes first.

...R

Take a look at https://www.circuitsathome.com/mcu/reading-rotary-encoder-on-arduino/ .

This provides compact and very efficient code for dealing with Gray code type devices (which is what yours is) and should be very easy to adapt to your needs.

Determining direction but checking which pulse comes first is fine until the flow chances direction, how does the system not get confused what pulse was first mid way trough counting in one direction and then changes

Rustie0125: how does the system not get confused what pulse was first mid way trough counting in one direction and then changes

I don't know but I suspect it needs to take account of a sudden aberration in the time between pulses.

...R

Rustie0125: Determining direction but checking which pulse comes first is fine until the flow chances direction, how does the system not get confused what pulse was first mid way trough counting in one direction and then changes

Did you bother looking at the reference I provided ?