débitmetre et interruption pin

bonjour à tous,

j'ai un problème d'interruption dans un code pour lire 5 débitmètres à effet hall sur un arduino uno et un lcd key pad.

le problème c'est que je peux lire les voie 1 et 2 qui sont sur les pin 2 et 3

mais pas les voies 3 4 5 sur les pins 11 12 13

les autres pins sont pris par le lcd.

j'ai cru voir que les pins 2 et 3 sont interrupts et pas les autres

y a t il un moyen de faire fonctionner différemment ou dois-je acheter une mega 2560 ?

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

//pins
const int voie1Pin = 2;     //pin location of flow rate meter on voie1 line
const int voie2Pin = 3;     //pin location of flow rate meter on voie2 line
const int voie3Pin = 11;    //pin location of flow rate meter on voie3 line
const int voie4Pin = 12;    //pin location of flow rate meter on voie4 line
const int voie5Pin = 13;    //pin location of flow rate meter on voie5 line

// variables
volatile int voie1Pulsecount;  //measuring the rising edges of the signal for the voie1 line
volatile int voie2Pulsecount;  //measuring the rising edges of the signal for the voie2 line
volatile int voie3Pulsecount;  //measuring the rising edges of the signal for the voie3 line
volatile int voie4Pulsecount;  //measuring the rising edges of the signal for the voie4 line
volatile int voie5Pulsecount;  //measuring the rising edges of the signal for the voie5 line

unsigned int copyvoie1Pulsecount;
unsigned int copyvoie2Pulsecount;
unsigned int copyvoie3Pulsecount;
unsigned int copyvoie4Pulsecount;
unsigned int copyvoie5Pulsecount;

double voie1Read;
double voie2Read;
double voie3Read;
double voie4Read;
double voie5Read;

float TOTAL = 0;

                   /*************************************************************************/

void setup() {
  Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Water Flow Meter");
lcd.setCursor(0,1);
lcd.print("****************");
delay(2000);

 
  pinMode(voie1Pin, INPUT); //initializes digital pin 2 as an input
  pinMode(voie2Pin, INPUT); //initializes digital pin 3 as an input
  pinMode(voie3Pin, INPUT); //initializes digital pin 11 as an input
  pinMode(voie4Pin, INPUT); //initializes digital pin 12 as an input
  pinMode(voie5Pin, INPUT); //initializes digital pin 13 as an input

  
attachInterrupt(digitalPinToInterrupt(2),  voie1RPM, RISING);   //attaching voie1 pulse counter interrupt to pin 2
attachInterrupt(digitalPinToInterrupt(3),  voie2RPM, RISING);   //attaching voie2 pulse counter interrupt to pin 3
attachInterrupt(digitalPinToInterrupt(11), voie3RPM, RISING);   //attaching voie3 pulse counter interrupt to pin 11
attachInterrupt(digitalPinToInterrupt(12), voie4RPM, RISING);   //attaching voie4 pulse counter interrupt to pin 12
attachInterrupt(digitalPinToInterrupt(13), voie5RPM, RISING);   //attaching voie5 pulse counter interrupt to pin 13
}
                  /************************************************************************/
void loop()
{
  static unsigned long lastsecond;


  if (micros() - lastsecond >= 1000000)
  {
    lastsecond += 1000000;
    getCount();

                  voie1Read = (copyvoie1Pulsecount / 7.5); //(voie1 pulse frequency / 7.5Q), = flow rate in L/min
                  voie2Read = (copyvoie2Pulsecount / 7.5); //(voie2 pulse frequency / 7.5Q), = flow rate in L/min
                  voie3Read = (copyvoie3Pulsecount / 7.5); //(voie3 pulse frequency / 7.5Q), = flow rate in L/min
                  voie4Read = (copyvoie4Pulsecount / 7.5); //(voie4 pulse frequency / 7.5Q), = flow rate in L/min
                  voie5Read = (copyvoie5Pulsecount / 7.5); //(voie5 pulse frequency / 7.5Q), = flow rate in L/min


TOTAL = TOTAL + voie1Read + voie2Read + voie3Read + voie4Read + voie5Read;
Serial.print("TOTAL:");
Serial.println(TOTAL);

  
   
    Serial.print ("voie1 : ");
    Serial.print (voie1Read, 2); //Prints the number calculated above
    Serial.println (" L/min");
      Serial.print ("voie2 : ");
      Serial.print (voie2Read, 2); //Prints the number calculated above
      Serial.println (" L/min");
        Serial.print ("voie3 : ");
        Serial.print (voie3Read, 2); //Prints the number calculated above
        Serial.println (" L/min");




      

    
lcd.clear();
             lcd.setCursor(0,0);
             lcd.print(voie1Read, 1);
                                      lcd.setCursor(4,0);
                                      lcd.print(voie2Read, 1);
                                                               lcd.setCursor(8,0);
                                                               lcd.print(voie3Read, 1);
                                                                                        lcd.setCursor(12,0);
                                                                                        lcd.print(voie4Read, 1);
                                                                                                                 lcd.setCursor(0,1);
                                                                                                                 lcd.print(voie5Read, 1);

lcd.setCursor(6,1);
lcd.print("Total ");
lcd.print(TOTAL/60,0);
    
 }}



// functions -----------------------------------------------------

void voie1RPM (){      //This is the function that the interupt calls
  voie1Pulsecount++;}  //This function measures the rising and falling edge of the hall effect sensors signal

void voie2RPM (){      //This is the function that the interupt calls
  voie2Pulsecount++;}  //This function measures the rising and falling edge of the hall effect sensors signal

void voie3RPM (){      //This is the function that the interupt calls
  voie3Pulsecount++;}  //This function measures the rising and falling edge of the hall effect sensors signal

void voie4RPM (){      //This is the function that the interupt calls
  voie4Pulsecount++;}  //This function measures the rising and falling edge of the hall effect sensors signal

void voie5RPM (){      //This is the function that the interupt calls
  voie5Pulsecount++;}  //This function measures the rising and falling edge of the hall effect sensors signal


void getCount(){
  noInterrupts();
  copyvoie1Pulsecount = voie1Pulsecount;
           voie1Pulsecount = 0;
  copyvoie2Pulsecount = voie2Pulsecount;
           voie2Pulsecount = 0;
  copyvoie3Pulsecount = voie3Pulsecount;
           voie3Pulsecount = 0;
  copyvoie4Pulsecount = voie4Pulsecount;
           voie4Pulsecount = 0;
  copyvoie5Pulsecount = voie5Pulsecount;
           voie5Pulsecount = 0;
  
  interrupts();}

La UNO est équipée d'un ATMEGA328P, qui offre seulement deux entrées avec interruption : pin 2 et 3.

Il faudrait utiliser les PinChangeInterrupts.

oui je viens de voir qu'on peut le faire avec toutes les pins .

tu peux me donner un exemple avec "mon" code ?

L'exemple du lien précédent n'est pas suffisamment clair ?

non désolé c'est trop complexe pour le débutant que je suis, si tu pouvais me le modifier au moins pour la voie 3 après je peux faire les autres

Les pins D0 à D7 sont sur la routine :

ISR (PCINT2_vect) pin change interrupt for D0 to D7

ISR (PCINT2_vect) // handle pin change interrupt for D0 to D7 here
 {
     int d3 = digitalRead(3);
     int d4 = digitalRead(4);
     // etc.
 }

Tu devras lire l'état de chaque pin pour savoir dans quel état elle est.
Ce sera donc plus lent qu'avec les interruptions externes D2 et D3.
Cela sera acceptable ou pas selon la vitesse du PWM.

faut que je supprime ça du coup ?

 pinMode(voie1Pin, INPUT); //initializes digital pin 2 as an input
  pinMode(voie2Pin, INPUT); //initializes digital pin 3 as an input
  pinMode(voie3Pin, INPUT); //initializes digital pin 11 as an input
  pinMode(voie4Pin, INPUT); //initializes digital pin 12 as an input
  pinMode(voie5Pin, INPUT); //initializes digital pin 13 as an input



  
attachInterrupt(digitalPinToInterrupt(2),  voie1RPM, RISING);   //attaching voie1 pulse counter interrupt to pin 2
attachInterrupt(digitalPinToInterrupt(3),  voie2RPM, RISING);   //attaching voie2 pulse counter interrupt to pin 3
attachInterrupt(digitalPinToInterrupt(11), voie3RPM, RISING);   //attaching voie3 pulse counter interrupt to pin 11
attachInterrupt(digitalPinToInterrupt(12), voie4RPM, RISING);   //attaching voie4 pulse counter interrupt to pin 12
attachInterrupt(digitalPinToInterrupt(13), voie5RPM, RISING);   //attaching voie5 pulse counter interrupt to pin 13

pas les appels à pinMode. Les pins doivent rester en entrée.
attachInterrupt : oui, à supprimer

J'ai ajouté ça sans succès

void pciSetup(byte pin)
{
    *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));  // enable pin
    PCIFR  |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
    PCICR  |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
}



ISR (PCINT0_vect) // handle pin change interrupt for D8 to D13 here
 {    
      int voie3Pin = digitalRead(11);
 }
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

//pins
const int voie1Pin = 2;     //pin location of flow rate meter on voie1 line
const int voie2Pin = 3;     //pin location of flow rate meter on voie2 line
const int voie3Pin = 11;    //pin location of flow rate meter on voie3 line
const int voie4Pin = 12;    //pin location of flow rate meter on voie4 line
const int voie5Pin = 13;    //pin location of flow rate meter on voie5 line

// variables
volatile int voie1Pulsecount;  //measuring the rising edges of the signal for the voie1 line
volatile int voie2Pulsecount;  //measuring the rising edges of the signal for the voie2 line
volatile int voie3Pulsecount;  //measuring the rising edges of the signal for the voie3 line
volatile int voie4Pulsecount;  //measuring the rising edges of the signal for the voie4 line
volatile int voie5Pulsecount;  //measuring the rising edges of the signal for the voie5 line

unsigned int copyvoie1Pulsecount;
unsigned int copyvoie2Pulsecount;
unsigned int copyvoie3Pulsecount;
unsigned int copyvoie4Pulsecount;
unsigned int copyvoie5Pulsecount;

double voie1Read;
double voie2Read;
double voie3Read;
double voie4Read;
double voie5Read;

float TOTAL = 0;



void pciSetup(byte pin)
{
    *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));  // enable pin
    PCIFR  |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
    PCICR  |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
}



ISR (PCINT0_vect) // handle pin change interrupt for D8 to D13 here
 {    
      int voie3Pin = digitalRead(11);
 }











                   /*************************************************************************/

void setup() {
  Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Water Flow Meter");
lcd.setCursor(0,1);
lcd.print("****************");
delay(2000);






 
  pinMode(voie1Pin, INPUT); //initializes digital pin 2 as an input
  pinMode(voie2Pin, INPUT); //initializes digital pin 3 as an input
  pinMode(voie3Pin, INPUT); //initializes digital pin 11 as an input
  pinMode(voie4Pin, INPUT); //initializes digital pin 12 as an input
  pinMode(voie5Pin, INPUT); //initializes digital pin 13 as an input



  /*
attachInterrupt(digitalPinToInterrupt(2),  voie1RPM, RISING);   //attaching voie1 pulse counter interrupt to pin 2
attachInterrupt(digitalPinToInterrupt(3),  voie2RPM, RISING);   //attaching voie2 pulse counter interrupt to pin 3
attachInterrupt(digitalPinToInterrupt(11), voie3RPM, RISING);   //attaching voie3 pulse counter interrupt to pin 11
attachInterrupt(digitalPinToInterrupt(12), voie4RPM, RISING);   //attaching voie4 pulse counter interrupt to pin 12
attachInterrupt(digitalPinToInterrupt(13), voie5RPM, RISING);   //attaching voie5 pulse counter interrupt to pin 13
*/
}
                  /************************************************************************/
void loop()
{
  static unsigned long lastsecond;


  if (micros() - lastsecond >= 1000000)
  {
    lastsecond += 1000000;
    getCount();

                  voie1Read = (copyvoie1Pulsecount / 7.5); //(voie1 pulse frequency / 7.5Q), = flow rate in L/min
                  voie2Read = (copyvoie2Pulsecount / 7.5); //(voie2 pulse frequency / 7.5Q), = flow rate in L/min
                  voie3Read = (copyvoie3Pulsecount / 7.5); //(voie3 pulse frequency / 7.5Q), = flow rate in L/min
                  voie4Read = (copyvoie4Pulsecount / 7.5); //(voie4 pulse frequency / 7.5Q), = flow rate in L/min
                  voie5Read = (copyvoie5Pulsecount / 7.5); //(voie5 pulse frequency / 7.5Q), = flow rate in L/min


TOTAL = TOTAL + voie1Read + voie2Read + voie3Read + voie4Read + voie5Read;
Serial.print("TOTAL:");
Serial.println(TOTAL);

  
   
    Serial.print ("voie1 : ");
    Serial.print (voie1Read, 2); //Prints the number calculated above
    Serial.println (" L/min");
      Serial.print ("voie2 : ");
      Serial.print (voie2Read, 2); //Prints the number calculated above
      Serial.println (" L/min");
        Serial.print ("voie3 : ");
        Serial.print (voie3Read, 2); //Prints the number calculated above
        Serial.println (" L/min");


      

    
lcd.clear();
             lcd.setCursor(0,0);
             lcd.print(voie1Read, 1);
                                      lcd.setCursor(4,0);
                                      lcd.print(voie2Read, 1);
                                                               lcd.setCursor(8,0);
                                                               lcd.print(voie3Read, 1);
                                                                                        lcd.setCursor(12,0);
                                                                                        lcd.print(voie4Read, 1);
                                                                                                                 lcd.setCursor(0,1);
                                                                                                                 lcd.print(voie5Read, 1);

lcd.setCursor(6,1);
lcd.print("Total ");
lcd.print(TOTAL/60,0);
    
 }}



// functions -----------------------------------------------------

void voie1RPM (){      //This is the function that the interupt calls
  voie1Pulsecount++;}  //This function measures the rising and falling edge of the hall effect sensors signal

void voie2RPM (){      //This is the function that the interupt calls
  voie2Pulsecount++;}  //This function measures the rising and falling edge of the hall effect sensors signal

void voie3RPM (){      //This is the function that the interupt calls
  voie3Pulsecount++;}  //This function measures the rising and falling edge of the hall effect sensors signal

void voie4RPM (){      //This is the function that the interupt calls
  voie4Pulsecount++;}  //This function measures the rising and falling edge of the hall effect sensors signal

void voie5RPM (){      //This is the function that the interupt calls
  voie5Pulsecount++;}  //This function measures the rising and falling edge of the hall effect sensors signal


void getCount(){
  noInterrupts();
  copyvoie1Pulsecount = voie1Pulsecount;
           voie1Pulsecount = 0;
  copyvoie2Pulsecount = voie2Pulsecount;
           voie2Pulsecount = 0;
  copyvoie3Pulsecount = voie3Pulsecount;
           voie3Pulsecount = 0;
  copyvoie4Pulsecount = voie4Pulsecount;
           voie4Pulsecount = 0;
  copyvoie5Pulsecount = voie5Pulsecount;
           voie5Pulsecount = 0;
  
  interrupts();}

Sans succès : cela veut dire quoi ?

les valeurs restent à 0 sur le port serie

Je ne vois nulle part d'appel à la fonction pciSetup() dans ton code.
Relis l'exemple.

hello
je viens juste d'utiliser cette possibilité

je viens de l'adapter à ton code

j'ai limité à D11,D12,D13

cpt_eau_interruptions.zip (2.47 KB)

merci c'est super sympa d'avoir pris le temps de modifier le code.
toutes les voies restent à 0 sur le lcd et sur le port serie

sauf le total à 0.27 meme après reset

Je n'ai pas testé avec un lcd, mais sur le moniteur à 1000000bauds, les voies affichent bien
ce qu'elles voient passer à chaque seconde.
à la seconde suivante, si le flux est stoppé, elle t'annonceront 0
par contre le total n'est pas remis à zéro

j'ai testé avec un générateur de fréquences, sur chacune des voies c'est ok sur le moniteur

j'ai retenté c'est pareil

t'es sur les pins 2 3 11 12 13 ?

20:20:06.594 -> voie3 : 0.00 L/min
20:20:06.594 -> voie4 : 0.00 L/min
20:20:06.594 -> voie5 : 0.00 L/min
20:20:07.589 -> TOTAL:0.27
20:20:07.589 -> voie1 : 0.00 L/min
20:20:07.589 -> voie2 : 0.00 L/min
20:20:07.589 -> voie3 : 0.00 L/min
20:20:07.589 -> voie4 : 0.00 L/min
20:20:07.589 -> voie5 : 0.00 L/min
20:20:08.615 -> TOTAL:0.27
20:20:08.615 -> voie1 : 0.00 L/min
20:20:08.615 -> voie2 : 0.00 L/min
20:20:08.615 -> voie3 : 0.00 L/min
20:20:08.615 -> voie4 : 0.00 L/min
20:20:08.615 -> voie5 : 0.00 L/min
20:20:09.606 -> TOTAL:0.27

j'ai reussi avec un débitmètre à la fois , mais toutes les voies en meme tps je suppose qu'elles s’interrompent mutuellement.

sinon je pensais à un truc...
est ce qu'il est possible de lire chaque broche pendant 5s avant de passer à la suivante ?
ça me suffit comme résolution , le débit ne bouge pas tant que ça.

hello
j'ai revu un peu le prg
voir les essais en fichier joint
faits avec mon générateur de fréquences
signal carré, amplitude 5 volts et fréquence sur 27400Hertz
tu verras sur la copie d'écran que les 5 entrées ont comptées tous les crénaux
les 5 entrées reliées ensembles

cpt_eau_interruptions_v1.zip (2.6 KB)