5 Replies Latest reply on Oct 14, 2015 11:58 AM by MrPrezident

    Erratic behavior with hardware interrupts on Galileo Gen 2

    MrPrezident

      I've never been able to get hardware interrupts to work properly on Galileo.  My latest project I was trying to use the interrupts to find home position for my stepper motors using makeshift optical encoders.  It works fine on Arduino Uno, but on Galileo it seems like they are randomly triggering, or maybe it's that the interrupts are significantly delayed. I can't really tell what's going on. I eventually rewrote my code to poll the encoder instead, and that works great, but does anyone know how I can get it working with interrupts?  Here is my code:

       

      #define OPTICAL_SENSOR1_PIN 2
      #define OPTICAL_SENSOR2_PIN 3
      
      volatile int state1 = LOW;
      volatile int state2 = LOW;
      
      void setup() 
      {
        pinMode(OPTICAL_SENSOR1_PIN, INPUT_PULLUP);
        pinMode(OPTICAL_SENSOR2_PIN, INPUT_PULLUP);
      
      //  //Arduino UNO
      //  attachInterrupt(0, myinterrupt1, CHANGE);
      //  attachInterrupt(1, myinterrupt2, CHANGE);
        //Galileo
        attachInterrupt(2, myinterrupt1, CHANGE);
        attachInterrupt(3, myinterrupt2, CHANGE);
      
        goToStart1();
       goToStart2();
      
      //  //Arduino UNO  
      //  detachInterrupt(0);
      //  detachInterrupt(1);
        //Galileo
        detachInterrupt(2);
        detachInterrupt(3);
      
      }
      
      void loop() 
      {
      }
      
      void myinterrupt1() {
        state1 = digitalRead(OPTICAL_SENSOR1_PIN);
      }
      void myinterrupt2() {
        state2 = digitalRead(OPTICAL_SENSOR2_PIN);
      }
      
      void goToStart1() {
        if(state1==LOW){
          //If motor1 already detecting home, move away from home position first
         //so that we can accurately find the encoder edge transition
        }
        while(state1==HIGH){
          //Move stepper motor1 one step
        }
      }
      
      void goToStart2() {
        if(state2==LOW){
          //If motor2 already detecting home, move away from home position first
          //so that we can accurately find the encoder edge transition
        }
        while(state2==HIGH){
          //Move stepper motor2 one step
        }
      }