DDS/examples/SimpleSin/SimpleSin.ino

50 lines
852 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-30 19:07:00 +00:00
#define DDS_USE_ONLY_TIMER2 true
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();
2017-07-30 18:53:55 +00:00
dds.startPhaseAccumulator(DDS_USE_ONLY_TIMER2);
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
2017-07-30 18:53:55 +00:00
#if DDS_USE_ONLY_TIMER2
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();
}
2017-07-30 18:53:55 +00:00
}
#else // Use the ADC timer instead
2017-07-28 23:16:10 +00:00
ISR(ADC_vect) {
2017-07-30 19:07:00 +00:00
static unsigned char tcnt = 0;
TIFR1 = _BV(ICF1); // Clear the timer flag
if(++tcnt == 4) {
tcnt = 0;
2016-08-27 19:50:51 +00:00
}
2017-07-30 19:07:00 +00:00
dds.clockTick();
2016-08-27 19:50:51 +00:00
}
2017-07-30 18:53:55 +00:00
#endif