Library for multiple flow meters/ hall sensors?

I need to measure the frequency (flow) from several flow sensors and a hall effect sensor. The PRJC FreqMeasure library seems to be a good choice:
[FreqMeasure library](http://FreqMeasure library)
I am running it now with one flow meter. Is there a library designed to handle multiple sensors? If not, how would I modify the FreqMeasure library?

I'm using an arduino Mega 2560. Am I limited to six devices by the number of available interrupts?

======================
I solved this problem by writing a new library to support multiple flow meters. It is here:
http://forum.arduino.cc/index.php?topic=236326.0

I do not plan to substantially work on FreqMeasure within the next 2 years (and perhaps not ever again), other than minor tweaks to port it to other boards. If you want the code to work differently, you're going to have to roll up your sleeves and do the work yourself. Or maybe hire someone to do it? The code is open source, afterall.

If you look at util/capture.h, you'll see the options for hardware. Arduino Mega has 4 timers compatible with FreqMeasure. However, two of them do not have their ICP pins routed to any of Mega's accessible pins. You could in theory use those other timers if you modify your board to gain access to those extra pins. You'll need to refer to Atmel's datasheet for the chip and Arduino's schematic and PCB layout documentation to discover where those pins are located.

In theory, 4 copies of FreqMeasure could run simultaneously. I wrote the code to use only 1 timer, which you can change by editing util/capture.h. Read the comments in that file for details. To run more than one copy, you'll have to edit the name of the library class and the default instance, so the other copies won't conflict. You might have to edit more stuff too. The errors from the compiler will give you an indication if stuff is conflicting between the multiple copies of the library. You'll need to resolve those problems, but if you post here with the specific code and error messages, perhaps you'll get some help? I personally can not get very involved.

I know you said you wanted 6 sensors. There are only 4 timers inside Arduino Mega that can work with FreqMeasure. Nothing you do can change that reality of the hardware. If you do put this work into modified copies of the FreqMeasure, do so with an awareness of this hardware limit.

Good luck. If you do get it working, I hope you'll participate in the spirit of open source by publishing your code, even though that's not required by the very permissive MIT license FreqMeasure uses.

Thanks, Paul, for your detailed reply. I did read the capture utility file, and saw that it would work with both pins 48 and 49 on the Mega- so I see how I could copy the library and run two instances of it.. It lead me to ask: What is the purpose of the capture.lib, and why does FreqMeasure use ICP pins/timers instead of interrupts?

I hacked together a second instance of Paul’s library to support a second sensor. It works with my Mega 2560. It’s attached below. They all go in a folder called FreqMeasure2. Put the capture2.h file in a subfolder called util.

Perhaps a more skilled programmer could make single library that would support more sensors!

FreqMeasure2.cpp (3.53 KB)

FreqMeasure2.h (268 Bytes)

keywords.txt (83 Bytes)

capture2.h (4.39 KB)

No library for counters but a general purpose library that makes life easier and puts a smile on my face every day:
http://playground.arduino.cc/Code/SMlib

I have used it for an 8 channel counter:

#include <SM.h>

SM Counter8(Reset, Count);

int OngoingCount[8];
int SignalState[8];
int FinishedCount[8];
const int FirstChannel = 2;
const int Period = 1000;

void setup(){}//setup()

void loop(){
  EXEC(Counter8);
}//loop()

State Reset(){
  for(int i = 0; i<8; i++){//all channels
    FinishedCount[i] = OngoingCount[i];//save all channels
    OngoingCount[i] = 0;//reset all channels
  }//for(i)
}//Reset()

State Count(){
  for(int i = 0; i<8; i++){//all channels
    if(RE(digitalRead(FirstChannel + i), SignalState[i])) OngoingCount[i]++;//edge detected, increase channel counter
  }//for(i)
  if(Counter8.Timeout(Period)) Counter8.Set(Reset, Count);
}//Count()

Thanks nilton, the SM library has opened a whole new world for me. What do you think of the QM visual events tool?

Actually, I still need some help on the FreqMeasure2 library. My hall sensor measures 1.6 hz on the arduino, but 16 hz on my volt meter, so something is wrong. The voltage from the hall sensor is 2.0 v high, and 0.0 v low. Could the high voltage be too low? Or more likely, there is interaction between some uncorrected part of FreqMeasure and FreqMeasure2 libraries. Help!

i had a check on the data sheet.
Vil is -0.5 up to 0.3Vcc (for Vcc >2,4V which is the case for a 5V arduino) no problems here.
Vih is 0.6
Vcc up to Vcc+0.5 meaning that a 5V arduino will need at least 3V(=06*5V) for a high signal. So this could be the problem. Also, please check the sensor output when connected, it might give a different reading.

I had a look at the QM but i have not tried it. The idea is nice as long as it doesn't restrict too much. The only restriction with my library is that you have write non-blocking code, and that should not be a big one anyway.

turgo:
I need to measure the frequency (flow) from several flow sensors and a hall effect sensor. The PRJC FreqMeasure library seems to be a good choice:
[FreqMeasure library](http://FreqMeasure library)
I am running it now with one flow meter. Is there a library designed to handle multiple sensors? If not, how would I modify the FreqMeasure library?

I'm using an arduino Mega 2560. Am I limited to six devices by the number of available interrupts?

You can use pin-change interrupts to deal with a lot more pins, but you are bandwidth
limited since an interrupt handler takes a certain amount of time to run.

What frequencies are involved?

Hi Mark,
The frequencies are low, 5-100 hz. Do you have an example program to handle several pin change interrupts?

Nilton:

I discovered that the hall sensor output needed to be pulled high with a 10k resistor. However, it did not change the measurement by the Arduino.

I posted code for a frequency counter that does not take over any of the timers at Frequency Counter Library - #36 by dc42 - Science and Measurement - Arduino Forum. It isn't suitable for high frequencies, but the ones you want to measure are very low. It uses an interrupt for the input being counted. If you don't have enough interrupt pins for all your channels, you could adapt it to use pin change interrupts.

Hi Turgo. I am looking to carry out a project involving the connection of more than one flow sensor to the Arduino Mega 2560. Do you have example code for how you solved the issue you were facing with respect to the same? If so, do you mind posting it to this forum? Thanks.

I solved this problem by writing a new FlowCounters library to support multiple flow meters. It is here:
http://forum.arduino.cc/index.php?topic=236326.0

Hello all,

I have tried the second instance of the freqMeasure library, made by Turgo in post#3.

I did not get it working properly.
Has anyone get this working or is there another option to measure dual RPM's ?

Thanks in advance.