Skip to content

Commit 4fb17c4

Browse files
committed
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.
1 parent 9904a6f commit 4fb17c4

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

hardware/arduino/cores/arduino/wiring.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,6 @@ void init()
280280
#endif
281281

282282
#if defined(TCCR4A) && defined(TCCR4B) && defined(TCCR4D) /* beginning of timer4 block for 32U4 and similar */
283-
sbi(TCCR4A, COM4A1); // clear channel A on output compare match
284-
cbi(TCCR4A, COM4A0);
285-
sbi(TCCR4C, COM4D1); // clear channel D on output compare match
286-
cbi(TCCR4C, COM4D0);
287283
sbi(TCCR4B, CS42); // set timer4 prescale factor to 64
288284
sbi(TCCR4B, CS41);
289285
sbi(TCCR4B, CS40);

hardware/arduino/cores/arduino/wiring_analog.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ void analogWrite(uint8_t pin, int val)
210210
case TIMER4A:
211211
//connect pwm to pin on timer 4, channel A
212212
sbi(TCCR4A, COM4A1);
213+
#if defined(COM4A0) // only used on 32U4
214+
cbi(TCCR4A, COM4A0);
215+
#endif
213216
OCR4A = val; // set pwm duty
214217
break;
215218
#endif
@@ -234,6 +237,9 @@ void analogWrite(uint8_t pin, int val)
234237
case TIMER4D:
235238
// connect pwm to pin on timer 4, channel D
236239
sbi(TCCR4C, COM4D1);
240+
#if defined(COM4D0) // only used on 32U4
241+
cbi(TCCR4C, COM4D0);
242+
#endif
237243
OCR4D = val; // set pwm duty
238244
break;
239245
#endif

0 commit comments

Comments
 (0)