HamShield/examples/DDS/DDS.ino

77 lines
1.7 KiB
Arduino
Raw Normal View History

/* Hamshield
* Example: DDS
2016-08-26 21:40:47 +00:00
* This is a simple example to show how to transmit arbitrary
* tones. In this case, the sketh alternates between 1200Hz
* and 2200Hz at 1s intervals.
* Connect the HamShield to your Arduino. Screw the antenna
* into the HamShield RF jack. Connect the Arduino to wall
* power and then to your computer via USB. Upload this program
* to your Arduino. To test, set a HandyTalkie to 438MHz. You
* should hear two alternating tones.
*/
#define DDS_REFCLK_DEFAULT 9600
#include <HamShield.h>
#include <DDS.h>
2015-11-23 16:54:10 +00:00
#define PWM_PIN 3
#define RESET_PIN A3
#define SWITCH_PIN 2
#define DDS_USE_ONLY_TIMER2 true
#define TIMER2_PHASE_ADVANCE 24
HamShield radio;
DDS dds;
void setup() {
2015-11-23 16:54:10 +00:00
// NOTE: if not using PWM out, it should be held low to avoid tx noise
pinMode(PWM_PIN, OUTPUT);
digitalWrite(PWM_PIN, LOW);
// prep the switch
pinMode(SWITCH_PIN, INPUT_PULLUP);
// set up the reset control pin
pinMode(RESET_PIN, OUTPUT);
// turn on radio
digitalWrite(RESET_PIN, HIGH);
radio.initialize();
radio.setRfPower(0);
radio.frequency(438000);
radio.setModeTransmit();
dds.start();
dds.startPhaseAccumulator(DDS_USE_ONLY_TIMER2);
dds.playWait(600, 3000);
dds.on();
//dds.setAmplitude(31);
}
void loop() {
dds.setFrequency(2200);
delay(1000);
dds.setFrequency(1200);
delay(1000);
}
#if DDS_USE_ONLY_TIMER2
ISR(TIMER2_OVF_vect) {
2015-07-09 20:57:22 +00:00
static unsigned char tcnt = 0;
if(++tcnt == TIMER2_PHASE_ADVANCE) {
2015-07-09 20:57:22 +00:00
tcnt = 0;
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;
2015-07-09 20:57:22 +00:00
}
dds.clockTick();
}
#endif