Reading 6 pulse sensors
Jonathan
Posts: 1,023
HI All,
I am working on a project that needs to read 6 water flow sensors that output one pulse for every .1/cubic foot of water. The maximum pulse rate would be about 13 pulses per minute. I don't need to know the length or frequency of the pulses, just count them. As the sensor revolves about 1/3 of the time the output is high, 2/3 it is low, so quite likely one or more sensors will be inactive and remain high at any given time.
I can think of a couple of ways to do this but my solutions are kludgy, I'm quite sure there is an elegant and simple solution that is beyond my abilities using the counters or some such. Any tips towards a simple scheme to read these sensors?
Thanks!
I am working on a project that needs to read 6 water flow sensors that output one pulse for every .1/cubic foot of water. The maximum pulse rate would be about 13 pulses per minute. I don't need to know the length or frequency of the pulses, just count them. As the sensor revolves about 1/3 of the time the output is high, 2/3 it is low, so quite likely one or more sensors will be inactive and remain high at any given time.
I can think of a couple of ways to do this but my solutions are kludgy, I'm quite sure there is an elegant and simple solution that is beyond my abilities using the counters or some such. Any tips towards a simple scheme to read these sensors?
Thanks!
Comments
What language are you using?
At this speed you can have a simple loop just XORing the previous and current sample, when it's non-zero you can find out which ones changed by shifting bit by bit and maybe ANDing with if you are only interested in low to high edges etc. BTW, the WAITPNE instruction could be used but it's just as easy to use a simple loop too.
011001 <- PREVIOUS SAMPLE
011001 <- CURRENT SAMPLE
000000 <- XOR
011001 <- PREVIOUS SAMPLE
001011 <- CURRENT SAMPLE
010010 <- XOR non-zero indicates change of state
000010 <- ANDing the XOR with the current sample can indicate low to high edges
In your case you could probably sample every second or so and record a change of state only when the desired state exists twice in a row.
can elect to ignore any change that happens within N milliseconds of the last change you registered.
It occured to me you can detect a positive edge just with: only if currentState is 1 and previousState is 0 the 'greater than' is true.
So here is a simple code that detects pos edges of 6 sensors:
Andy
There are obvious high and low levels, but at the ttl setting, the Saleae detects a huge number of transitions at the ostensibly low level. A conventional debouncer, one that looks for a long period of stability at one level, is likely to fail due to the frequent spikes. A closer view shows that the spikes consist of "bell claps" about 20µs long separated by quiet intervals of 20 to 100µs. The solution we came up with, a firmware patch, was a digital low-pass filter, basically looking for a preponderance of either high or low levels.
Don't ask... Of course the best thing would be to get to the root cause of the noise, but this system is located at a hard to access site and was wired up by someone unknown, and came as a given, wires emerging from a conduit. Sometimes you just have to deal with it.
These particular flow meters have an isolated output, an optoisolator with both the collector and emitter of the output NPN available. So it takes a pullup or pulldown resistor to complete the circuit. That presents a fairly high impedance to the line. I suspect that there was some other nasty signal running parallel in the same conduit, crosstalk ensuing.
would probably have worked well for that signal - the noise is all high frequency. Looks
like the wires run alongside wires from a motor controller or other high power PWM signal.