LOTS OF NEW UPDATES! These have all been personally Measured By Myself!!

 

Want to change the frequency on your your arduino mega?

I have painstakingly Spend many hours today going through every timer one by one and checking them on the Oscilloscope.

I can now accurately say these are all guaranteed within .05% precise… 

A lot of this info is out there on the web but not much of it is all in one place and as easy to find as right here VS. Arduino’s Forums.

Getting all this data together for my projects has taken me much effort since a lot of it was hard to completely understand when every place said refer to the datasheet.
That’s great! The french in the data sheet says yes there are timer’s and yes they can be changed, but there was no dumb dumb version in there to say , Do this, Type this here.

There is a lot of info on this for other boards like UNO etc…. but they don’t work the same on the mega’s.

Ok So…..

Arduino mega pins and hardware Timers

Pin       Timer
46        OC5B
45        OC5B
44        OC5B
13         OC0B  //Caution: this one  directly effects major timing { i.e delay and millis}
12         OC1B
11         OC1A
10         OC2A
9           OC2B
8           OC4C
7           OC4B
6           OC4A
5           OC3A
4           OC0B    //Caution: this one  directly effects major timing { i.e delay and millis}
3           OC3C
2           OC3B

All that is really important above is the numbers. They tell you what timers there on.
For example  pin 2 is OC3B which is timer 3.

another way to look at this is:
timer 0 —–  pin 4, 13                  *there’s alot of misinfo about Pin-13 but after checking 13
timer 1 —–  pin 11, 12, 13                            it is in fact on Timer 0   “Thx Max K.”
timer 2 —–  pin 9, 10
timer 3 —–  pin 2, 3, 5
timer 4 —–  pin 6, 7, 8
timer 5 —– pin 44, 45, 46

————————————————————————————–

TIMER 0    (Pin 4, 13)
Value                             Divisor                      Frequency
0×01                                  1                                62.5035 KHz
0×02                                  8                                7.8125 KHz
0×03                                  64                               976.5 Hz              // default
0×04                                  256                              244.1 Hz
0×05                                  1024                            61.0 Hz
Code:                 TCCR0B = (TCCR0B & 0xF8) | value ;
————————————————————————————-

TIMER 1      (Pin 11, 12)
Value                             Divisor                      Frequency
0×01                                  1                                31.374 KHz
0×02                                  8                                3.921 KHz
0×03                                  64                              490.1 Hz      // default
0×04                                  256                            122.5 Hz
0×05                                  1024                           30.63 Hz
Code:                 TCCR1B = (TCCR1B & 0xF8) | value ;
————————————————————————————–

TIMER 2       (Pin 9, 10)
Value                             Divisor                      Frequency
0×01                                  1                                31.374 KHz
0×02                                  8                                3.921 KHz
0×03                                 32                             980.3 Hz
0×04                                 64                             490.1 Hz               // default
0×05                                 128                           245 hz
0×06                                 256                           122.5 hz
0×07                                 1024                           30.63 hz
Code:                 TCCR2B = (TCCR2B & 0xF8) | value ;
—————————————————————————————-

Timers 3, 4, 5  Oddly do not use the divisors the data sheet says: Below are actual measured values!

TIMER 3     ( Pin 2, 3, 5)
Value                             Divisor                      Frequency
0×01                                  1                                31.374 KHz
0×02                                  8                                3.921 Khz
0×03                                 64                             490.1 Hz            // default
0×04                                 256                             122.5 Hz
0×05                                 1024                           30.63 Hz
Code:                 TCCR3B = (TCCR3B & 0xF8) | value ;
—————————————————————————————-

TIMER 4        (Pin 6, 7, 8)
Value                             Divisor                      Frequency
0×01                                  1                                31.374 KHz
0×02                                  8                                3.921 Khz
0×03                                 64                             490.1 Hz            // default
0×04                                 256                             122.5 Hz
0×05                                 1024                           30.63 Hz
Code:                 TCCR4B = (TCCR4B & 0xF8) | value ;
—————————————————————————————-

TIMER 5          (Pin 44, 45, 46)
Value                             Divisor                      Frequency
0×01                                  1                                31.374 KHz
0×02                                  8                                3.921 Khz
0×03                                 64                             490.1 Hz            // default
0×04                                 256                             122.5 Hz
0×05                                 1024                           30.63 Hz
Code:                 TCCR5B = (TCCR5B & 0xF8) | value ;
—————————————————————————————-

To set your timer just add it to your sketch:
Here’s and example for Pins 9 and 10 on Timer 2 @ 490.1Hz;

void setup () {
TCCR2B = (TCCR2B & 0xF8) | 0×04;
}

I know there is more that can be done with these And there are other ways as well but this is what i know works thus far.
Hope this is helpful to someone.