Created
September 12, 2013 16:27
-
-
Save anonymous/6540329 to your computer and use it in GitHub Desktop.
Test Sketch for the Kanga DDS Shield
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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