Skip to content

Commit 3cde935

Browse files
committed
Update Tone.cpp
Rebased the bugfix from the original Google Code issue arduino#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.
1 parent 4c9e5fc commit 3cde935

File tree

1 file changed

+6
-5
lines changed
  • hardware/arduino/avr/cores/arduino

1 file changed

+6
-5
lines changed

Diff for: hardware/arduino/avr/cores/arduino/Tone.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Version Modified By Date Comments
3030
0006 D Mellis 09/12/29 Replaced objects with functions
3131
0007 M Sproul 10/08/29 Changed #ifdefs from cpu to register
3232
0008 S Kanemoto 12/06/22 Fixed for Leonardo by @maris_HY
33+
0009 J Reucker 15/04/10 Issue #292 Fixed problems with ATmega8 (thanks to Pete62)
3334
*************************************************/
3435

3536
#include <avr/interrupt.h>
@@ -296,13 +297,13 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
296297
#if defined(TCCR0B)
297298
if (_timer == 0)
298299
{
299-
TCCR0B = prescalarbits;
300+
TCCR0B = (TCCR0B & 0b11111000) | prescalarbits;
300301
}
301302
else
302303
#endif
303304
#if defined(TCCR2B)
304305
{
305-
TCCR2B = prescalarbits;
306+
TCCR2B = (TCCR2B & 0b11111000) | prescalarbits;
306307
}
307308
#else
308309
{
@@ -456,19 +457,19 @@ void disableTimer(uint8_t _timer)
456457

457458
#if defined(TIMSK3)
458459
case 3:
459-
TIMSK3 = 0;
460+
TIMSK3 &= ~(1 << OCIE3A);
460461
break;
461462
#endif
462463

463464
#if defined(TIMSK4)
464465
case 4:
465-
TIMSK4 = 0;
466+
TIMSK4 &= ~(1 << OCIE4A);
466467
break;
467468
#endif
468469

469470
#if defined(TIMSK5)
470471
case 5:
471-
TIMSK5 = 0;
472+
TIMSK5 &= ~(1 << OCIE5A);
472473
break;
473474
#endif
474475
}

0 commit comments

Comments
 (0)