From 02aa13d0784a648f42d28f096000baf8dbdb0076 Mon Sep 17 00:00:00 2001 From: "Mr.Blinky" Date: Fri, 21 Sep 2018 00:23:05 +0200 Subject: [PATCH] Fixed interrupt glitch in ATMlib.play() Timer/counter 4 is enabled on Arduino init() and a Timer/counter 4 overflow may happen right after the timer/counter 4 interrupt is enabled. When this happens the channels have not been initialized yet causing random noise/sounds being played. This has been fixed by moving the interrupt enable after the channels have been initialized. --- board-package-source/libraries/ATMlib/src/ATMlib.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/board-package-source/libraries/ATMlib/src/ATMlib.cpp b/board-package-source/libraries/ATMlib/src/ATMlib.cpp index 6c5b77b..8b83c11 100644 --- a/board-package-source/libraries/ATMlib/src/ATMlib.cpp +++ b/board-package-source/libraries/ATMlib/src/ATMlib.cpp @@ -131,8 +131,6 @@ void ATMsynth::play(const byte *song) { TCCR4C = 0b01000101; OCR4D = 0x80; #endif - TIMSK4 = 0b00000100; - // Load a melody stream and start grinding samples // Read track count @@ -145,6 +143,7 @@ void ATMsynth::play(const byte *song) { for (unsigned n = 0; n < 4; n++) { channel[n].ptr = getTrackPointer(pgm_read_byte(song++)); } + TIMSK4 = 0b00000100;// enable interrupt as last } // Stop playing, unload melody