Go Down

Topic: Spurious interrupt response (Read 203 times) previous topic - next topic

Pallnor

I'm trying to simulate an X-Y display that is used to display ion images. The ions are rastered with an X raster time of about 90 microseconds and a Y time of about 12ms. A synchronising pulse is available at the start of each X and Y scan. Each ion produces a pulse of 300ns duration. The pulse rate can be up to 50k per second. I'm using a Due to determine the time from the start of each raster and the arrival of each ion. The data is transferred to a PC via UDP for real time display.

The system works well but there is a spurious signal about 7 microseconds in from the start of the X scan. This signal depends on the overall pulse rate and can be over 10% of the total signal at high rates. There is no sign of this signal on the data input line.

The following code is much simplified but exhibits the problem :

Code: [Select]
const int XInput = 33;
const int PulseInput = 25; 
 
  volatile boolean DataReady ;
  volatile unsigned long XTime;   
  volatile unsigned long PulseTime;
  volatile unsigned long XTimeDiff;
     
  int DataPoints = 6000;
  unsigned long Data[6000] ;   
  int i;
  int PulseCounter = 0;

void setup()
{
 Serial.begin(115200); 

 pinMode(PulseInput, INPUT);
 pinMode(XInput,INPUT_PULLUP);
 
 attachInterrupt(XInput, XLine, RISING); 
 attachInterrupt(PulseInput, PulseDetected, RISING); 
 }

void loop()

   if (DataReady == true)
   {   
      DataReady = false;       
      Data[PulseCounter] = XTimeDiff; 
      PulseCounter++;     
      if(PulseCounter > DataPoints)
      {   
        for (i=0;i<DataPoints;i++)
       {
         Serial.println(Data[i]);       
       }           
       PulseCounter = 0;     
     }       
   }   
}

void XLine()

  XTime =  micros(); 
}
void PulseDetected()
{   
  PulseTime =  micros();   
  XTimeDiff = PulseTime - XTime;
  DataReady =  true  ;   
}

 
   

I'm using version 1.6.7 of the IDE.
The problem manifests itself without the Ethernet card and also when I change input pins, detach interrupts during serial sending or limit data collection to one block of data.

I suspect the problem is associated with using micros() and interrupts together but I'm at a loss as to how to fix this.
 
       

Go Up