Hallo Arthur,
In der Lib scheint sich ein Fehler eingeschlichen zu haben. Möglicherweise kommt es aber auch zu einem Rechenfehler, weil im Compiler bezügl. Type-Cast etwas geändert wurde und es dadurch zu anderen Rundungen kommt.
Hier mal eine veränderte Version der Funktion "Sound"
Code:/*************************************************************************** * void sound(uint16_t freq, uint16_t duration_msec, uint8_t amplitude) * * use motors as loudspeaker and create a sound * * input * frequency: uint16_t freq * duration: uint16_t duration_msec * amplitude: uint8_t amplitude * * example: sound(1000, 100, 255); * 1Khz, 100ms, max. amplitude * * last modification: * Ver. Date Author Comments * ------- ---------- -------------- --------------------------------- * sto2 1.09.2006 stochri first version * sto3 17.6.2007 stochri type cast to remove time duration error * ------- ---------- -------------- --------------------------------- * ***************************************************************************/ void Sound(uint16_t freq, uint16_t duration_msec, uint8_t amplitude) { uint16_t wait_tics; uint32_t n,k,period_usec,dauer_usec; period_usec=1000000L/freq; dauer_usec=1000*(uint32_t)duration_msec; k=dauer_usec/period_usec; //IR Interuptfreq=36KHz //Wavefreq=18KHz wait_tics=18000/freq; MotorSpeed(amplitude,amplitude); for(n=0;n<k;n++) { MotorDir(FWD,FWD); Sleep(wait_tics); MotorDir(RWD,RWD); Sleep(wait_tics); } MotorSpeed(0,0); } #define BEEP Sound(1000, 100, 255) /*************************************************************************** * * (c) 2006 stochri * *************************************************************************** * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * any later version. * ***************************************************************************/Damit sollte es eigentlich gehen. Im Anhang noch ein Zip-File mit Hex-Datei und einem Beispiel. Gruss, stochri







Zitieren

Lesezeichen