Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Hardware Interrupt M4 SAMD51 ItsyBitsy
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Hardware Interrupt M4 SAMD51 ItsyBitsy

by lavericklavericklaverick on Wed Jul 22, 2020 7:54 am

Hi,

Im trying to accurately measure time between on and off of a digital signal.

Ive made a little test setup... I have a feather M0 running the blink example, this is connected to the input of the board running the hardware interrupt code, which calculates the time between on and off.

Interrupt code:
Code: Select all | TOGGLE FULL SIZE
const byte LED = 13;
const byte BUTTON = 2;
int on;
int off;

// Interrupt Service Routine (ISR)
void switchPressed ()
{
  if (digitalRead (BUTTON) == HIGH) {
    on = micros();
    digitalWrite (LED, HIGH);
    //Serial.println(on);
  }
  else {
    off = micros();
    digitalWrite (LED, LOW);
    Serial.println(off - on);
  }  // end of switchPressed
}
void setup ()
{
  Serial.begin(9600);
  pinMode (LED, OUTPUT);  // so we can update the LED
  digitalWrite (BUTTON, HIGH);  // internal pull-up resistor
  attachInterrupt (digitalPinToInterrupt (BUTTON), switchPressed, CHANGE);  // attach interrupt handler
}  // end of setup

void loop ()
{
  // loop doing nothing
}


Using an oscilloscope i can see the input is around 99.965ms
osc.PNG
osc.PNG (19.72 KiB) Viewed 29 times


I have tested this with a Due and the M4 @ 120Mhz and 200MHz with the following results
graph.PNG
graph.PNG (26.12 KiB) Viewed 29 times


I would have expected the M4 to be the most accurate @200MHz, however the Due outperforms it running @84MHz.

Does anyone know why this might be? Or have a solution to make the M4 more accurate?

Many thanks,

Andrew

lavericklavericklaverick
 
Posts: 19
Joined: Mon May 06, 2019 6:58 pm

Please be positive and constructive with your questions and comments.