Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Si5351Arduino v2.0.0 library frequency bug test
/*
* 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;
#define BUTTON 12
#define LED 13
uint8_t state = 0;
void setup()
{
// Start serial and initialize the Si5351
Serial.begin(57600);
si5351.init(SI5351_CRYSTAL_LOAD_0PF, 0);
//si5351.set_correction(970);
si5351.set_correction(0);
// Set CLK0 to output 14 MHz with a fixed PLL frequency
si5351.set_freq(1460000000ULL, SI5351_CLK0);
//si5351.set_freq(14650000000ULL, SI5351_CLK0);
si5351.set_freq(10000000ULL, SI5351_CLK1);
si5351.set_freq(1410000ULL, SI5351_CLK2);
//si5351.drive_strength(SI5351_CLK0, SI5351_DRIVE_8MA);
Serial.print("State:");
Serial.println(state);
Serial.print("CLK0:");
Serial.println((uint32_t)(si5351.clk_freq[0]/100));
Serial.print("CLK1:");
Serial.println((uint32_t)(si5351.clk_freq[1]/100));
Serial.print("CLK2:");
Serial.println((uint32_t)(si5351.clk_freq[2]/100));
Serial.print("PLLA:");
Serial.println((uint32_t)(si5351.plla_freq/100));
Serial.println();
// Use a button connected to pin 12 as a trigger
pinMode(BUTTON, INPUT_PULLUP);
pinMode(LED, OUTPUT);
}
void loop()
{
// Debounce the button and trigger CLK1 output
if(digitalRead(BUTTON) == LOW)
{
delay(100); // delay to debounce
if (digitalRead(BUTTON) == LOW)
{
if(state == 0)
{
state = 1;
digitalWrite(LED, HIGH);
uint8_t status;
si5351.set_freq(1460000000ULL, SI5351_CLK0);
//status = si5351.set_freq(1290000000ULL, SI5351_CLK0);
status = si5351.set_freq(14345000000ULL, SI5351_CLK2);
//status = si5351.set_freq(12300000000ULL, SI5351_CLK2);
//Serial.print("Status:");
//Serial.println(status);
Serial.print("State:");
Serial.println(state);
Serial.print("CLK0:");
Serial.println((uint32_t)(si5351.clk_freq[0]/100));
Serial.print("CLK1:");
Serial.println((uint32_t)(si5351.clk_freq[1]/100));
Serial.print("CLK2:");
Serial.println((uint32_t)(si5351.clk_freq[2]/100));
Serial.print("PLLA:");
Serial.println((uint32_t)(si5351.plla_freq/100));
//Serial.print("PLL assignment:");
//Serial.println(si5351.pll_assignment[2]);
Serial.println();
}
else if(state == 1)
{
state = 2;
digitalWrite(LED, LOW);
uint8_t status;
//status = si5351.set_freq(14345000000ULL, SI5351_CLK2);
status = si5351.set_freq(12300000000ULL, SI5351_CLK2);
//Serial.print("Status:");
//Serial.println(status);
Serial.print("State:");
Serial.println(state);
Serial.print("CLK0:");
Serial.println((uint32_t)(si5351.clk_freq[0]/100));
Serial.print("CLK1:");
Serial.println((uint32_t)(si5351.clk_freq[1]/100));
Serial.print("CLK2:");
Serial.println((uint32_t)(si5351.clk_freq[2]/100));
Serial.print("PLLA:");
Serial.println((uint32_t)(si5351.plla_freq/100));
Serial.println();
}
else if(state == 2)
{
state = 3;
digitalWrite(LED, LOW);
uint8_t status;
si5351.set_freq(1410000ULL, SI5351_CLK2);
status = si5351.set_freq(14650000000ULL, SI5351_CLK0);
si5351.set_freq(10000000ULL, SI5351_CLK1);
//Serial.print("Status:");
//Serial.println(status);
Serial.print("State:");
Serial.println(state);
Serial.print("CLK0:");
Serial.println((uint32_t)(si5351.clk_freq[0]/100));
Serial.print("CLK1:");
Serial.println((uint32_t)(si5351.clk_freq[1]/100));
Serial.print("CLK2:");
Serial.println((uint32_t)(si5351.clk_freq[2]/100));
Serial.print("PLLA:");
Serial.println((uint32_t)(si5351.plla_freq/100));
Serial.println();
}
else if(state == 3)
{
state = 4;
si5351.reset();
Serial.print("State:");
Serial.println(state);
Serial.print("CLK0:");
Serial.println((uint32_t)(si5351.clk_freq[0]/100));
Serial.print("CLK1:");
Serial.println((uint32_t)(si5351.clk_freq[1]/100));
Serial.print("CLK2:");
Serial.println((uint32_t)(si5351.clk_freq[2]/100));
Serial.print("PLLA:");
Serial.println((uint32_t)(si5351.plla_freq/100));
Serial.println();
}
else if(state == 4)
{
state = 0;
digitalWrite(LED, LOW);
uint8_t status;
si5351.set_freq(1460000000ULL, SI5351_CLK0);
si5351.set_freq(10000000ULL, SI5351_CLK1);
si5351.set_freq(1410000ULL, SI5351_CLK2);
//si5351.set_freq(14650000000ULL, SI5351_CLK0);
//Serial.print("Status:");
//Serial.println(status);
Serial.print("State:");
Serial.println(state);
Serial.print("CLK0:");
Serial.println((uint32_t)(si5351.clk_freq[0]/100));
Serial.print("CLK1:");
Serial.println((uint32_t)(si5351.clk_freq[1]/100));
Serial.print("CLK2:");
Serial.println((uint32_t)(si5351.clk_freq[2]/100));
Serial.print("PLLA:");
Serial.println((uint32_t)(si5351.plla_freq/100));
Serial.println();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.