I am working with "Another Frequency Counter" program in Nick Gammon's excellent notes on Timers and Counters (http://www.gammon.com.au/forum/?id=11504
). This is the example that works by counting the interval between rising edges. I tested on my UNO first and it worked just fine. But in trying to convert it to run on a MEGA 2560 I came across what appears to me to be an Interrupt numbering mismatch between those used in the Arduino AttachInterrupt / DetachInterrupt commands and the ATMEL numbering for the MEGA 2560.
According to the Arduino reference the Mega2560 mapping is:
int.0 pin 2
int.1 pin 3
int.2 pin 21
int.3 pin 20
int.4 pin 19
int.5 pin 18
So I decided to use int.5 on pin D18 but then I noticed that maps to pin 46 on the MEGA2560 chip ("PD3/TXD1/INT3")
This suggests that if I use AttachInterrupt(5,isr,rising) with the signal coming into D18 I am actually using MEGA interrupt 3 and Timer/Counter 3 !
Checking the MEGA2560 pin mapping http://arduino.cc/en/Hacking/PinMapping2560
further suggests the true mapping is:Arduino MEGA2560
int.0 pin 2 interrupt/counter 4
int.1 pin 3 interrupt/counter 5
int.2 pin 21 interrupt/counter 0
int.3 pin 20 interrupt/counter 1
int.4 pin 19 interrupt/counter 2
int.5 pin 18 interrupt/counter 3
Am I interpreting this correctly?
Interestingly when I convert Nick Gammons example from interrupt 0 to interrupt 5 with the signal on D18 it does read the frequency correct, but only on the first reading. I have yet to try using Attachinterrupt(5...) and timer/counter 3, but will do so if my understanding above proves correct