Corrected the duration calculation on fixed DDS length.

This commit is contained in:
Stephen Olesen 2015-07-01 18:05:17 -06:00
parent 120442533d
commit 660fe0c602
2 changed files with 3 additions and 4 deletions

4
DDS.h
View File

@ -170,7 +170,7 @@ public:
void on(unsigned short duration) { void on(unsigned short duration) {
// Duration in ticks from milliseconds is: // Duration in ticks from milliseconds is:
// t = (1/refclk) // t = (1/refclk)
tickDuration = (duration * refclk) / 1000; tickDuration = (unsigned long)((unsigned long)duration * (unsigned long)refclk) / 1000;
timeLimited = true; timeLimited = true;
running = true; running = true;
} }
@ -186,7 +186,7 @@ public:
// Blocking version // Blocking version
void playWait(unsigned short freq, unsigned short duration) { void playWait(unsigned short freq, unsigned short duration) {
play(freq, duration); play(freq, duration);
delay(duration * 1000); delay(duration);
} }
// Our maximum clock isn't very high, so our highest // Our maximum clock isn't very high, so our highest

View File

@ -8,9 +8,8 @@ void setup() {
pinMode(3, OUTPUT); pinMode(3, OUTPUT);
pinMode(11, OUTPUT); pinMode(11, OUTPUT);
dds.start(); dds.start();
dds.setFrequency(440); dds.playWait(600, 3000);
dds.on(); dds.on();
delay(5000);
} }
void loop() { void loop() {