Added support libraries

Uploaded Si5351 library and encoder library
This commit is contained in:
JeffersGlass
2015-09-21 15:45:16 -05:00
parent e126029540
commit 810a91b366
18 changed files with 4464 additions and 0 deletions

View File

@ -0,0 +1,115 @@
/* Simple calibration routine for the Si5351 breakout board.
*
* Copyright 2015 Paul Warren <pwarren@pwarren.id.au>
*
* Uses code from https://github.com/darksidelemm/open_radio_miniconf_2015
* and the old version of the calibration sketch
*
* This sketch 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.
* Foobar 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.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "si5351.h"
#include "Wire.h"
Si5351 si5351;
int32_t cal_factor;
int32_t old_cal;
uint64_t rx_freq;
uint64_t target_freq = 1000000000ULL; // 10 MHz, in hundredths of hertz
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);
}
void loop()
{
si5351.update_status();
if (si5351.dev_status.SYS_INIT == 1) {
Serial.println("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);
Serial.println();
Serial.println(F("Adjust until your frequency counter reads as close to 10 MHz as possible"));
vfo_interface();
Serial.print(F("Calibration factor is "));
Serial.println(cal_factor);
Serial.println("Setting calibration factor");
si5351.set_correction(cal_factor);
Serial.println("Resetting target frequency");
si5351.set_freq(target_freq, SI5351_PLL_FIXED, SI5351_CLK0);
}
}
static void flush_input(void)
{
while (Serial.available() > 0)
Serial.read();
}
static void vfo_interface(void)
{
rx_freq = target_freq;
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) {
char c = Serial.read();
switch (c) {
case 'q':
flush_input();
return;
case 'r': rx_freq += 1; break;
case 'f': rx_freq -= 1; break;
case 't': rx_freq += 10; break;
case 'g': rx_freq -= 10; break;
case 'y': rx_freq += 100; break;
case 'h': rx_freq -= 100; break;
case 'u': rx_freq += 1000; break;
case 'j': rx_freq -= 1000; break;
case 'i': rx_freq += 10000; break;
case 'k': rx_freq -= 10000; break;
case 'o': rx_freq += 100000; break;
case 'l': rx_freq -= 100000; break;
case 'p': rx_freq += 1000000; break;
case ';': rx_freq -= 1000000; break;
default:
// 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:");
Serial.println(cal_factor);
}
}
}

View File

@ -0,0 +1,56 @@
/*
* si5351example.ino - Simple example of using Si5351Arduino library
*
* Copyright (C) 2015 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);
// 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 CLK1 to output 20 MHz
si5351.set_freq(2000000000ULL, 0ULL, SI5351_CLK1);
}
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);
}

View File

@ -0,0 +1,92 @@
/*
* si5351phase.ino - Example for setting phase with Si5351Arduino library
*
* Copyright (C) 2015 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/>.
*/
/*
* Setting the phase of a clock requires that you manually set the PLL and
* take the PLL frequency into account when calculation the value to place
* in the phase register. As shown on page 10 of Silicon Labs Application
* Note 619 (AN619), the phase register is a 7-bit register, where a bit
* represents a phase difference of 1/4 the PLL period. Therefore, the best
* way to get an accurate phase setting is to make the PLL an even multiple
* of the clock frequency, depending on what phase you need.
*
* If you need a 90 degree phase shift (as in many RF applications), then
* it is quite easy to determine your parameters. Pick a PLL frequency that
* is an even multiple of your clock frequency (remember that the PLL needs
* to be in the range of 600 to 900 MHz). Then to set a 90 degree phase shift,
* you simply enter that multiple into the phase register. Remember when
* setting multiple outputs to be phase-related to each other, they each need
* to be referenced to the same PLL.
*/
#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);
// We will output 14.1 MHz on CLK0 and CLK1.
// A PLLA frequency of 705 MHz was chosen to give an even
// divisor by 14.1 MHz.
unsigned long long freq = 1410000000ULL;
unsigned long long pll_freq = 70500000000ULL;
// Set PLLA to the chosen frequency
si5351.set_pll(pll_freq, SI5351_PLLA);
// Set CLK0 and CLK1 to use PLLA as the MS source
si5351.set_ms_source(SI5351_CLK0, SI5351_PLLA);
si5351.set_ms_source(SI5351_CLK1, SI5351_PLLA);
// Set CLK0 and CLK1 to output 14.1 MHz with a fixed PLL frequency
si5351.set_freq(freq, pll_freq, SI5351_CLK0);
si5351.set_freq(freq, pll_freq, SI5351_CLK1);
// Now we can set CLK1 to have a 90 deg phase shift by entering
// 50 in the CLK1 phase register, since the ratio of the PLL to
// the clock frequency is 50.
si5351.set_phase(SI5351_CLK0, 0);
si5351.set_phase(SI5351_CLK1, 50);
// We need to reset the PLL before they will be in phase alignment
si5351.pll_reset(SI5351_PLLA);
}
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);
}