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 *************************
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?
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
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
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
135139const byte EEP_VER = 8 ;
136140const byte FMW_VER = 16 ;
137141
138142// structured data: Main Configuration Parameters
139- // nine, all strings ends with a null
140143struct 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.
155160struct 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 ******/
350358void 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
397405boolean ritActive = false ; // true: rit active, false: rit disabled
398406boolean tx = false ; // whether we are on TX mode or not
399407unsigned long lastMilis = 0 ; // to track the last sampled time
400- boolean barReDraw = true ; // bar needs to be redrawn from zero
401408boolean split = false ; // this holds th split state
402409boolean catTX = false ; // CAT command to go to PTT
403410word qcounter = 0 ; // Timer to be incremented each 1/4 second
@@ -451,7 +458,7 @@ void changeMode() {
451458void 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) {
0 commit comments