Arduino Mega: PWM Pin and Frequency Timer Control
Arduino Mega: PWM Pin and Frequency Timer Control
• Categories
◦ Arduino
◦ Componets
◦ LED
◦ News From the Web…
◦ Parts
◦ Photoshop Tutorials
◦ Scooter Mods
◦ Uncategorized
• Pages
◦ About
◦ Forum Signup
◦ forums
◦ Password Recovery
◦ Contact Us
• Forums
• Subscribe
Mar
8
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…..
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.
————————————————————————————–
TIMER 0 (Pin 4, 13)
Value Divisor Frequency
0x01 1 62.5035 KHz
0x02 8 7.8125 KHz
0x03 64 976.5 Hz // default
0x04 256 244.1 Hz
0x05 1024 61.0 Hz
Code: TCCR0B = (TCCR0B & 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
0x01 1 31.374 KHz
0x02 8 3.921 Khz
0x03 64 490.1 Hz // default
0x04 256 122.5 Hz
0x05 1024 30.63 Hz
Code: TCCR3B = (TCCR3B & 0xF8) | value ;
—————————————————————————————-
TIMER 4 (Pin 6, 7, 8)
Value Divisor Frequency
0x01 1 31.374 KHz
0x02 8 3.921 Khz
0x03 64 490.1 Hz // default
0x04 256 122.5 Hz
0x05 1024 30.63 Hz
Code: TCCR4B = (TCCR4B & 0xF8) | value ;
—————————————————————————————-
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.
1. horacio says:
December 30, 2016 at 4:48 pm
Reply
Reply
3. khaled says:
May 15, 2017 at 5:11 pm
Reply
4. cassio says:
June 8, 2017 at 9:09 am
Reply
5. david says:
October 2, 2017 at 2:44 am
hello , how to flashing led with frequency 40hz for exemple with arduino uno , and how to writing codes in
IDE , because i want to using arduino uno with led for brainwaves entrainment with different frequency like
2hz 7.5hz 5hz 25hz 40hz 1hz . thanks for help me .
Reply
thank you.
Reply
◦ fabrice says:
June 10, 2018 at 11:32 am
Fabrice
to France
Reply
Reply
Name (required)
Categories
• Arduino (7)
• Componets (3)
• LED (1)
• News From the Web… (2)
• Parts (4)
• Photoshop Tutorials (3)
• Scooter Mods (1)
• Uncategorized (2)
Recent Posts
Links
• Adafruit Forums
• Adafruit's Blog
• icstation.com
• Jeremy Saglimbeni: The Custom Geek.com
• YouTube Channel
Subscribe (RSS)