Si5351 VFO - Ino
Si5351 VFO - Ino
Si5351 VFO - Ino
Si5351 VFO
This version uses the new version of the Si5351 library from NT7S.
see: http://arduino.cc/en/Reference/AttachInterrupt for what pins that have
interrupts.
UNO and 328 boards: Encoder on pin 2 and 3. Center pin to GND.
Leonardo: Encoder on pin 0 and 1. Center pin to GND.
LCD connections for for the LinkSprite 16 X 2 LCD Keypad Shield for Arduino.
Change as necessary for your LCD.
IF frequency is positive for sum product (IF = RF + LO) and negative for diff (IF =
RF - LO)
VFO signal output on CLK0, BFO signal on CLK2
*/
// Only leave one uncommented for the display you wish to use
//#define OLED
//#define LCD
#define LCDI2C
#include <si5351.h>
#include "Wire.h"
// Class instantiation
Si5351 si5351;
// interrupt service routine vars
boolean A_set = false;
boolean B_set = false;
volatile unsigned long frequency = 7100000UL; // This will be the frequency it
always starts on.
volatile int tx;
// MHz
if(num / 1000000UL > 0)
{
sprintf(str, "%3lu", num / 1000000UL);
zero_pad = 1;
}
else
{
strcat(str, " ");
}
num %= 1000000UL;
// kHz
if(zero_pad == 1)
{
sprintf(temp_str, ",%03lu", num / 1000UL);
strcat(str, temp_str);
}
else if(num / 1000UL > 0)
{
sprintf(temp_str, ",%3lu", num / 1000UL);
strcat(str, temp_str);
zero_pad = 1;
}
else
{
strcat(str, " ");
}
num %= 1000UL;
// Hz
if(zero_pad == 1)
{
sprintf(temp_str, ",%03lu", num);
strcat(str, temp_str);
}
else
{
sprintf(temp_str, ",%3lu", num);
strcat(str, temp_str);
}
#if defined(OLED)
void draw_oled(void)
{
char temp_str[21];
u8g.setFont(u8g_font_unifont);
//u8g.setFont(u8g_font_helvR12);
sprintf_seperated(temp_str, frequency);
u8g.drawStr(0, 32, temp_str);
u8g.setFont(u8g_font_unifont);
sprintf(temp_str, "Step: %5u", freqstep[freqsteps]);
u8g.drawStr(0, 56, temp_str);
}
#endif
sprintf_seperated(temp_str, frequency);
lcd.setCursor(0, 0);
lcd.print(temp_str);
lcd.setCursor(6, 1);
sprintf(temp_str, "%5u", freqstep[freqsteps]);
lcd.print(temp_str);
}
#endif
void setup()
{
Serial.begin(9600);
// Set GPIO
pinMode(encoderPinA, INPUT);
pinMode(encoderPinB, INPUT);
pinMode(stepbutton, INPUT);
pinMode(txpin, INPUT);
#endif
#if defined(LCD)
lcd.begin(16, 2);
lcd.print("Si5351 VFO");
delay(2000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Step: ");
#endif
#if defined(OLED)
//U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0, corr);
si5351.set_freq((frequency + iffreq) * 100ULL, SI5351_CLK0);
si5351.set_freq(iffreq * 100ULL, SI5351_CLK2);
}
void loop()
{
if(digitalRead(txpin))
{
tx = 0;
}
else
{
tx = 1;
}
if (lastReportedPos != frequency)
{
lastReportedPos = frequency;
// Handle LCD
#if defined(LCD) || defined(LCDI2C)
draw_lcd();
#endif
// Handle OLED
#if defined(OLED)
u8g.firstPage();
do
{
draw_oled();
} while(u8g.nextPage());
delay(50);
#endif
if (inData == 'F')
{
frequency = Serial.parseInt();
inData = 0;
}
if (digitalRead(stepbutton) == LOW )
{
delay(50); // delay to debounce
if (digitalRead(stepbutton) == LOW )
{
freqsteps = freqsteps + 1;