Got it and implemented such a technique.
... so I accidentally nuked my nano by shorting a couple pins and setting fire to the regulator. This accident was not in vane though because it forced me to use another nano, which I have verified exhibits the exact same behaviour (randomly fluctuating RPM readings). At this point I really think the interrupts are getting triggered by edges that it is "seeing", despite the source signal being pretty decent. I'm not sure what I can do about this. I take it there's no way to use hardware interrupts that will trigger off some custom voltage level so I'm stuck with whatever it thinks is "HIGH" and "LOW". I could put a capacitor on the interrupt pin to ground but I'm not sure that will reliably fix the problem either. Any recommendations at this point?
Code:
void sensorTest() {
unsigned int avgrpm[] = {0,0,0,0,0,0,0,0,0,0};
unsigned int finalrpm = 0;
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
currenttime = micros();
attachInterrupt(1, interruptRoutine, FALLING);
while(1){
RPM = (double)interval*0.000001;
RPM = 60/RPM;
avgrpm[a] = (unsigned int)RPM;
finalrpm = 0;
for(int b = 0; b<10; b++) {
finalrpm += avgrpm[b];
}
finalrpm *= 0.1;
if((micros() - delaycounter) > 100000) {
tft.fillRect(0, 0, 64, 80, ILI9341_BLACK);
tft.setCursor(0, 0);
tft.println((float)analogRead(A7)*5/1023);
tft.println((float)analogRead(A6)*5/1023);
tft.println((float)analogRead(A5)*5/1023);
tft.println((float)analogRead(A4)*5*2.375/1023+6.3625);
tft.println(finalrpm);
delaycounter = micros();
}
if(a>9)
a=0;
}
}
void interruptRoutine() {
interval = micros() - currenttime;
currenttime += interval;
a++;
}