Is 1/10000sec (100µS) so we get our result in just 100µS. We deduce the frequency by multiplying theĬounts between the leading edges by 62.5.Īn advantage of this method is the quick calculation. By using no prescaler the timer countsĮvery clock cycle (62.5nS at 16 MHz). Timer 3 is a high-precision 16-bit timer. * Frequency counter using Timer 3 to work out the interval (i.e wavelength)īy counting between two consecutive rising interrupts (leading edge) on pin D18 (int3).īased on Nick Gammon's similar program for Atmel 328P processor, here:Īdapted for MEGA2560 by Chris Jennings. If anyone is interested, here is the code: #define CJ_ID "Wavelength2560 version:C" So my listing of the numbering mismatch above seems to be correct. The Mega is 100 compatible with Arduino IDE and most of the shields are designed for the Arduino mega2560 R3RoHS Compliant The chip is Atmega2560-16au and Atmega16u2, the same as the official version. Since posting I adapted my code to use timer/counter 3, interrupt 3 and Attach/DetachInterrupt 5, and it works perfectly on my MEGA2560. I have yet to try using Attachinterrupt(5.) and timer/counter 3, but will do so if my understanding above proves correct 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. 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 !Ĭhecking the MEGA2560 pin mapping further suggests the true mapping is: 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") 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.Īccording to the Arduino reference the Mega2560 mapping is: I tested on my UNO first and it worked just fine. This is the example that works by counting the interval between rising edges. I am working with "Another Frequency Counter" program in Nick Gammon's excellent notes on Timers and Counters ( Gammon Forum : Electronics : Microprocessors : Timers and counters).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |