Activity Forums Questions & Troubleshooting controllino mega attachinterrupt

  • controllino mega attachinterrupt

  • Agmar

    Member
    June 19, 2023 at 10:41 am

    I am currently trying to connect a flowmeter (GEMS212465) to a controllino maxi.

    I am connected to port 18 (IN0). I am not able to count pulses with controllino, and it works perfectly with arduino mega.

    I have tried on controllino maxi with 24V and on the upper side with 5v

    is there something special to set up?

    Thank you for your support

    //byte sensorInterrupt = 5; // 1 = digital pin 3 or 18 = digital pin 5
    byte sensorPin = 18;

    // le capteur Gems FT210 génère 22000 pulsation par litre (soit 22 pulsations par millilitre)
    float calibrationFactor = 22;

    volatile int pulseCount; //ATTENTION la declaration d’une variable insuffisamment longue par rapport à ce que l’on veut enregistrer peut donner un résultat faux : byte? int? ou long?

    float flowRate;
    float flowMilliLitres;
    float totalMilliLitres;

    unsigned long oldTime;
    float intervalMesure;

    void setup()
    {

    // Initialize a serial connection for reporting values to the host
    Serial.begin(9600);
    Serial.println(“capteur debit 20190611”);
    Serial.print(“sensorPin : “);
    Serial.println(sensorPin);
    Serial.print(“correspondance digitalpintointerrupt : “);
    Serial.println(digitalPinToInterrupt(sensorPin));

    pinMode(sensorPin, INPUT);
    digitalWrite(sensorPin, HIGH);

    pulseCount = 0;
    flowRate = 0.0;
    flowMilliLitres = 0;
    totalMilliLitres = 0;
    oldTime = 0;
    intervalMesure = 1000; //(en milliseconde)

    // The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
    // Configured to trigger on a FALLING state change (transition from HIGH
    // state to LOW state)
    //attachInterrupt(digitalPinToInterrupt(sensorPin), pulseCounter, FALLING);
    attachInterrupt(digitalPinToInterrupt(sensorPin), pulseCounter, FALLING);
    }

    /**
    * Main program loop
    */
    void loop()
    {

    if((millis() – oldTime) > intervalMesure) // ne mesurer qu’une fois par interval de mesure
    {
    // Disable the interrupt while calculating flow rate and sending the value to
    // the host
    detachInterrupt(digitalPinToInterrupt(sensorPin));
    Serial.print(“interval reel: “);
    Serial.println(millis() – oldTime);
    // Because this loop may not complete in exactly 1 second intervals we calculate
    // the number of milliseconds that have passed since the last execution and use
    // that to scale the output.

    flowRate = ((intervalMesure / (millis() – oldTime)) * pulseCount);

    // quantité eau en mL
    flowMilliLitres = flowRate/calibrationFactor;

    // on déduit le nombre de pulsation pour une seconde
    flowRate =flowRate/intervalMesure*1000;
    // on applique la calibration pour avoir le résultat en mL/s
    flowRate = flowRate/calibrationFactor;

    // Note the time this processing pass was executed. Note that because we’ve
    // disabled interrupts the millis() function won’t actually be incrementing right
    // at this point, but it will still return the value it was set to just before
    // interrupts went away.
    oldTime = millis();

    // Add the millilitres passed in this second to the cumulative total
    totalMilliLitres += flowMilliLitres;

    unsigned int frac;

    // Print the flow rate for this second in litres / minute

    Serial.print(“pulsation: “);
    Serial.println(pulseCount);
    Serial.print(“Flow rate: “);
    Serial.print(flowRate*3.6); // Print the integer part of the variable
    Serial.print(“L/h”);
    Serial.print(“\t”); // Print tab space

    // Print the cumulative total of litres flowed since starting
    Serial.print(“Output Liquid Quantity: “);
    Serial.print(totalMilliLitres);
    Serial.println(“mL”);

    // Reset the pulse counter so we can start incrementing again
    pulseCount = 0;

    // Enable the interrupt again now that we’ve finished sending output
    //attachInterrupt(digitalPinToInterrupt(sensorPin), pulseCounter, FALLING);
    attachInterrupt(digitalPinToInterrupt(sensorPin), pulseCounter, FALLING);
    }
    }

    /*
    Insterrupt Service Routine
    */
    void pulseCounter()
    {
    // Increment the pulse counter
    pulseCount++;
    }

  • Laydi1

    Member
    October 4, 2023 at 9:12 am

    Do you find your life to be tedious and boring? Do you wish to live a new life that is suited to your desires? The bitlife game will help you do that!

  • Agmar

    Member
    October 5, 2023 at 1:20 pm

    Hello everybody,

    Finally I fixed the issue, by connecting the flowmeter on the upper side (5V) and by installing the a pull up resistance.

Viewing 1 - 3 of 3 replies

Log in to reply.

Original Post
0 of 0 posts June 2018
Now