Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Owner

ednisley commented Jun 25, 2017

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