[Q] Tone plays the desired tone AND a ~1kz unstoppable tone

HI,
i've ported an sketch from an NANO to a MEGA 2560 with ethernet shield.
Everything but the tone works like charm.
When i use tone or (newtone), it plays the desired tone but also an ~1khz tone that can't be stopped anymore.
I've tried several PWM outputs to prevent timer issues without luck.

here's a bit of my code:

//#include <SD.h>
//#include <NewTone.h>
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <RCSwitch.h>
#include "pitches.h"

//-----------------------------------------------------------------------------------------------
// Ethernet configuration
//-----------------------------------------------------------------------------------------------
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC Address
byte ip[] = { 192,168,1, 200 };                        // IP Address
EthernetServer server(80);                           // Server Port 80
//-----------------------------------------------------------------------------------------------
// UDP/NTP configuration
//-----------------------------------------------------------------------------------------------
unsigned int localPort = 8888;      // local port to listen for UDP packets
IPAddress timeServer(192, 43, 244, 18); // time.nist.gov NTP server
const  byte timeZoneOffset = +1; // GMT zone;
//-----------------------------------------------------------------------------------------------
// EMAIL configuration
//-----------------------------------------------------------------------------------------------
char Mailserver[] = "mail.gmx.net";

//-----------------------------------------------------------------------------------------------
// RC configuration
//-----------------------------------------------------------------------------------------------
byte RCTransmissionPin = 7; // pin attached to RC transmitter
byte RCRXinterrupt = 0;  // Receiver on inerrupt 0 => that is pin #2
//-----------------------------------------------------------------------------------------------
// AUDIO configuration
//-----------------------------------------------------------------------------------------------
const byte BuzzerPin = 46; // pin for the piezzo buzzer
unsigned int pace = 1150; // music speed

//-----------------------------------------------------------------------------------------------
//---------------  NO MORE EDITING BELOW THIS LINE!!!! ------------------------------------------
//-----------------------------------------------------------------------------------------------

// --------------------------------------
// alarm state definitions
// --------------------------------------
const byte arm = 1;
const byte disarm = 2;
const byte alert = 3;
// --------------------------------------
// sensor definition
// --------------------------------------
typedef struct a_sensor{
  unsigned long id; // decimal RC code
  String name; // readable name
  byte level;  // 0=always on, 1=nightmode, 2=full armed
  unsigned long lasttime;
  boolean      hastriggered;
  byte action;
  unsigned int timedelay;
  a_sensor* nextsensor;
} a_sensor;

a_sensor *root;    // root of the sensorlist
a_sensor *lastknown; // last triggered sensor

// --------------------------------------
unsigned long lastreceived; // holds the last received decimal code from rc sensor
unsigned long lastreceivedlength;

byte armedlevel = 0; // holds the alarm level (0= only alway on/fire/smoke,...)
byte prealarmcounter = 0;
byte prealarmid;

const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets 
time_t prevDisplay = 0; // when the digital clock was displayed

EthernetUDP Udp; // A UDP instance to let us send and receive packets over UDP

EthernetClient client;

RCSwitch mySwitch = RCSwitch(); // RCSwitch configuration

// --------------------------------------
// Buzzer Melody definition 
// --------------------------------------
const int *currentMelody;
byte *currentMelodyDurations;
byte currentMelodyPosition = 0;
byte currentMelodyLength = 0;


const int melodyBeep[] = {NOTE_C5, NOTE_C6};
byte noteDurationsBeep[] = {8, 16};
byte melodyBeepLength = 2;

const int melodyUp[] = {NOTE_C4, NOTE_D4, NOTE_G4};
byte noteDurationsUp[] = {4, 8, 16};  
byte melodyUpLength = 3;

const int melodyDown[] = {NOTE_G4, NOTE_D4, NOTE_C4};
byte noteDurationsDown[] = {4, 8, 16};  
byte melodyDownLength = 3;

const int melodyAlarm[] = {NOTE_C6, NOTE_G6, NOTE_C6, NOTE_G5, NOTE_C7, NOTE_C6};
byte noteDurationsAlarm[] = {16, 16, 8, 8, 4, 8};  
byte melodyAlarmLength = 6;

boolean playsound = false;
boolean playloop = false;


//---------------------------------------------------------------------------------------------
// Setup
// ---------------------------------------------------------------------------------------------
void setup() {
    // initialise serial port for debugging
    Serial.begin(9600);
 
    while (!Serial) {
      ; // wait for serial port to connect. Needed for Leonardo only
    }
    
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH);

    // initialise alert system
    InitialiseSettings();  

  // Network initialisation
  // Initialise ethernet
  Ethernet.begin(mac, ip);

  // start http server
  server.begin();

  //initialise UDP
  Udp.begin(localPort);
  // set the NTP service host
  setSyncProvider(getNtpTime);
  //sync arduino time with NTP Time
  
  //while(timeStatus()== timeNotSet); // wait until the time is set by the sync provider

  //enable transmittion of rc-commands on RCTransmissionPin
  mySwitch.enableTransmit( RCTransmissionPin );
  //enable reception of rc-commands on RCRXPin
  mySwitch.enableReceive(RCRXinterrupt);  // Receiver on inerrupt 0 => that is pin #2

  tone(BuzzerPin,440,10); // HERE THE PROBLEM OCCURS

}

Thanks for any advice

There is a lot there that seems unrelated to tone output. Can you produce a minimal sketch that demonstrates the problem? It may improve your own understanding of the problem and expose any false assumptions you're making about what is causing it, but in any case it would reduce the amount of code we need to understand.

Thanks for reply,

so i reduced the code and found the following:
it does not matter of i use the standard tone or the newtone library
each tone plays well and clean, but after the tone ends, the 1khz tone apperars and stays.
this tone is about half as loud as the real tones.
i've even tried to set the output to low manualy, but it does not have any affect.
i've removed the ethernet shield as well, but its still the same.

hardware is: + from piezzo on pin 6, - from piezo on gnd.

the sketch works on my two nanos fine, and the MEGA is an original one, used for the first time.

#include <NewTone.h>
const byte BuzzerPin = 6; 

void setup() {
  NewTone(BuzzerPin,440,500);
  delay(500);
  NewTone(BuzzerPin,640,500);
  delay(500);
  NewTone(BuzzerPin,440,500);
  delay(500);
  NewTone(BuzzerPin,440,500);
  delay(500);
  NewTone(BuzzerPin,640,500);
  delay(500);
}

void loop() {
}

Try adding the following at the end, after you have played the tones:

pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, LOW);

Alternatively, calling noTone(buzzerPin) may have the same effect.

digitalwrite(pin,LOW) didi it! MANY THANKS!
But why have i to use this only on the MEGA and not the UNO and NANO??