0

help Using interrupts on feather m0's
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

help Using interrupts on feather m0's

by nitrousbob on Thu Jun 13, 2019 1:07 pm

I have a sketch i used with an UNO, I was able to easily read up to 32k rpms from a function generator

Code: Select all | TOGGLE FULL SIZE
float rev = 0;                                       // Inital Case for Motor (Stop)
int rpm;                                             // Revoluation per minute, unit of speed measuring as integer
int oldtime = 0;                                     // Starting
int timey;                                            // Save time as integer
                           

void isr () {                                        // Interrupt service routine
  rev ++;
}

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT);
    attachInterrupt(digitalPinToInterrupt(2), isr, RISING); // Attaching the interrupt (recommended)
}

void loop() {
  delay(500);
  detachInterrupt(digitalPinToInterrupt(2));          // Detaches the interrupt
  timey=millis()-oldtime;                             // Finds the time
  rpm=(rev/timey)*1000;                              // Calculates RPM used to be 60000
  oldtime=millis();                                  // Saves the current time
  rev=0;
     
  Serial.println("___TACHOMETER___");
  Serial.print(" RPM");
  Serial.println(rpm);
   
  attachInterrupt(digitalPinToInterrupt(2),isr,RISING);
}


I tried to change all the 2's to a 5 to use Digital Pin 5 on the M0 and I cannot get it to work. Is there something else to get the interrupts to work on a Feather?


I also realized later that the function generator was probably putting out 5v, possibly, so im going to get a level shifter put in for the input to pin 5

nitrousbob
 
Posts: 13
Joined: Sun Mar 11, 2018 1:43 pm

Please be positive and constructive with your questions and comments.