Want to change the frequency on your your arduino mega?
Alot 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 on 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.
Thats 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 to 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
Lastly to all the OG's here that know this stuff cause it was feed to em in a bottle. Please be gentle. If there are mistakes or things to add. let me know so i can fix em or add em.
Mostly I'm making this cause it felt there wasn't greatly one place to go for this info.
Ok so
Arduino mega pins and hardware Timers
PWM Hardware
46 OC5?
45 OC5?
44 OC5?
13 OC1C
12 OC1B
11 OC1A
10 OC2A
9 OC2B
8 OC4C
7 OC4B
6 OC4A
5 OC3A
4 OC0B //never mess with this one at it 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
timer 1 ----- pin 11, 12, 13
timer 2 ----- pin 9, 10
timer 3 ----- pin 2, 3, 5
timer 4 ----- pin 6, 7, 8
timer 5 ----- pin 44, 45, 46
Unfortunate I do not have a oscilloscope cause I'm poor. So the rest of these frequencies are taken from other ref's. I can not guarantee the exact freq's but they should be close.
If someone knows these more accurately than i have listed please feel free to let me know so i can change em.
TIMER 0
Value Divisor Frequency
0x01 1 62500 hz
0x02 8 7812.5 hz
0x03 64 976.5625 hz // default
0x04 256 244.140625 hz
0x05 1024 61.03515625 hz
Code: TCCR0B = (TCCR0B & 0xF8) | value ;
TIMER 1
Value Divisor Frequency
0x01 1 31250 hz
0x02 8 3906.25 hz
0x03 64 488.28125 hz // default
0x04 256 122.0703125 hz
0x05 1024 30.517578125 hz
Code: TCCR1B = (TCCR1B & 0xF8) | value ;
TIMER 2
Value Divisor Frequency
0x01 1 31250 hz
0x02 8 3926.25 hz
0x03 32 976.5625 hz
0x04 64 488.28125 hz // default
0x05 128 244.140625 hz
0x06 256 122.0703125 hz
0x07 1024 30.517578125 hz
Code: TCCR2B = (TCCR2B & 0xF8) | value ;
the rest i do not know the frequencies: but I can tell you tell you the values available.
TIMER 3
Value Divisor Frequency
0x01 1 ? hz
0x02 8 ? hz
0x03 64 ? hz // default
0x04 128 ? hz
0x05 1024 ? hz
Code: TCCR3B = (TCCR3B & 0xF8) | value ;
TIMER 4
Value Divisor Frequency
0x01 1 ? hz
0x02 8 ? hz
0x03 64 ? hz // default
0x04 128 ? hz
0x05 1024 ? hz
Code: TCCR4B = (TCCR4B & 0xF8) | value ;
TIMER 5
Value Divisor Frequency
0x01 1 ? hz
0x02 8 ? hz
0x03 64 ? hz // default
0x04 128 ? hz
0x05 1024 ? hz
Code: TCCR5B = (TCCR5B & 0xF8) | value ;
To set your timer just add it to your sketch:
Here's and example;
void setup () {
TCCR2B = (TCCR2B & 0xF8) | 0x04;
}
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.
More Info at SobiSource.com