arduinotimestampembeddedinterruptinterruption

Arduino - Gyro sensor - ISR - TimeStamp


I currently working to recreate a quad-copter controller.

I am working on getting data from my gyro sensor, and to do that, I'm using an ISR with an interuption.

My problem is, when I call my function "gyro.getX" on the main program, it work. But, when I call this function from my ISR, it doesn't work. I think that I found the reson of the bug, the function I'm using is provided by the "Adafruit_LSM9DS0" library (from ST), and it used a "timestamp". I think that the current time from my ISR is different that the current time from my Main program, but i don't know how to fix it.

Here a shortcut of my program:

void loop(){
/*main prog*/
}

/*
*Reserve interrupt routine service (ISR) by Arduino
*/
ISR(TIMER2_OVF_vect)
{
    TCNT2 = 256 - 250; // 250 x 16 µS = 4 ms
    if (varCompteur++ > 25)// 25 * 4 ms = 100 ms (half-period)
    {
        varCompteur = 0;
        
        SensorGet(pX, pY);//Feed gyro circular buffers
    }
}

void SensorGet(float * pRollX, float * pPitchY)
{   
    lsm.getEvent(&accel, &mag, &gyro, &temp);
    
    GiroX_Feed(pX, gyro.gyro.x);
    GiroY_Feed(pPitchY, gyro.gyro.y);
}
    


bool Adafruit_LSM9DS0::getEvent(sensors_event_t *accelEvent,
                                sensors_event_t *magEvent,
                                sensors_event_t *gyroEvent,
                                sensors_event_t *tempEvent)
{
  /* Grab new sensor reading and timestamp. */
  read();
  uint32_t timestamp = millis();

  /* Update appropriate sensor events. */
  if (accelEvent) getAccelEvent(accelEvent, timestamp);
  if (magEvent)   getMagEvent(magEvent, timestamp);
  if (gyroEvent)  getGyroEvent(gyroEvent, timestamp);
  if (tempEvent)  getTempEvent(tempEvent, timestamp);

  return true;
}

Solution

  • The problem isn't the time. The problem is likely that your sensor uses the I2C and it is disabled during an interrupt routine, or it's some other communication protocol that relies on interrupts to function and is therefore disabled during your ISR.

    You are really abusing the interrupt. This is not the kind of thing interrupts are for. Interrupt should be super fast, no time for communications there. So the real question is why do you think you need an interrupt for this?