fixed digitalWrite on timer 4 pins (D6 and D13)

This commit is contained in:
Zach Eveland 2011-12-18 14:18:38 -05:00
parent 9bd7761e3a
commit 177641003c
3 changed files with 11 additions and 25 deletions

View File

@ -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

View File

@ -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

View File

@ -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)