Update Tone.cpp

Rebased the bugfix from the original Google Code issue #292 to work with Arduino 1.6.x

Description of original fix provided by Pete62:
The later 8 bit AVR's use two registers (TCCRxA, TCCRxB) whereas the ATmega8 only uses a single register (TCCR2) to house the control bits for Timer 2.  Bits were inadvertently being cleared.
This commit is contained in:
Jan 2015-04-11 00:15:58 +02:00
parent 4c9e5fc564
commit 3cde93501c
1 changed files with 6 additions and 5 deletions

View File

@ -30,6 +30,7 @@ Version Modified By Date Comments
0006 D Mellis 09/12/29 Replaced objects with functions 0006 D Mellis 09/12/29 Replaced objects with functions
0007 M Sproul 10/08/29 Changed #ifdefs from cpu to register 0007 M Sproul 10/08/29 Changed #ifdefs from cpu to register
0008 S Kanemoto 12/06/22 Fixed for Leonardo by @maris_HY 0008 S Kanemoto 12/06/22 Fixed for Leonardo by @maris_HY
0009 J Reucker 15/04/10 Issue #292 Fixed problems with ATmega8 (thanks to Pete62)
*************************************************/ *************************************************/
#include <avr/interrupt.h> #include <avr/interrupt.h>
@ -296,13 +297,13 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
#if defined(TCCR0B) #if defined(TCCR0B)
if (_timer == 0) if (_timer == 0)
{ {
TCCR0B = prescalarbits; TCCR0B = (TCCR0B & 0b11111000) | prescalarbits;
} }
else else
#endif #endif
#if defined(TCCR2B) #if defined(TCCR2B)
{ {
TCCR2B = prescalarbits; TCCR2B = (TCCR2B & 0b11111000) | prescalarbits;
} }
#else #else
{ {
@ -456,19 +457,19 @@ void disableTimer(uint8_t _timer)
#if defined(TIMSK3) #if defined(TIMSK3)
case 3: case 3:
TIMSK3 = 0; TIMSK3 &= ~(1 << OCIE3A);
break; break;
#endif #endif
#if defined(TIMSK4) #if defined(TIMSK4)
case 4: case 4:
TIMSK4 = 0; TIMSK4 &= ~(1 << OCIE4A);
break; break;
#endif #endif
#if defined(TIMSK5) #if defined(TIMSK5)
case 5: case 5:
TIMSK5 = 0; TIMSK5 &= ~(1 << OCIE5A);
break; break;
#endif #endif
} }