Arduino source code: Adjust AD9850 DDS frequency offset to zero-beat with GPS-locked oscillator
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
// Zero-beat oscillator to 10 MHz GPS-locked reference | |
printf("Zero beat DDS oscillator against GPS\n"); | |
TempFreq.fx_64 = CALFREQ; | |
u8x8.clearDisplay(); | |
byte ln = 0; | |
u8x8.drawString(0,ln++,"10 MHz Zero Beat"); | |
u8x8.drawString(0,ln++,"<- Joystick ->"); | |
u8x8.drawString(0,ln++," Button = set "); | |
int32_t OldOffset = OscOffset; | |
while (analogRead(PIN_JOYBUTTTON) > 500) { | |
int ai = analogRead(PIN_JOY_Y) - 512; // totally ad-hoc axes | |
if (ai < -100) { | |
OscOffset += 1; | |
} | |
else if (ai > 100) { | |
OscOffset -= 1; | |
} | |
if (OscOffset != OldOffset) { | |
ln = 4; | |
sprintf(Buffer,"Offset %8ld",OscOffset); | |
u8x8.drawString(0,ln++,Buffer); | |
CalcOscillator(OscOffset); // recalculate constants | |
TempCount.fx_64 = MultiplyFixedPt(TempFreq,CtPerHz); // recalculate delta phase count | |
WriteDDS(TempCount.fx_32.high); // should be 10 MHz out! | |
OldOffset = OscOffset; | |
} | |
Wire.requestFrom(LM75_ADDR,2); | |
Temperature.fx_32.high = Wire.read(); | |
Temperature.fx_32.low = (uint32_t)Wire.read() << 24; | |
PrintFixedPtRounded(Buffer,Temperature,3); | |
ln = 7; | |
u8x8.drawString(0,ln,"DDS Temp"); | |
u8x8.drawString(16-strlen(Buffer),ln++,Buffer); | |
delay(100); | |
} | |
printf("Oscillator offset: %ld\n",OscOffset); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More details on my blog at http://wp.me/poZKh-6Sz