Create a gist now

Instantly share code, notes, and snippets.

anonymous /Kanga_DDS_Shield_Test
Created Sep 12, 2013

What would you like to do?
Test Sketch for the Kanga DDS Shield
/*
Kanga_DDS_Shield_Test
Simple test sketch for the DDS Shield
Set up and output 1MHz
See: http://m0xpd.blogspot.co.uk/p/kanga-uk-resources.html
m0xpd
September 2013
*/
// set pin numbers (assuming the default pin assignment)...
const int W_CLK = 2;
const int FQ_UD = 3;
const int DATA = 4;
const int RESET = 5;
// set frequency...
double freq = 1000000;
#define pulseHigh(pin) {digitalWrite(pin, HIGH); digitalWrite(pin, LOW); }
void tfr_byte2(byte data)
{
shiftOut(DATA, W_CLK, LSBFIRST, data);
}
void sendFrequency(double frequency) {
int32_t freq = frequency * 4294967295/125000000;
for (int b=0; b<4; b++, freq>>=8) {
tfr_byte2(freq & 0xFF);
}
tfr_byte2(0x000);
pulseHigh(FQ_UD);
}
void setup() {
pinMode(FQ_UD, OUTPUT);
pinMode(W_CLK, OUTPUT);
pinMode(DATA, OUTPUT);
pinMode(RESET, OUTPUT);
pulseHigh(RESET);
pulseHigh(W_CLK);
pulseHigh(FQ_UD);
sendFrequency(freq);
}
void loop(){
// .. sit doing nothing!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment