Skip to content

Commit adb53c3

Browse files
committed
Codements update/chage to reflect lastest changes
1 parent af82d8c commit adb53c3

File tree

4 files changed

+70
-73
lines changed

4 files changed

+70
-73
lines changed

arduino-arcs.ino

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@
3434
/*******************************************************************************
3535
* Important information you need to know about this code & Si5351
3636
*
37-
* We use a Si5351a control code that presume this:
37+
* We use a embed Si5351a control code that presume this:
3838
* * We use CLK0 & CLK1 ONLY
3939
* * CLK0 use PLLA & CLK1 use PLLB
4040
* * CLK0 is employed as VFO (to mix with the RF from/to the antenna)
4141
* * CLK1 is employed as BFO (to mix with the IF to mod/demodulate the audio)
42-
* * We use the full power in all outputs (8mA ~0dB?)
42+
* * We use the full power in all outputs (8mA)
4343
*
44-
* * Please have in mind that this IC has a SQUARE wave output and you need to
45-
* apply some kind of low-pass/band-pass filtering to smooth it and get rid
46-
* of the nasty harmonics
44+
* * Please have in mind that this IC has a SQUARE wave output and you MAY
45+
* need to apply some kind of low-pass/band-pass filtering to smooth it
46+
* and get rid of the nasty harmonics.
47+
* * If you generate a BFO below 1Mhz you MUST filter the output of that CLK.
48+
* The output of the Si5351 is harmonic rich below 1Mhz and you will NEED
49+
* the filtering because those harmonics are close enough of the fundamental.
4750
******************************************************************************/
4851

4952
/****************************** FEATURES SEGMENTATION *************************
@@ -52,6 +55,7 @@
5255
*
5356
* For example: one user requested a "headless" mode: no lcd, no buttons, just
5457
* cat control via serial/usb from the PC. for that we have the headless mode.
58+
* Tip: uncomment th LCD define and you will have it.
5559
*******************************************************************************/
5660

5761
// You like to have CAT control (PC control) of the sketch via Serial link?
@@ -65,8 +69,8 @@
6569
#define ABUT True
6670

6771
// Memories?
68-
//#define MEMORIES True // limited to 100 mems
69-
// in some arduino boards can be less.
72+
//#define MEMORIES True // hard limited to 99 mems (~80 on the ATMEga168)
73+
// because we have only two spaces to represent that
7074

7175
// Smeter on the LCD?
7276
#define SMETER True
@@ -106,7 +110,7 @@
106110
#endif // cat control
107111
#endif // headless
108112

109-
// safety check for no rotary
113+
// safety check for no rotary, if no rotary then abut has no use.
110114
#ifndef ROTARY
111115
// no need for Analog Buttons
112116
#ifdef ABUT
@@ -119,39 +123,40 @@
119123
#endif // memories
120124
#endif // rotary
121125

122-
// safety check for no analog buttons & memories
126+
// safety check for memories only when analog buttons are in use
123127
#ifndef ABUT
124128
#ifdef MEMORIES
125129
#undef MEMORIES
126130
#endif // memories
127131
#endif // abut
128132

129133
// default (non optional) libraries loading
130-
#include <EEPROM.h> // default
131-
#include <Wire.h> // Wire (I2C)
134+
#include <EEPROM.h> // Internal EEPROM
135+
#include <Wire.h> // I2C
132136

133137
// The eeprom & sketch version; if the eeprom version is lower than the one on
134138
// the sketch we force an update (init) to make a consistent work on upgrades
135139
const byte EEP_VER = 8;
136140
const byte FMW_VER = 16;
137141

138142
// structured data: Main Configuration Parameters
139-
// nine, all strings ends with a null
140143
struct userData {
141144
byte fmwver = FMW_VER;
142145
byte eepver = EEP_VER;
143146
long ifreq; // first or unique IF
144147
long if2; // second IF, usually higher than the ifreq
145148
long a; // VFO a
146-
byte aMode;
149+
byte aMode; // VFO a mode
147150
long b; // VFO b
148-
byte bMode;
151+
byte bMode; // VFO b mode
149152
int usb;
150153
int cw;
151154
int ppm;
152155
};
153156

154157
// declaring the main configuration variable for mem storage
158+
// BEWARE: you can't use it outside a procedure or function
159+
// the compiler is not happy with that.
155160
struct userData u;
156161

157162
// The start byte in the eeprom where we put mem[0]
@@ -173,7 +178,7 @@ struct userData u;
173178

174179
// If you have a half step encoder (you need two clicks to make a step)
175180
// uncomment this to get it working
176-
#define HALF_STEP
181+
//#define HALF_STEP
177182

178183
// include the libs
179184
#include <Rotary.h> // https://github.com/mathertel/RotaryEncoder/
@@ -201,28 +206,31 @@ struct userData u;
201206
// define the sampling rate used
202207
#define BMUX_SAMPLING 10 // 10 samples per second
203208

204-
// include the lib
205-
#include <BMux.h> // https://github.com/pavelmc/BMux/
206-
207209
// define the analog pin to handle the buttons
208210
#define KEYS_PIN 2
209211

212+
// include the lib
213+
#include <BMux.h> // https://github.com/pavelmc/BMux/
214+
210215
// instantiate it
211216
BMux abm;
212217

213218
// Creating the analog buttons for the BMux lib; see the BMux doc for details
214219
// you may have to tweak this values a little for your particular hardware
215220
//
216-
// define the adc levels of for the buttons values
221+
// Also on the examples on the lib there is a sketch that will allow to
222+
// compute the exact values for your hardware.
223+
//
224+
// Define the adc levels of for the buttons values
217225
// top resistor 4k7 2k2 10k
218226
#define b1 207 // 1k2 470 2k2
219227
#define b2 370 // 2k7 1k 4k7
220228
#define b3 512 // 4k7 2k2 10k
221229
#define b4 697 // 10k 4k7 22k
222230

223231
#ifdef MEMORIES
224-
// buttons has a second action related to memories
225-
// only if we have memories set
232+
// Analog buttons has a second action related to memories
233+
// but only if we have memories set
226234
Button bvfoab = Button(b1, &btnVFOABClick, &btnVFOMEM);
227235
Button bmode = Button(b2, &btnModeClick, &btnVFOsMEM);
228236
Button brit = Button(b3, &btnRITClick, &btnEraseMEM);
@@ -231,7 +239,7 @@ struct userData u;
231239
// memory object definition
232240
boolean vfoMode = true;
233241
word mem = 0; // actual memory channel
234-
word memCount = 0; // how many mems this chip support
242+
word memCount; // how many mems this chip support
235243
// (it's calculated in the setup process)
236244

237245
// memory type
@@ -245,7 +253,7 @@ struct userData u;
245253
struct mmem memo;
246254

247255
#else
248-
// buttons with single functions
256+
// Analog buttons with single functions
249257
Button bvfoab = Button(b1, &btnVFOABClick);
250258
Button bmode = Button(b2, &btnModeClick);
251259
Button brit = Button(b3, &btnRITClick);
@@ -279,14 +287,16 @@ struct userData u;
279287
// lcd library instantiate
280288
LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
281289

282-
// how many samples we take in the smeter, we use a 2/3 trick to get some
283-
// inertia and improve the look & feel of the bar
284-
#define BARGRAPH_SAMPLES 6
285-
word pep[BARGRAPH_SAMPLES] = {};
286-
// s-meter readings storage
287-
boolean smeterOk = false; // it's ok to show the bar graph
288-
word sMeter = 0; // hold the value of the Smeter readings
289-
// in both RX and TX modes
290+
#ifdef SMETER
291+
// how many samples we take in the smeter, we use a 2/3 trick to get some
292+
// inertia and improve the look & feel of the bar
293+
#define BARGRAPH_SAMPLES 6
294+
word pep[BARGRAPH_SAMPLES] = {}; // s-meter readings storage
295+
boolean smeterOk = false; // it's ok to show the bar graph
296+
word sMeter = 0; // hold the value of the Smeter readings
297+
// in both RX and TX modes
298+
boolean barReDraw = true; // Smeter bar needs to be redrawn
299+
#endif // smeter
290300
#endif // nolcd
291301

292302

@@ -311,17 +321,15 @@ struct userData u;
311321
#define CONFIG_MAX 8
312322

313323
// Tick interval for the timed actions like the SMeter and the autosave
314-
#define TICK_INTERVAL 250 // milli seconds, 4 ticks per second
324+
#define TICK_INTERVAL 250 // in milli seconds, 4 ticks per second
315325

316-
// EERPOM saving interval (if some parameter has changed) in TICK_INTERVAL
326+
// EERPOM auto saving interval (if some parameter has changed) in TICK_INTERVAL
317327
// var is word so max is 65535 in 1/4 secs is ~ 16383 sec ~ 273 min ~ 4h 33 min
318328
#define SAVE_INTERVAL 2400 // 10 minutes = 60 sec * 4 ticks/sec * 10 min
319329

320330
// Si5351a Xtal
321-
long XTAL = 27000000; // default FREQ of the XTAL for the Si5351a
322-
323-
// the variables
324-
long XTAL_C = XTAL + u.ppm; // corrected xtal with the ppm
331+
const long XTAL = 27000000; // default FREQ of the XTAL for the Si5351a
332+
long CXTAL = XTAL + u.ppm; // corrected xtal with the ppm
325333

326334
/******************************************************************************
327335
* The use of an XFO... some users are requesting the use of an XFO in the
@@ -348,8 +356,7 @@ long XTAL_C = XTAL + u.ppm; // corrected xtal with the ppm
348356

349357
/****** hardware pre-configured values ******/
350358
void setDefaultVals() {
351-
// 1st IF xtal, if you have just one IF this is ZERO
352-
// this is the (positive) difference between the high and low IFs in Hz
359+
// 1st (or High) IF value, if you have just one IF this is ZERO
353360
u.if2 = 0; // Zero if no second IF
354361

355362
// 2nd of unique IF, this is the one you beat to get the audio
@@ -373,8 +380,9 @@ void setDefaultVals() {
373380
// VFO B default mode
374381
u.aMode = MODE_LSB; // LSB
375382

376-
// This value is not the real PPM value is just the freq correction for your
377-
// particular xtal from the 27.00000 Mhz one, if you can measure it put it here
383+
// This value is not the real PPM value is just the freq correction for
384+
// yourparticular xtal from the 27.00000 Mhz one, if you can measure it
385+
// put it here, this trick is computational simpler and yet accurate
378386
u.ppm = 2256; // in Hz, mine is 2.256 Khz up
379387
}
380388

@@ -397,7 +405,6 @@ boolean activeVFO = true; // true: A, False: B
397405
boolean ritActive = false; // true: rit active, false: rit disabled
398406
boolean tx = false; // whether we are on TX mode or not
399407
unsigned long lastMilis = 0; // to track the last sampled time
400-
boolean barReDraw = true; // bar needs to be redrawn from zero
401408
boolean split = false; // this holds th split state
402409
boolean catTX = false; // CAT command to go to PTT
403410
word qcounter = 0; // Timer to be incremented each 1/4 second
@@ -451,7 +458,7 @@ void changeMode() {
451458
void going2RX() {
452459
// PTT released, going to RX
453460
tx = false;
454-
digitalWrite(PTT, LOW);
461+
digitalWrite(PTT, 0);
455462

456463
// make changes if tx goes active when RIT is active
457464
if (ritActive) {

fa-lcd.ino

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212

1313
#ifdef LCD
1414
#ifdef ABUT
15-
// check some values don't go below zero
16-
void belowZero(long *value) {
17-
// some values are not meant to be below zero, this check and fix that
18-
if (*value < 0) *value = 0;
19-
}
15+
// check some values don't go below zero, as some values are not meant
16+
// to be below zero, this check and fix that
17+
void belowZero(long *value) { if (*value < 0) *value = 0; }
2018

2119

2220
// update the setup values
@@ -26,8 +24,6 @@
2624
// just showing, show the config on the LCD
2725
updateShowConfig(dir);
2826
} else {
29-
// change the VFO to A by default
30-
swapVFO(1);
3127
// I'm modifying, switch on the config item
3228
switch (config) {
3329
case CONFIG_IF:
@@ -52,7 +48,7 @@
5248
*ptrVFO += getStep() * dir;
5349
belowZero(ptrVFO);
5450
break;
55-
case CONFIG_MODE_A: // whichever VFO
51+
case CONFIG_MODE_A: // whichever VFO is active
5652
case CONFIG_MODE_B:
5753
// hot swap it
5854
changeMode();
@@ -75,7 +71,7 @@
7571
// change the Si5351 PPM
7672
u.ppm += getStep() * dir;
7773
// instruct the lib to use the new ppm value
78-
XTAL_C = XTAL + u.ppm;
74+
CXTAL = XTAL + u.ppm;
7975
// reset the Si5351
8076
Si5351_resets();
8177
break;
@@ -109,7 +105,7 @@
109105
void showConfigLabels() {
110106
switch (config) {
111107
case CONFIG_IF:
112-
lcd.print(F(" IF frequency "));
108+
lcd.print(F(" Main IF freq. "));
113109
break;
114110
case CONFIG_IF2:
115111
lcd.print(F(" High IF (opt) "));
@@ -161,6 +157,7 @@
161157

162158
// show the ppm as a signed long
163159
void showConfigValue(long val) {
160+
// add spacers
164161
spaces(3);
165162

166163
// Show the sign only on config and not VFO & IF
@@ -229,10 +226,7 @@
229226
// print a string of spaces, to save some flash/eeprom "space"
230227
void spaces(byte m) {
231228
// print m spaces in the LCD
232-
while (m) {
233-
lcd.print(" ");
234-
m--;
235-
}
229+
while (m) { lcd.print(" "); m--; }
236230
}
237231

238232

@@ -385,18 +379,18 @@
385379

386380
// show rit in LCD
387381
void showRit() {
388-
/***************************************************************************
382+
/***********************************************************************
389383
* RIT show something like this on the line of the non active VFO
390384
*
391385
* |0123456789abcdef|
392386
* |----------------|
393387
* |RX RIT -9.99 khz|
394388
* |----------------|
395389
*
396-
* WARNING !!!!!!!!!!!!!!!!!!!!1
397-
* If the user change the VFO we need to *RESET* & disable the RIT ASAP.
390+
* WARNING !!! If the user change the VFO we need to *RESET*
391+
* & disable the RIT ASAP.
398392
*
399-
**************************************************************************/
393+
**********************************************************************/
400394

401395
// get the active VFO to calculate the deviation & scale it down
402396
long diff = (*ptrVFO - tvfo)/10;

fd-si5351.ino

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ void si5351aSetFrequency(byte clk, unsigned long frequency) {
5353
case 128: R = 112; break;
5454
}
5555

56-
a = fvco / XTAL_C;
57-
f = fvco - a * XTAL_C;
56+
a = fvco / CXTAL;
57+
f = fvco - a * CXTAL;
5858
f = f * c;
59-
f = f / XTAL_C;
59+
f = f / CXTAL;
6060
b = f;
6161

6262
MSx_P1 = 128 * outdivider - 512;
@@ -66,9 +66,8 @@ void si5351aSetFrequency(byte clk, unsigned long frequency) {
6666
MSNx_P2 = 128 * b - MSNx_P2 * c;
6767
MSNx_P3 = c;
6868

69-
// PLLs and CLK# registers are allocated with a shift, we handle that with
70-
// the shifts var to make code smaller
71-
if (clk > 0 ) shifts = 8;
69+
// CLK# registers are exactly 8 * clk bytes shifted from a base register.
70+
shifts = clk * 8;
7271

7372
// plls, A & B registers separated by 8 bytes
7473
si5351ai2cWrite(26 + shifts, (MSNx_P3 & 65280) >> 8); // Bits [15:8] of MSNx_P3 in register 26
@@ -80,9 +79,6 @@ void si5351aSetFrequency(byte clk, unsigned long frequency) {
8079
si5351ai2cWrite(32 + shifts, (MSNx_P2 & 65280) >> 8); // Bits [15:8] of MSNx_P2 in register 32
8180
si5351ai2cWrite(33 + shifts, MSNx_P2 & 255); // Bits [7:0] of MSNx_P2 in register 33
8281

83-
// CLK# registers are exactly 8 * clk bytes shifted from a base register.
84-
shifts = clk * 8;
85-
8682
// multisynths
8783
si5351ai2cWrite(42 + shifts, 0); // Bits [15:8] of MS0_P3 (always 0) in register 42
8884
si5351ai2cWrite(43 + shifts, 1); // Bits [7:0] of MS0_P3 (always 1) in register 43

0 commit comments

Comments
 (0)