From 638043e4e363057262a29cc6bcc10aec5b770f25 Mon Sep 17 00:00:00 2001 From: nick6x Date: Sat, 27 Aug 2016 12:50:51 -0700 Subject: [PATCH] Add simple example to library. --- examples/SimpleSin/SimpleSin.ino | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/SimpleSin/SimpleSin.ino diff --git a/examples/SimpleSin/SimpleSin.ino b/examples/SimpleSin/SimpleSin.ino new file mode 100644 index 0000000..ce7cc4d --- /dev/null +++ b/examples/SimpleSin/SimpleSin.ino @@ -0,0 +1,41 @@ +/* DDS + * Example: Simple Sin + * This is a simple example that outputs a sin + * wave on pin 3. +*/ + +#define DDS_REFCLK_DEFAULT 9600 +#include + +#define PWM_PIN 3 + +DDS dds; + +void setup() { + pinMode(PWM_PIN, OUTPUT); + digitalWrite(PWM_PIN, LOW); + + dds.start(); + dds.playWait(600, 3000); + dds.on(); + //dds.setAmplitude(31); +} + +void loop() { + dds.setFrequency(2200); +} + +#ifdef DDS_USE_ONLY_TIMER2 +ISR(TIMER2_OVF_vect) { + dds.clockTick(); +} +#else // Use the ADC timer instead +ISR(ADC_vect) { + static unsigned char tcnt = 0; + TIFR1 = _BV(ICF1); // Clear the timer flag + if(++tcnt == 4) { + tcnt = 0; + } + dds.clockTick(); +} +#endif \ No newline at end of file