Last active
October 31, 2021 17:06
-
-
Save la3pna/c6999f5f59f875a1200193153191fa0a to your computer and use it in GitHub Desktop.
Si5351 Simple Sweep Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Si5351 Simple Sweep Generator | |
connect Si5351 to I2C | |
Sweep out is on pin 5, ranging from 0-5V (3.3V). | |
Use a filter on sweep out voltage. 100K + 1uF should be a good start. | |
A op-amp can be used to improve the filtering of the DC voltage. | |
Copyright (c) 2016 Thomas S. Knutsen <[email protected]> | |
Permission is hereby granted, free of charge, to any person obtaining | |
a copy of this software and associated documentation files (the | |
"Software"), to deal in the Software without restriction, including | |
without limitation the rights to use, copy, modify, merge, publish, | |
distribute, sublicense, and/or sell copies of the Software, and to | |
permit persons to whom the Software is furnished to do so, subject | |
to the following conditions: | |
The above copyright notice and this permission notice shall be | |
included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR | |
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | |
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
*/ | |
int correction = 0; // use the Si5351 correction sketch to find the frequency correction factor | |
int inData = 0; | |
long steps = 100; | |
unsigned long startFreq = 10000000; | |
unsigned long stopFreq = 100000000; | |
int analogpin = 5; | |
int delaytime = 50; | |
#include <si5351.h> | |
#include "Wire.h" | |
Si5351 si5351; | |
void setup() { | |
Serial.begin(9600); | |
while (!Serial) { | |
; // wait for serial port to connect. Needed for Leonardo only | |
} | |
si5351.init(SI5351_CRYSTAL_LOAD_8PF, 0); | |
si5351.drive_strength(SI5351_CLK0, SI5351_DRIVE_6MA); | |
si5351.set_correction(correction); | |
info(); | |
} | |
void info(){ | |
Serial.println("Si5351 sweeper"); | |
Serial.println("A = Start frequency"); | |
Serial.println("B = Stop frequency"); | |
Serial.println("S = Stepsize"); | |
Serial.println("M = single sweep"); | |
Serial.println("C = continious sweep untill Q"); | |
Serial.println("T = timestep in ms, currently 50."); | |
} | |
void loop() { | |
inData = 0; | |
if (Serial.available() > 0) // see if incoming serial data: | |
{ | |
inData = Serial.read(); // read oldest byte in serial buffer: | |
} | |
if (inData == 'M') { | |
inData = 0; | |
unsigned long freqstep = (stopFreq - startFreq) / steps ; | |
for (int i = 0; i < (steps+1); i++ ) { | |
unsigned long freq = startFreq + (freqstep*i); | |
si5351.set_freq(freq*100ULL, 0, SI5351_CLK0); | |
analogWrite(analogpin, map(i, 0, steps,0,255)); | |
delay(delaytime); | |
} | |
} | |
if (inData == 'C'){ | |
boolean runing = true; | |
inData = 0; | |
while(runing){ | |
unsigned long freqstep = (stopFreq - startFreq) / steps ; | |
for (int i = 0; i < (steps+1); i++ ) { | |
unsigned long freq = startFreq + (freqstep*i); | |
si5351.set_freq(freq*100ULL, 0, SI5351_CLK0); | |
analogWrite(analogpin, map(i, 0, steps,0,255)); | |
delay(delaytime); | |
if (Serial.available() > 0) // see if incoming serial data: | |
{ | |
inData = Serial.read(); // read oldest byte in serial buffer: | |
if (inData == 'Q'){ | |
runing = false; | |
inData = 0; | |
} | |
} | |
} | |
} | |
} | |
if (inData == 'S') { | |
steps = Serial.parseInt(); | |
Serial.print("Steps: "); | |
Serial.println(steps); | |
inData = 0; | |
} | |
if (inData == 'H'){ | |
info(); | |
} | |
if (inData == 'T'){ | |
delaytime = Serial.parseInt(); | |
Serial.print("time pr step: "); | |
Serial.println(delaytime); | |
inData = 0; | |
} | |
if (inData == 'L') { | |
for (int i = 0; i < (steps+1); i++ ) { | |
// print out the value you read: | |
Serial.print(i*10); | |
Serial.print(';'); | |
Serial.print(steps); | |
Serial.print(';'); | |
Serial.println(-i); | |
delay(10); // delay in between reads for stability | |
} | |
inData = 0; | |
} | |
if (inData == 'A') { | |
startFreq = Serial.parseInt(); | |
Serial.print("Start: "); | |
Serial.println(startFreq); | |
inData = 0; | |
} | |
if (inData == 'B') { | |
stopFreq = Serial.parseInt(); | |
Serial.print("Stop: "); | |
Serial.println(stopFreq); | |
inData = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment