/********************************************************************* This sketch is designed to facilitate a one-time calibration of the si5351 three port oscillator board. To provide maximum versitility, no display is used in the sketch. Rather, the serial monitor is all that is needed to do the work. You will first be asked to select a WWV Frequency, depending on current proprogation, that you will zero beat the signal from the oscillator. WARNING... WWV time signals are outside the amateur band, you must not apply any amplification to the output of the si5351. 73, N0TKN March 16, 2015 ********************************************************************/ //#include // code for si5351 clock generator module from Adafruit // it is controlled via i2c buss on pins a4 and a5 #include "si5351.h" #include "Wire.h" Si5351 si5351; int_fast32_t bfo = 8998500L; // default offset int_fast32_t caltx = 10000000L; // Calibration frequency ** int_fast32_t calval = 100L; // Calibration frequency ** int calinc = 0;// increment value used in the calibration routine ** int flag = 0;// use to show warning only once int value = 0; int mult = 0; int dummy = 0; int x = 0; const int LedPin = 13; // ** void setup() { Serial.begin(115200); // connect to the serial port pinMode(LedPin,OUTPUT);//** digitalWrite(LedPin,LOW);//** Blink(3); // initialize the Si5351 si5351.init(SI5351_CRYSTAL_LOAD_8PF); //si5351.set_correction(170);// Not needed if we are calibrating ** si5351.set_pll(SI5351_PLL_FIXED, SI5351_PLLA); si5351.set_freq(0 , SI5351_PLL_FIXED, SI5351_CLK0); si5351.set_freq(bfo, 0, SI5351_CLK2); si5351.drive_strength(SI5351_CLK0,SI5351_DRIVE_8MA); si5351.drive_strength(SI5351_CLK2,SI5351_DRIVE_8MA); } void loop() { IntroScreen(); //Display intro screen in serial monitor IntroScreen(); //get WWV frequency for zero beat one time //display warning screen on no amplification one time GetCalibrationValue();//display current si5351 calibration value and ask for change //if new value is requested get the new value from keyboard //program that value and loop back } void Blink(int blinks){ while (x < blinks + 1){ digitalWrite(LedPin, HIGH); // turn the LED on (HIGH is the voltage level) delay(500); // wait for a second digitalWrite(LedPin, LOW); // turn the LED off by making the voltage LOW delay(500); x++; } } void IntroScreen(){ if (flag == 0){ Serial.println("*****************************************"); Serial.println("* 5351 Calibrate Routine * "); Serial.println("* *"); Serial.println("* Please enter a WWV frequency you *"); Serial.println("* can currently hear...5, 10 or 15 MHZ *"); Serial.println("* *"); Serial.println("* Enter 5, 10 or 15 and press return *"); Serial.println("*****************************************"); while(value == 0){ value = Serial.parseInt(); } delay(500); mult = value; value = 0; bfo = mult * 1000000; si5351.set_freq(bfo, 0, SI5351_CLK2); Serial.println("*****************************************"); Serial.println("* * "); Serial.println("* WARNING *"); Serial.print("* "); Serial.print(mult); Serial.println(" MHZ.is outside the Amateur Band *"); Serial.println("* *"); Serial.println("* Do not amplify *"); Serial.println("* *"); Serial.println("*****************************************"); flag = 1; delay(4000); } } void GetCalibrationValue(){ calval=5000; calval=si5351.get_correction(); delay(500); Serial.println(" "); Serial.println(" ");Serial.println(" "); Serial.println(" ");Serial.println(" "); Serial.println(" ");Serial.println(" "); Serial.println(" "); Serial.println(" "); Serial.println("*****************************************"); Serial.println("* * "); Serial.println("* The current calibration value is: *"); Serial.print("* "); Serial.print(calval); Serial.println(" *"); Serial.println("* *"); Serial.println("* Enter 1 to keep this value and exit *"); Serial.println("* or press 2 to try a new value *"); Serial.println("*****************************************"); Serial.println(" ");Serial.println(" "); Serial.println(" ");Serial.println(" "); while(value == 0){ value = Serial.parseInt(); } if (value == 1){ dummy = 1; // value is 1 so exit ExitQuit(); } else if (value == 2){ //save value dummy = 2; GetNewValue(); } else if (value > 2){// must be an invalid slection dummy = 99 - value; Serial.print("value equals = "); Serial.println(value); Serial.print("Dummy equals = "); Serial.println(dummy); Serial.println(" "); Serial.println(" "); Serial.println(" "); Serial.println("*****************************************"); Serial.println("* Invalid selection *"); Serial.println("* Please select 1 or 2 *"); Serial.println("*****************************************"); Serial.println(" ");Serial.println(" "); Serial.println(" ");Serial.println(" "); value = 0; delay(3000); } } void GetNewValue(){ Serial.println(" "); Serial.println(" ");Serial.println(" "); Serial.println(" ");Serial.println(" "); Serial.println(" ");Serial.println(" "); Serial.println(" "); Serial.println(" "); Serial.println("*****************************************"); Serial.println("* Please Enter a new * "); Serial.println("* Calibration Value *"); Serial.println("*****************************************"); Serial.println(" ");Serial.println(" "); Serial.println(" ");Serial.println(" "); value = 0; while(value == 0){ value = Serial.parseInt(); } si5351.set_correction(value); delay (250); si5351.set_freq(bfo, 0, SI5351_CLK2); value=0; delay(1000); } void ExitQuit(){ Serial.println(" "); Serial.println(" "); Serial.println(" "); Serial.println("*****************************************"); Serial.println("* All Done *"); Serial.println("* Disconnect USB Cable *"); Serial.println("*****************************************"); Serial.println(" ");Serial.println(" "); Serial.println(" ");Serial.println(" "); si5351.set_freq(9000000, 0, SI5351_CLK2); value = 0; while (value==0){//lock in a loop and stay right here until reset dummy = 999; } }