From c58fcf5554827113680ee16559c36ed21e0ec0e0 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Sun, 11 Dec 2011 19:56:50 -0500 Subject: fixed TIMER4 use on Leonardo ATMEGA32U4 has major differences in TIMER4 registers compared to ATMEGA1280 and 2560. turnOffPWM, analogWrite, and initialize routines had wrong registers, bit names, etc. --- cores/arduino/wiring.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) mode change 100755 => 100644 cores/arduino/wiring.c (limited to 'cores/arduino/wiring.c') diff --git a/cores/arduino/wiring.c b/cores/arduino/wiring.c old mode 100755 new mode 100644 index e7f7cde..9c264d0 --- a/cores/arduino/wiring.c +++ b/cores/arduino/wiring.c @@ -278,12 +278,21 @@ void init() sbi(TCCR3B, CS30); sbi(TCCR3A, WGM30); // put timer 3 in 8-bit phase correct pwm mode #endif - + +#if defined(TCCR4A) && defined(TCCR4B) && defined(TCCR4D) /* beginning of timer4 block for 32U4 and similar */ + sbi(TCCR4A, COM4A1); // clear channel A on output compare match + sbi(TCCR4C, COM4D1); // clear channel D on output compare match + sbi(TCCR4B, CS42); // set timer4 prescale factor to 64 + sbi(TCCR4B, CS41); + sbi(TCCR4B, CS40); + sbi(TCCR4D, WGM40); // put timer 4 in phase- and frequency-correct PWM mode +#else /* beginning of timer4 block for ATMEGA1280 and ATMEGA2560 */ #if defined(TCCR4B) && defined(CS41) && defined(WGM40) sbi(TCCR4B, CS41); // set timer 4 prescale factor to 64 sbi(TCCR4B, CS40); sbi(TCCR4A, WGM40); // put timer 4 in 8-bit phase correct pwm mode #endif +#endif /* end timer4 block for ATMEGA1280/2560 and similar */ #if defined(TCCR5B) && defined(CS51) && defined(WGM50) sbi(TCCR5B, CS51); // set timer 5 prescale factor to 64 -- cgit v1.2.3-18-g5258