DDS/examples/SimpleSin/SimpleSin.ino

52 lines
880 B
Arduino
Raw Normal View History

2016-08-27 19:50:51 +00:00
/* DDS
* Example: Simple Sin
* This is a simple example that outputs a sin
* wave on pin 3.
*/
#define DDS_REFCLK_DEFAULT 9600
#include <DDS.h>
#define PWM_PIN 3
2017-07-28 23:16:10 +00:00
#define TIMER2_PHASE_ADVANCE 24
2016-08-27 19:50:51 +00:00
DDS dds;
void setup() {
pinMode(PWM_PIN, OUTPUT);
digitalWrite(PWM_PIN, LOW);
dds.start();
dds.startPhaseAccumulator(false);
2016-08-27 19:50:51 +00:00
dds.playWait(600, 3000);
dds.on();
//dds.setAmplitude(31);
}
void loop() {
dds.setFrequency(2200);
}
2017-07-28 23:16:10 +00:00
//Uncomment if using dds.startPhaseAccumulator(true);
/*ISR(TIMER2_OVF_vect) {
2016-08-27 19:50:51 +00:00
static unsigned char tcnt = 0;
2017-07-28 23:16:10 +00:00
if(++tcnt == TIMER2_PHASE_ADVANCE) {
2016-08-27 19:50:51 +00:00
tcnt = 0;
2017-07-28 23:16:10 +00:00
dds.clockTick();
}
}*/
//Comment if using dds.startPhaseAccumulator(true);
ISR(ADC_vect) {
if(false){
static unsigned char tcnt = 0;
TIFR1 = _BV(ICF1); // Clear the timer flag
if(++tcnt == 4) {
tcnt = 0;
}
dds.clockTick();
2016-08-27 19:50:51 +00:00
}
}