#include "si5351.h"
#include "Wire.h"
#include
Si5351 si5351;
Encoder myEnc(5, 6);
void setup()
{
// Start serial and initialize the Si5351
Serial.begin(57600);
si5351.init(SI5351_CRYSTAL_LOAD_8PF);
// Set CLK0 to output 14 MHz with a fixed PLL frequency
si5351.set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
si5351.set_freq(7000000ULL, SI5351_PLL_FIXED, SI5351_CLK0);
Serial.println("Starting");
}
long oldPosition = -999;
void loop()
{
long newPosition = myEnc.read();
if (newPosition != oldPosition) {
oldPosition = newPosition;
unsigned long int frequency = 7000000ULL + newPosition;
Serial.println(frequency);
si5351.set_freq(frequency, SI5351_PLL_FIXED, SI5351_CLK0);
}
}
And here's how it behaves (listen for the tone on the receiver in the background).
The flaw with this code is that if you turn the knob too fast it can't adjust the Si5351 fast enough to keep up. I have some vague ideas about how to deal with this, perhaps only updating a few times a second.
Take a look at my notes on this challenge at
ReplyDeletehttp://nosmokehere.blogspot.com/2014/12/signal-generator-part-2b-interrupting.html?m=1
Either my approach, or M0XPDs method linked in my article should help.