From 6a44faedbb0ae06229ccad0ee415bbbf3635e755 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Sun, 18 Dec 2011 14:18:38 -0500 Subject: [PATCH] fixed digitalWrite on timer 4 pins (D6 and D13) --- hardware/arduino/cores/arduino/wiring.c | 4 ++++ .../arduino/cores/arduino/wiring_analog.c | 8 +------ .../arduino/cores/arduino/wiring_digital.c | 24 +++++-------------- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/hardware/arduino/cores/arduino/wiring.c b/hardware/arduino/cores/arduino/wiring.c index 9c264d0fc..fb447eb53 100644 --- a/hardware/arduino/cores/arduino/wiring.c +++ b/hardware/arduino/cores/arduino/wiring.c @@ -281,11 +281,15 @@ void init() #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 + cbi(TCCR4A, COM4A0); sbi(TCCR4C, COM4D1); // clear channel D on output compare match + cbi(TCCR4C, COM4D0); 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 + sbi(TCCR4A, PWM4A); // enable PWM mode for comparator OCR4A + sbi(TCCR4C, PWM4D); // enable PWM mode for comparator OCR4D #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 diff --git a/hardware/arduino/cores/arduino/wiring_analog.c b/hardware/arduino/cores/arduino/wiring_analog.c index db6cb7ef0..8a6fef3c9 100644 --- a/hardware/arduino/cores/arduino/wiring_analog.c +++ b/hardware/arduino/cores/arduino/wiring_analog.c @@ -207,11 +207,7 @@ void analogWrite(uint8_t pin, int val) #if defined(TCCR4A) case TIMER4A: //connect pwm to pin on timer 4, channel A - #if defined(PWM4A) /* ATMEGA32U4 and related */ - sbi(TCCR4A, PWM4A); - #elif defined(COM4A1) /* ATMEGA1280/2560 and related */ sbi(TCCR4A, COM4A1); - #endif OCR4A = val; // set pwm duty break; #endif @@ -235,9 +231,7 @@ void analogWrite(uint8_t pin, int val) #if defined(TCCR4C) case TIMER4D: // connect pwm to pin on timer 4, channel D - #if defined(PWM4D) /* ATMEGA32U4 and related */ - sbi(TCCR4C, PWM4D); - #endif + sbi(TCCR4C, COM4D1); OCR4D = val; // set pwm duty break; #endif diff --git a/hardware/arduino/cores/arduino/wiring_digital.c b/hardware/arduino/cores/arduino/wiring_digital.c index 112defc9c..75f850e76 100644 --- a/hardware/arduino/cores/arduino/wiring_digital.c +++ b/hardware/arduino/cores/arduino/wiring_digital.c @@ -105,29 +105,17 @@ static void turnOffPWM(uint8_t timer) case TIMER3C: cbi(TCCR3A, COM3C1); break; #endif - #if defined(TCCR4A) - case TIMER4A: - #if defined(PWM4A) - cbi(TCCR4A, PWM4A); - #elif defined(COM4A1) - cbi(TCCR4A, COM4A1); - #endif - break; - #endif - + #if defined(TCCR4A) && defined(COM4A1) + case TIMER4A: cbi(TCCR4A, COM4A1); break; + #endif #if defined(TCCR4A) && defined(COM4B1) case TIMER4B: cbi(TCCR4A, COM4B1); break; #endif #if defined(TCCR4A) && defined(COM4C1) case TIMER4C: cbi(TCCR4A, COM4C1); break; - #endif - - #if defined(TCCR4C) - case TIMER4D: - #if defined(PWM4D) - cbi(TCCR4C, PWM4D); - #endif - break; + #endif + #if defined(TCCR4C) && defined(COM4D1) + case TIMER4D: cbi(TCCR4C, COM4D1); break; #endif #if defined(TCCR5A)