AT 1284p with tone() frequency wrong above ~25kHz - why?

Hi All,
I’m experimenting with an Atmel Mega 1284p. I found this simple “Frequency Generator”:

// Frequenz-/Rechteckgenerator

#define INLENGTH 5       //maximale Größe der Zahl
#define INTERMINATOR 'H' //'H' von 'Hz'

char inString[INLENGTH+2];
int inCount;

#define MinFreq 33
#define MaxFreq 65535
#define Ausgangspin 12   //muss kein PWM-Pin sein HR: 26

unsigned int Frequenz = 60000; //Hz (Maximum: 65535 Hz)

void setup(){
 OSCCAL = 138;
 Serial1.println("Bitte angeben wieviel Hz ausgegeben werden sollen (mit 'Hz')!");
 //Serial1.print("Oscal: ");
 //int temp = OSCCAL;
 tone(Ausgangspin, Frequenz);


void loop(){
 Eingabe();  //Eingabe-Funktion, die Eingabe-String entgegennimmt

 //Zeichenkette -> Zahl

 //Bereich prüfen
 Frequenz=constrain(Frequenz, MinFreq, MaxFreq);

 Serial1.print("Es wird gesetzt: ");
 tone(Ausgangspin, Frequenz);

void Eingabe(){
 inCount=0;          //Ziffern-Zähler rücksetzen
 while (Serial1.available()==0);
 inString[inCount] =;
 if(inString[inCount]==INTERMINATOR) break;
 //continue;     //geht nicht
 inCount--;      //-> Workaround
 while(++inCount < (INLENGTH+1));

The code runs on the 1284p @ 8MHz (Board Definition from: and Arduino IDE 1.6.12)

I checked the output with an oszi and at low frequencys like 5kHz or 10kHz and 20kHz, its except a few Hz up or down, correct. But at 30kHz up to 60kHz its about 10% less than expected (set to 60kHz gives me 54kHz). This is a very strange behaviour because I checked the setup with an Arduino Nano and it was all right (set to 60kHz gives me 60kHz).

I then tryed to go into the tone() function and it seems like it’s using different counters. Maybee there is something wrong with the Board definition?

Is there a way of getting this work on 1284p?

Thank you very much!