aboutsummaryrefslogtreecommitdiff
path: root/cores
diff options
context:
space:
mode:
Diffstat (limited to 'cores')
-rw-r--r--cores/arduino/wiring.c4
-rw-r--r--cores/arduino/wiring_analog.c8
-rw-r--r--cores/arduino/wiring_digital.c24
3 files changed, 11 insertions, 25 deletions
diff --git a/cores/arduino/wiring.c b/cores/arduino/wiring.c
index 9c264d0..fb447eb 100644
--- a/cores/arduino/wiring.c
+++ b/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/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c
index db6cb7e..8a6fef3 100644
--- a/cores/arduino/wiring_analog.c
+++ b/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/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c
index 112defc..75f850e 100644
--- a/cores/arduino/wiring_digital.c
+++ b/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)