I'd like to play an asynch 'beep' sound (2.5kHz, pin 8) on an Arduino Mega with several other modules connected. I write them here, just for the record: SDCard reader and RFID reader through SPI bus, RTC through I2C, GSM module through hardware Serial 1. And I use PWM on two other pins (11,12) for controlling LEDs brightness.
It works well, however, sometimes (1 of 10) the beep frequency is about half-tone higher.
The code itself is good, because I use a constant in the tone() function call for specifying the frequency.
Does anybody have an idea what can influence the tone's PWM frequency such way, maybe on hardware level?