Repository navigation
Fix for issue #292 - #2961
Fix for issue #292#2961
Conversation
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.
There was a problem hiding this comment.
Did you test it with a Leonardo?
If so, it would be more coherent to use the notation bitWrite(TIMSK3, OCIE3A, 0); as in the previous case
There was a problem hiding this comment.
Actually the problem seems to be TIMSK5... Just tried to compile for the Leonardo:
Arduino: 1.6.1 (Linux), Platine: "Arduino Leonardo"
/home/jan/arduino-1.6.1/hardware/arduino/avr/cores/arduino/Tone.cpp: In function 'void disableTimer(uint8_t)':
/home/jan/arduino-1.6.1/hardware/arduino/avr/cores/arduino/Tone.cpp:472:24: error: 'OCIE5A' was not declared in this scope
TIMSK5 &= ~(1 << OCIE5A);
^
Fehler beim Kompilieren.
I'll try to find a fix for that.
There was a problem hiding this comment.
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:
...
#define TIMSK4 _SFR_MEM8(0x72)
#define TOIE4 2
#define OCIE4B 5
#define OCIE4A 6
#define OCIE4D 7
#define TIMSK5 _SFR_MEM8(0x73)
#ifndef __ASSEMBLER__
#define ADC _SFR_MEM16(0x78)
#endif
#define ADCW _SFR_MEM16(0x78)
...
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.
Replaced direct register manipulation with calls to bitWrite(). Fixed TIMSK5 usage on Leonardo (as well as some other preprocessor statements).
|
I've fixed this now by extending these preprocessor checks. The toneMelody example was tested with these changes on the following platforms: Compiles & runs on Leonardo |
|
Thank you @jan-r ! |
This bugfix makes the Tone library work with ATmega8-based boards. See #292.
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.