|
|
发表于 2015-7-27 22:27:54
|
显示全部楼层
本帖最后由 Paderboy 于 2015-7-27 22:36 编辑
For Arduino Mega: (tested on Arduino Mega 2560)
timer 0 (controls pin 13, 4)
timer 1 (controls pin 12, 11)
timer 2 (controls pin 10, 9)
timer 3 (controls pin 5, 3, 2)
timer 4 (controls pin 8, 7, 6)
TCCRnB, where 'n' is the number for the timer.
TCCR2B for timer 2, TCCR3B for timer 3.
Eg:
TCCR2B = TCCR2B & 0b11111000 | 0x01;
//sets Arduino Mega's pin 10 and 9 to frequency 31250.
//code typically inserted in setup()
Setting Divisor Frequency
0x01 1 62500
0x02 8 7812.5
0x03 64 976.5625 <--DEFAULT
0x04 256 244.140625
0x05 1024 61.03515625
Setting Divisor Frequency
0x01 1 31372.55
0x02 8 3921.16
0x03 64 490.20 <--DEFAULT
0x04 256 122.55
0x05 1024 30.64
http://playground.arduino.cc/Main/TimerPWMCheatsheet |
|