Skip to content

Commit

Permalink
manual merge
Browse files Browse the repository at this point in the history
  • Loading branch information
NT7S committed Dec 1, 2016
2 parents 5726a58 + 273e9fa commit ad6005a
Show file tree
Hide file tree
Showing 13 changed files with 1,607 additions and 583 deletions.
290 changes: 204 additions & 86 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* Simple calibration routine for the Si5351 breakout board.
/*
* si5351_calibration.ino - Simple calibration routine for the Si5351
* breakout board.
*
* Copyright 2015 Paul Warren <pwarren@pwarren.id.au>
* Copyright 2015 - 2016 Paul Warren <pwarren@pwarren.id.au>
* Jason Milldrum <milldrum@gmail.com>
*
* Uses code from https://github.com/darksidelemm/open_radio_miniconf_2015
* and the old version of the calibration sketch
Expand All @@ -22,7 +25,7 @@

Si5351 si5351;

int32_t cal_factor;
int32_t cal_factor = 0;
int32_t old_cal;

uint64_t rx_freq;
Expand All @@ -32,40 +35,38 @@ void setup()
{
// Start serial and initialize the Si5351
Serial.begin(57600);
si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0);

// get old cal factor
//old_cal = si5351.get_correction();
si5351.set_correction(0);
// start on target frequency
si5351.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
si5351.set_freq(target_freq, SI5351_PLL_FIXED, SI5351_CLK0);
// The crystal load value needs to match in order to have an accurate calibration
si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);

// Start on target frequency
si5351.set_freq(target_freq, SI5351_CLK0);
}

void loop()
{
si5351.update_status();
if (si5351.dev_status.SYS_INIT == 1) {
Serial.println("Initialising Si5351, you shouldn't see many of these!");
if (si5351.dev_status.SYS_INIT == 1)
{
Serial.println(F("Initialising Si5351, you shouldn't see many of these!"));
delay(500);
} else {
cal_factor = 0;
// Serial.print("Old cal factor was: ");
// Serial.println(old_cal);
// Serial.println("Cal factor now set to 0");
// si5351.set_correction(0);
}
else
{
Serial.println();
Serial.println(F("Adjust until your frequency counter reads as close to 10 MHz as possible"));
Serial.println(F("Adjust until your frequency counter reads as close to 10 MHz as possible."));
Serial.println(F("Press 'q' when complete."));
vfo_interface();

Serial.println();
Serial.print(F("Calibration factor is "));
Serial.println(cal_factor);
Serial.println("Setting calibration factor");
Serial.println(F("Setting calibration factor"));
si5351.set_correction(cal_factor);
Serial.println("Resetting target frequency");
si5351.set_freq(target_freq, SI5351_PLL_FIXED, SI5351_CLK0);
}


Serial.println(F("Resetting target frequency"));
si5351.set_freq(target_freq, SI5351_CLK0);
si5351.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
}
}

static void flush_input(void)
Expand All @@ -80,10 +81,13 @@ static void vfo_interface(void)
Serial.println(F(" Up: r t y u i o p"));
Serial.println(F(" Down: f g h j k l ;"));
Serial.println(F(" Hz: 0.01 0.1 1 10 100 1K 10k"));
while (1) {
if (Serial.available() > 0) {
while (1)
{
if (Serial.available() > 0)
{
char c = Serial.read();
switch (c) {
switch (c)
{
case 'q':
flush_input();
return;
Expand All @@ -105,11 +109,12 @@ static void vfo_interface(void)
// Do nothing
continue;
}
si5351.set_freq(rx_freq,SI5351_PLL_FIXED,SI5351_CLK0);

cal_factor = (int32_t)(target_freq - rx_freq);
Serial.print("Current difference:");
si5351.set_correction(cal_factor);
si5351.set_freq(target_freq, SI5351_CLK0);
Serial.print(F("Current difference:"));
Serial.println(cal_factor);
}
}
}

68 changes: 68 additions & 0 deletions examples/si5351_clk67_example/si5351_clk67_example.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* si5351_clk67_example.ino - Simple example of setting CLK6 and CLK7
* outputs using Si5351Arduino library
*
* Copyright (C) 2016 Jason Milldrum <milldrum@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "si5351.h"
#include "Wire.h"

Si5351 si5351;

void setup()
{
// Start serial and initialize the Si5351
Serial.begin(57600);
si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);

// Set CLK0 to output 14 MHz
si5351.set_freq(1400000000ULL, SI5351_CLK0);

// Set CLK6 to 23 MHz, library sets PLL to 874 MHz
si5351.set_freq(2300000000ULL, SI5351_CLK6);

// This won't work since it is not an even multiple of the PLL (874 MHz)
si5351.set_freq(1234567800ULL, SI5351_CLK7);

// Setting CLK7 to 87.4 MHz will work
si5351.set_freq(8740000000ULL, SI5351_CLK7);

si5351.update_status();
delay(500);
}

void loop()
{
// Read the Status Register and print it every 10 seconds
si5351.update_status();
Serial.print("PLLA: ");
Serial.print((uint32_t)(si5351.plla_freq/100));
Serial.print(" PLLB: ");
Serial.print((uint32_t)(si5351.pllb_freq/100));
Serial.print(" SYS_INIT: ");
Serial.print(si5351.dev_status.SYS_INIT);
Serial.print(" LOL_A: ");
Serial.print(si5351.dev_status.LOL_A);
Serial.print(" LOL_B: ");
Serial.print(si5351.dev_status.LOL_B);
Serial.print(" LOS: ");
Serial.print(si5351.dev_status.LOS);
Serial.print(" REVID: ");
Serial.println(si5351.dev_status.REVID);

delay(10000);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* si5351example.ino - Simple example of using Si5351Arduino library
* si5351_example.ino - Simple example of using Si5351Arduino library
*
* Copyright (C) 2015 Jason Milldrum <milldrum@gmail.com>
* Copyright (C) 2015 - 2016 Jason Milldrum <milldrum@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -16,7 +16,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#include "si5351.h"
#include "Wire.h"
Expand All @@ -27,14 +26,19 @@ void setup()
{
// Start serial and initialize the Si5351
Serial.begin(57600);
si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0);
si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);

// Set CLK0 to output 14 MHz with a fixed PLL frequency
si5351.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
si5351.set_freq(1400000000ULL, SI5351_PLL_FIXED, SI5351_CLK0);
// Set CLK0 to output 14 MHz
si5351.set_freq(1400000000ULL, SI5351_CLK0);

// Set CLK1 to output 20 MHz
si5351.set_freq(2000000000ULL, 0ULL, SI5351_CLK1);
// Set CLK1 to output 175 MHz
si5351.set_ms_source(SI5351_CLK1, SI5351_PLLB);
si5351.set_freq_manual(17500000000ULL, 70000000000ULL, SI5351_CLK1);

// Query a status update and wait a bit to let the Si5351 populate the
// status flags correctly.
si5351.update_status();
delay(500);
}

void loop()
Expand Down
61 changes: 61 additions & 0 deletions examples/si5351_ext_ref/si5351_ext_ref.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* si5351_ext_ref.ino - Simple example of using an external reference
* clock with the Si5351Arduino library
*
* Copyright (C) 2016 Jason Milldrum <milldrum@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "si5351.h"
#include "Wire.h"

Si5351 si5351;

void setup()
{
// Start serial
Serial.begin(57600);

// Initialize the Si5351 to use a 10 MHz clock input on CLKIN
si5351.init(SI5351_CRYSTAL_LOAD_0PF, 10000000UL, 0);

// Set PLLA and PLLB to use the signal on CLKIN instead of the XTAL
si5351.set_pll_input(SI5351_PLLA, SI5351_PLL_INPUT_CLKIN);
si5351.set_pll_input(SI5351_PLLB, SI5351_PLL_INPUT_CLKIN);

// Set CLK0 to output 14 MHz
si5351.set_freq(1400000000ULL, SI5351_CLK0);

si5351.update_status();
delay(500);
}

void loop()
{
// Read the Status Register and print it every 10 seconds
si5351.update_status();
Serial.print(" SYS_INIT: ");
Serial.print(si5351.dev_status.SYS_INIT);
Serial.print(" LOL_A: ");
Serial.print(si5351.dev_status.LOL_A);
Serial.print(" LOL_B: ");
Serial.print(si5351.dev_status.LOL_B);
Serial.print(" LOS: ");
Serial.print(si5351.dev_status.LOS);
Serial.print(" REVID: ");
Serial.println(si5351.dev_status.REVID);

delay(10000);
}
72 changes: 72 additions & 0 deletions examples/si5351_outputs/si5351_outputs.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* si5351_outputs.ino - How to set different output sources
* with the Si5351Arduino library
*
* Copyright (C) 2016 Jason Milldrum <milldrum@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "si5351.h"
#include "Wire.h"

Si5351 si5351;

void setup()
{
// Start serial and initialize the Si5351
Serial.begin(57600);
si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);

// Set CLK0 to output 14 MHz
si5351.set_freq(1400000000ULL, SI5351_CLK0);

// Enable clock fanout for the XO
si5351.set_clock_fanout(SI5351_FANOUT_XO, 1);

// Enable clock fanout for MS
si5351.set_clock_fanout(SI5351_FANOUT_MS, 1);

// Set CLK1 to output the XO signal
si5351.set_clock_source(SI5351_CLK1, SI5351_CLK_SRC_XTAL);
si5351.output_enable(SI5351_CLK1, 1);

// Set CLK2 to mirror the MS0 (CLK0) output
si5351.set_clock_source(SI5351_CLK2, SI5351_CLK_SRC_MS0);
si5351.output_enable(SI5351_CLK2, 1);

// Change CLK0 output to 10 MHz, observe how CLK2 also changes
si5351.set_freq(1000000000ULL, SI5351_CLK0);

si5351.update_status();
delay(500);
}

void loop()
{
// Read the Status Register and print it every 10 seconds
si5351.update_status();
Serial.print(" SYS_INIT: ");
Serial.print(si5351.dev_status.SYS_INIT);
Serial.print(" LOL_A: ");
Serial.print(si5351.dev_status.LOL_A);
Serial.print(" LOL_B: ");
Serial.print(si5351.dev_status.LOL_B);
Serial.print(" LOS: ");
Serial.print(si5351.dev_status.LOS);
Serial.print(" REVID: ");
Serial.println(si5351.dev_status.REVID);

delay(10000);
}
Loading

0 comments on commit ad6005a

Please sign in to comment.