#ifndef FreqMeasure2_capture2_h_ #define FreqMeasure2_capture2_h_ #include #include // Arduino Uno, Duemilanove, LilyPad, Mini, Fio, etc #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) #define CAPTURE_USE_TIMER1 // ICP1 is pin 8 // Teensy 1.0 #elif defined(__AVR_AT90USB162__) #define CAPTURE_USE_TIMER1 // ICP1 is pin 16 // Teensy 2.0 #elif defined(__AVR_ATmega32U4__) #define CAPTURE_USE_TIMER1 // ICP1 is pin 22 // #define CAPTURE_USE_TIMER3 // ICP3 is pin 10 // Teensy++ 1.0 & 2.0 #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) #define CAPTURE_USE_TIMER1 // ICP1 is pin 4 // #define CAPTURE_USE_TIMER3 // ICP3 is pin 17 // Sanguino #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) #define CAPTURE_USE_TIMER1 // ICP1 is pin 14 // Arduino Mega #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) // #define CAPTURE_USE_TIMER1 // ICP1 is not connected // #define CAPTURE_USE_TIMER3 // ICP3 is not connected // #define CAPTURE_USE_TIMER4 // ICP4 is pin 49 #define CAPTURE_USE_TIMER5 // ICP5 is pin 48 #else #error "Unknown chip, please edit me with timer+counter definitions" #endif #if defined(CAPTURE_USE_TIMER1) static uint8_t saveTCCR1A, saveTCCR1B; static inline void capture2_init(void) { saveTCCR1A = TCCR1A; saveTCCR1B = TCCR1B; TCCR1B = 0; TCCR1A = 0; TCNT1 = 0; TIFR1 = (1<