Skip to content

Fix for issue #292 #2961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions hardware/arduino/avr/cores/arduino/Tone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Version Modified By Date Comments
0006 D Mellis 09/12/29 Replaced objects with functions
0007 M Sproul 10/08/29 Changed #ifdefs from cpu to register
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>
Expand Down Expand Up @@ -296,13 +297,13 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
#if defined(TCCR0B)
if (_timer == 0)
{
TCCR0B = prescalarbits;
TCCR0B = (TCCR0B & 0b11111000) | prescalarbits;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems ok to me, although I've only read the datasheets and did't test it live

}
else
#endif
#if defined(TCCR2B)
{
TCCR2B = prescalarbits;
TCCR2B = (TCCR2B & 0b11111000) | prescalarbits;
}
#else
{
Expand Down Expand Up @@ -389,15 +390,15 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
break;
#endif

#if defined(TIMSK3)
#if defined(OCR3A) && defined(TIMSK3) && defined(OCIE3A)
case 3:
OCR3A = ocr;
timer3_toggle_count = toggle_count;
bitWrite(TIMSK3, OCIE3A, 1);
break;
#endif

#if defined(TIMSK4)
#if defined(OCR4A) && defined(TIMSK4) && defined(OCIE4A)
case 4:
OCR4A = ocr;
timer4_toggle_count = toggle_count;
Expand Down Expand Up @@ -454,21 +455,21 @@ void disableTimer(uint8_t _timer)
#endif
break;

#if defined(TIMSK3)
#if defined(TIMSK3) && defined(OCIE3A)
case 3:
TIMSK3 = 0;
bitWrite(TIMSK3, OCIE3A, 0);
break;
#endif

#if defined(TIMSK4)
#if defined(TIMSK4) && defined(OCIE4A)
case 4:
TIMSK4 = 0;
bitWrite(TIMSK4, OCIE4A, 0);
break;
#endif

#if defined(TIMSK5)
#if defined(TIMSK5) && defined(OCIE5A)
case 5:
TIMSK5 = 0;
bitWrite(TIMSK5, OCIE5A, 0);
break;
#endif
}
Expand Down