From 660fe0c602a29f19a8bdee1b187e48de9faf9b52 Mon Sep 17 00:00:00 2001 From: Stephen Olesen Date: Wed, 1 Jul 2015 18:05:17 -0600 Subject: [PATCH] Corrected the duration calculation on fixed DDS length. --- DDS.h | 4 ++-- examples/DDS/DDS.ino | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/DDS.h b/DDS.h index 8115dcc..be30411 100644 --- a/DDS.h +++ b/DDS.h @@ -170,7 +170,7 @@ public: void on(unsigned short duration) { // Duration in ticks from milliseconds is: // t = (1/refclk) - tickDuration = (duration * refclk) / 1000; + tickDuration = (unsigned long)((unsigned long)duration * (unsigned long)refclk) / 1000; timeLimited = true; running = true; } @@ -186,7 +186,7 @@ public: // Blocking version void playWait(unsigned short freq, unsigned short duration) { play(freq, duration); - delay(duration * 1000); + delay(duration); } // Our maximum clock isn't very high, so our highest diff --git a/examples/DDS/DDS.ino b/examples/DDS/DDS.ino index 245bb79..394ad18 100644 --- a/examples/DDS/DDS.ino +++ b/examples/DDS/DDS.ino @@ -8,9 +8,8 @@ void setup() { pinMode(3, OUTPUT); pinMode(11, OUTPUT); dds.start(); - dds.setFrequency(440); + dds.playWait(600, 3000); dds.on(); - delay(5000); } void loop() {