Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ednisley
Created June 25, 2017 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ednisley/7789232cd2d50c277a0aa615eec3bd43 to your computer and use it in GitHub Desktop.
Save ednisley/7789232cd2d50c277a0aa615eec3bd43 to your computer and use it in GitHub Desktop.
Arduino source code: Adjust AD9850 DDS frequency offset to zero-beat with GPS-locked oscillator
// 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);
@ednisley
Copy link
Author

More details on my blog at http://wp.me/poZKh-6Sz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment