From 4fb17c47cdccee963cf1a14127acfa005ef572d3 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Thu, 19 Apr 2012 15:52:16 -0400 Subject: [PATCH] bugfix for configuring PWM on D6 and D13 too early. (thanks to Limor Fried) was starting PWM on these pins too soon - in init() instead of when analogWrite() was called. as a result doing output on port registers directly failed. --- hardware/arduino/cores/arduino/wiring.c | 4 ---- hardware/arduino/cores/arduino/wiring_analog.c | 6 ++++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/hardware/arduino/cores/arduino/wiring.c b/hardware/arduino/cores/arduino/wiring.c index fb447eb53..ac8bb6f9b 100644 --- a/hardware/arduino/cores/arduino/wiring.c +++ b/hardware/arduino/cores/arduino/wiring.c @@ -280,10 +280,6 @@ void init() #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 - 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); diff --git a/hardware/arduino/cores/arduino/wiring_analog.c b/hardware/arduino/cores/arduino/wiring_analog.c index c06cad4a8..0e9881f6a 100644 --- a/hardware/arduino/cores/arduino/wiring_analog.c +++ b/hardware/arduino/cores/arduino/wiring_analog.c @@ -210,6 +210,9 @@ void analogWrite(uint8_t pin, int val) case TIMER4A: //connect pwm to pin on timer 4, channel A sbi(TCCR4A, COM4A1); + #if defined(COM4A0) // only used on 32U4 + cbi(TCCR4A, COM4A0); + #endif OCR4A = val; // set pwm duty break; #endif @@ -234,6 +237,9 @@ void analogWrite(uint8_t pin, int val) case TIMER4D: // connect pwm to pin on timer 4, channel D sbi(TCCR4C, COM4D1); + #if defined(COM4D0) // only used on 32U4 + cbi(TCCR4C, COM4D0); + #endif OCR4D = val; // set pwm duty break; #endif