-
-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Fix for issue #292 #2961
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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; | ||
} | ||
else | ||
#endif | ||
#if defined(TCCR2B) | ||
{ | ||
TCCR2B = prescalarbits; | ||
TCCR2B = (TCCR2B & 0b11111000) | prescalarbits; | ||
} | ||
#else | ||
{ | ||
|
@@ -456,19 +457,19 @@ void disableTimer(uint8_t _timer) | |
|
||
#if defined(TIMSK3) | ||
case 3: | ||
TIMSK3 = 0; | ||
TIMSK3 &= ~(1 << OCIE3A); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you test it with a Leonardo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually the problem seems to be TIMSK5... Just tried to compile for the Leonardo:
I'll try to find a fix for that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the ATmega32u4 datasheet, the Leonardo doesn't have a timer 5 and therefore does not have TIMSK5. Nevertheless, iom32u4.h defines TIMSK5, but without defining individual bits in it:
So the main question is why the CPU header defines TIMSK5 at all. But at least it explains the partly complicated #if defined(...) sequences in Tone.cpp, where the presence of all macros is carefully checked before actually doing something. I'll push the new fix in a minute. |
||
break; | ||
#endif | ||
|
||
#if defined(TIMSK4) | ||
case 4: | ||
TIMSK4 = 0; | ||
TIMSK4 &= ~(1 << OCIE4A); | ||
break; | ||
#endif | ||
|
||
#if defined(TIMSK5) | ||
case 5: | ||
TIMSK5 = 0; | ||
TIMSK5 &= ~(1 << OCIE5A); | ||
break; | ||
#endif | ||
} | ||
|
There was a problem hiding this comment.
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