diff options
author | Zach Eveland <zeveland@blacklabel-development.com> | 2011-12-11 19:56:50 -0500 |
---|---|---|
committer | Zach Eveland <zeveland@blacklabel-development.com> | 2011-12-11 19:56:50 -0500 |
commit | c58fcf5554827113680ee16559c36ed21e0ec0e0 (patch) | |
tree | 642552d3055d47962092c6d2b7233f6c8f086ddd /cores/arduino/wiring_analog.c | |
parent | a9d1368e4c424f17d7d77efeb666f2f7734c7b93 (diff) |
fixed TIMER4 use on Leonardo
ATMEGA32U4 has major differences in TIMER4 registers compared to ATMEGA1280 and 2560. turnOffPWM, analogWrite, and initialize routines had wrong registers, bit names, etc.
Diffstat (limited to 'cores/arduino/wiring_analog.c')
-rw-r--r-- | cores/arduino/wiring_analog.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c index 902b153..db6cb7e 100644 --- a/cores/arduino/wiring_analog.c +++ b/cores/arduino/wiring_analog.c @@ -204,14 +204,18 @@ void analogWrite(uint8_t pin, int val) break; #endif - #if defined(TCCR4A) && defined(COM4A1) + #if defined(TCCR4A) case TIMER4A: - // connect pwm to pin on timer 4, channel A + //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); - OCR4A = val; // set pwm duty + #endif + OCR4A = val; // set pwm duty break; #endif - + #if defined(TCCR4A) && defined(COM4B1) case TIMER4B: // connect pwm to pin on timer 4, channel B @@ -228,14 +232,17 @@ void analogWrite(uint8_t pin, int val) break; #endif - #if defined(TCCR4A) && defined(COM4D1) - case TIMER4D: + #if defined(TCCR4C) + case TIMER4D: // connect pwm to pin on timer 4, channel D - sbi(TCCR4A, COM4D1); - OCR4D = val; // set pwm duty + #if defined(PWM4D) /* ATMEGA32U4 and related */ + sbi(TCCR4C, PWM4D); + #endif + OCR4D = val; // set pwm duty break; #endif + #if defined(TCCR5A) && defined(COM5A1) case TIMER5A: // connect pwm to pin on timer 5, channel A @@ -270,3 +277,4 @@ void analogWrite(uint8_t pin, int val) } } } + |