GreyGnome / EnableInterrupt

New Arduino interrupt library, designed for Arduino Uno/Mega 2560/Leonardo/Due
329 stars 73 forks source link

Odd behaviour on Nano pin 2.... #65

Open simm42 opened 3 years ago

simm42 commented 3 years ago

Hi,

I'm using EnableInterrupt for tracking the tacho pulse on several PWM controlled 4 pin PC fans - 13 fans in total split over three nanos.

Originally I was using pin 2 for one of the signals, however it was consistently reading in the region of 8 times higher than the actual fan speed. This happened on all three nanos and regardless of if I swapped the fans around.

Each of the fans were wired up the same and each used the same function provided to the enableInterrupt call (counting on falling edge):

void fanSpeedCount(){
    int fan = pin_to_fan[arduinoInterruptedPin];
    fan_times[fan][fan_next_data[fan]] = millis();
    fan_next_data[fan] = (fan_next_data[fan] + 1) % FAN_DATA_POINTS;
}

I've solved this for myself by rewiring and not using pin 2 - my suspicion is it is related to pin 2 being a hardware interrupt pin and I didn't really want to get into debugging it beyond that.