-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTune.cpp
More file actions
506 lines (417 loc) · 15.7 KB
/
Copy pathTune.cpp
File metadata and controls
506 lines (417 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
#ifndef BEENHERE
#include "SDT.h"
#endif
#ifdef V12
#ifndef BEENHERE
#include "SDT.h"
#endif
// Fix for ResetTuning(). KF5N August 5, 2023
//AFP 09-24-23 V12
/*****
Purpose: Select PLL Multiplier
Parameter list:
void
Return value;
void
*****/
int EvenDivisor(long freq2) {
//freq2=freq2/100;
// Serial.print("freq2= ");
//Serial.println(freq2);
if (freq2 < 6850000)
multiple = 126;
if ((freq2 >= 6850000) && (freq2 < 9500000))
multiple = 88;
if ((freq2 >= 9500000) && (freq2 < 13600000))
multiple = 64;
if ((freq2 >= 13600000) && (freq2 < 17500000))
multiple = 44;
if ((freq2 >= 17500000) && (freq2 < 25000000))
multiple = 34;
if ((freq2 >= 25000000) && (freq2 < 36000000))
multiple = 24;
if ((freq2 >= 36000000) && (freq2 < 45000000))
multiple = 18;
if ((freq2 >= 45000000) && (freq2 < 60000000))
multiple = 14;
if ((freq2 >= 60000000) && (freq2 < 80000000))
multiple = 10;
if ((freq2 >= 80000000) && (freq2 < 100000000))
multiple = 8;
if ((freq2 >= 100000000) && (freq2 < 146600000))
multiple = 6;
if ((freq2 >= 150000000) && (freq2 < 220000000))
multiple = 4;
return multiple;
}
/*
void SendFrequency()//AFP 09-24-23 V12
{
Clk0SetFreq = ((centerFreq * SI5351_FREQ_MULT) + IFFreq * SI5351_FREQ_MULT) * MASTER_CLK_MULT;
Clk1SetFreq = ((centerFreq * SI5351_FREQ_MULT) + IFFreq * SI5351_FREQ_MULT) * MASTER_CLK_MULT; //v12
Clk2SetFreq = ((centerFreq * SI5351_FREQ_MULT) + IFFreq * SI5351_FREQ_MULT) * MASTER_CLK_MULT; //v12
long freq1=Clk0SetFreq;
si5351.set_freq_manual(freq1 * SI5351_FREQ_MULT, Even_Divisor * freq1 * SI5351_FREQ_MULT, SI5351_CLK0);
si5351.set_freq_manual(freq1 * SI5351_FREQ_MULT, Even_Divisor * freq1 * SI5351_FREQ_MULT, SI5351_CLK1);
si5351.set_phase(SI5351_CLK0, 0);
si5351.set_phase(SI5351_CLK1, Even_Divisor);
if (Even_Divisor != oldEven_Divisor)
{
si5351.pll_reset(SI5351_PLLA);
oldEven_Divisor = Even_Divisor;
}
}
*/
/*****
Purpose: A special variant of SetFreq() used only for calibration.
Parameter list:
void
Return value;
void
CAUTION: SI5351_FREQ_MULT is set in the si5253.h header file and is 100UL
*****/
void SetFreqCal(void) { // July 7 2023 KF5N
}
/***** //AFP 10-11-22 all new
Purpose: Reset tuning to center
Parameter list:
void
Return value;
void
*****/
void ResetTuning() {
//centerFreq = TxRxFreq;
currentFreq = centerFreq + NCOFreq; // Changed currentFreqA to currentFreq. KF5N August 5, 2023
NCOFreq = 0L;
centerFreq = TxRxFreq = currentFreq; // Changed currentFreqA to currentFreq. KF5N August 5, 2023
tft.writeTo(L2); // Clear layer 2. KF5N July 31, 2023
tft.clearMemory();
SetFreq(); // For new tuning scheme. KF5N July 22, 2023
DrawBandWidthIndicatorBar();
BandInformation();
ShowFrequency();
//centerTuneFlag = 1; Not necessary with new tuning scheme. KF5N July 22, 2023
}
// ===== End AFP 10-11-22
/*****
Purpose: SetFrequency
Parameter list:
void
Return value;
void
CAUTION: SI5351_FREQ_MULT is set in the si5253.h header file and is 100UL
*****/
void SetFreq() { //AFP 09-24-23 V12
#ifdef G0ORX_FRONTPANEL
__disable_irq();
#endif
// The receive LO frequency is not dependent on mode or sideband. CW frequency shift is done in DSP code.
if (radioState == SSB_RECEIVE_STATE || radioState == CW_RECEIVE_STATE) { // Receive state
Clk1SetFreq = ((TxRxFreq * SI5351_FREQ_MULT) + IFFreq * SI5351_FREQ_MULT);
multiple = EvenDivisor(Clk1SetFreq / SI5351_FREQ_MULT);
pll_freq = Clk1SetFreq * multiple;
freq = pll_freq / multiple;
si5351.output_enable(SI5351_CLK0, 1);
si5351.output_enable(SI5351_CLK1, 1);
si5351.output_enable(SI5351_CLK2, 0);
si5351.set_freq_manual(freq, pll_freq, SI5351_CLK0);
si5351.set_freq_manual(freq, pll_freq, SI5351_CLK1);
si5351.set_phase(SI5351_CLK0, 0);
si5351.set_phase(SI5351_CLK1, multiple);
if (multiple != oldMultiple) {
si5351.pll_reset(SI5351_PLLA);
si5351.pll_reset(SI5351_PLLB);
#ifndef G0ORX_CAT
Serial.println("Reset");
#endif
}
oldMultiple = multiple;
} else {
if (radioState == SSB_TRANSMIT_STATE) { // SSB Transmit state: No IF shift
Clk1SetFreq = ((TxRxFreq * SI5351_FREQ_MULT));
multiple = EvenDivisor(Clk1SetFreq / SI5351_FREQ_MULT);
pll_freq = Clk1SetFreq * multiple;
freq = pll_freq / multiple;
si5351.output_enable(SI5351_CLK0, 1);
si5351.output_enable(SI5351_CLK1, 1);
si5351.output_enable(SI5351_CLK2, 0);
si5351.set_freq_manual(Clk1SetFreq, pll_freq, SI5351_CLK0);
si5351.set_freq_manual(Clk1SetFreq, pll_freq, SI5351_CLK1);
si5351.set_phase(SI5351_CLK0, 0);
si5351.set_phase(SI5351_CLK1, multiple);
if (multiple != oldMultiple) {
si5351.pll_reset(SI5351_PLLA);
si5351.pll_reset(SI5351_PLLB);
Serial.println("Reset");
}
oldMultiple = multiple;
}
}
#ifdef G0ORX_FRONTPANEL
__enable_irq();
#endif
//si5351.output_enable(SI5351_CLK2, 0);
/*
#ifndef G0ORX_CAT
Serial.print("centerFreq=");
Serial.println(centerFreq);
Serial.print("Clk1SetFreq=");
Serial.println(Clk1SetFreq);
Serial.print("freq=");
Serial.println(freq);
Serial.print("pll_freq=");
Serial.println(pll_freq);
Serial.print("multiple=");
Serial.println(multiple);
#endif
*/
DrawFrequencyBarValue();
}
/*****
Purpose: Places the Fast Tune cursor in the center of the spectrum display
Parameter list:
Return value;
void
*****/
void CenterFastTune() {
tft.drawFastVLine(oldCursorPosition, SPECTRUM_TOP_Y + 20, SPECTRUM_HEIGHT - 27, RA8875_BLACK);
tft.drawFastVLine(newCursorPosition, SPECTRUM_TOP_Y + 20, SPECTRUM_HEIGHT - 27, RA8875_RED);
}
/*****
Purpose: Purpose is to sety VFOa to receive frequency and VFOb to the transmit frequency
Parameter list:
void
Return value;
int the offset as an int
CAUTION: SI5351_FREQ_MULT is set in the si5253.h header file and is 100UL
*****/
int DoSplitVFO() {
char freqBuffer[15];
int val;
long chunk = SPLIT_INCREMENT;
long splitOffset;
tft.drawRect(INFORMATION_WINDOW_X - 10, INFORMATION_WINDOW_Y - 2, 260, 200, RA8875_MAGENTA);
tft.fillRect(INFORMATION_WINDOW_X - 8, INFORMATION_WINDOW_Y, 250, 185, RA8875_BLACK); // Clear volume field
tft.setFontScale((enum RA8875tsize)1);
tft.setCursor(INFORMATION_WINDOW_X + 10, INFORMATION_WINDOW_Y + 5);
tft.print("xmit offset: ");
splitOffset = chunk; // Set starting offset to 500Hz
tft.setTextColor(RA8875_GREEN);
tft.setCursor(INFORMATION_WINDOW_X + 60, INFORMATION_WINDOW_Y + 90);
tft.print(splitOffset);
tft.print("Hz ");
while (true) {
if (filterEncoderMove != 0) { // Changed encoder?
splitOffset += filterEncoderMove * chunk;
tft.fillRect(INFORMATION_WINDOW_X + 60, INFORMATION_WINDOW_Y + 90, 150, 50, RA8875_BLACK);
tft.setCursor(INFORMATION_WINDOW_X + 60, INFORMATION_WINDOW_Y + 90);
tft.print(splitOffset);
tft.print("Hz ");
}
filterEncoderMove = 0L;
val = ReadSelectedPushButton(); // Read pin that controls all switches
val = ProcessButtonPress(val);
MyDelay(150L);
if (val == MENU_OPTION_SELECT) { // Make a choice??
Clk1SetFreq += splitOffset; // New transmit frequency // AFP 09-27-22
UpdateInfoWindow();
filterEncoderMove = 0L;
break;
}
}
currentFreqB = currentFreqA + splitOffset;
FormatFrequency(currentFreqB, freqBuffer);
tft.fillRect(FREQUENCY_X_SPLIT, FREQUENCY_Y - 12, VFOB_PIXEL_LENGTH, FREQUENCY_PIXEL_HI, RA8875_BLACK);
tft.setCursor(FREQUENCY_X_SPLIT, FREQUENCY_Y);
tft.setFont(&FreeMonoBold24pt7b);
tft.setTextColor(RA8875_GREEN);
tft.print(freqBuffer); // Show VFO_A
tft.setFont(&FreeMonoBold18pt7b);
FormatFrequency(currentFreqA, freqBuffer);
tft.setTextColor(RA8875_LIGHT_GREY);
tft.setCursor(FREQUENCY_X, FREQUENCY_Y + 6);
tft.print(freqBuffer); // Show VFO_A
tft.useLayers(1); //mainly used to turn on layers!
tft.layerEffect(OR);
tft.writeTo(L2);
tft.clearMemory();
tft.writeTo(L1);
tft.setFont(&FreeMono9pt7b);
tft.setTextColor(RA8875_RED);
tft.setCursor(FILTER_PARAMETERS_X + 180, FILTER_PARAMETERS_Y + 6);
tft.print("Split Active");
tft.setFontDefault();
return (int)splitOffset; // Can be +/-
}
#else
/*****
Purpose: A special variant of SetFreq() used only for calibration.
Parameter list:
void
Return value;
void
CAUTION: SI5351_FREQ_MULT is set in the si5253.h header file and is 100UL
*****/
void SetFreqCal(void)
{ // July 7 2023 KF5N
// NEVER USE AUDIONOINTERRUPTS HERE: that introduces annoying clicking noise with every frequency change
// SI5351_FREQ_MULT is 100ULL, MASTER_CLK_MULT is 4;
// The SSB LO frequency is always the same as the displayed transmit frequency.
// The CW LOT frequency must be shifted by 750 Hz due to the way the CW carrier is generated by a quadrature tone.
if (bands[currentBand].mode == DEMOD_LSB)
Clk1SetFreq = (((TxRxFreq + CWFreqShift + calFreqShift) * SI5351_FREQ_MULT)) * MASTER_CLK_MULT; // AFP 09-27-22; KF5N flip CWFreqShift, sign originally minus
if (bands[currentBand].mode == DEMOD_USB)
Clk1SetFreq = (((TxRxFreq - CWFreqShift - calFreqShift) * SI5351_FREQ_MULT)) * MASTER_CLK_MULT; // AFP 10-01-22; KF5N flip CWFreqShift, sign originally plus
// The receive LO frequency is not dependent on mode or sideband. CW frequency shift is done in DSP code.
Clk2SetFreq = ((centerFreq * SI5351_FREQ_MULT) + IFFreq * SI5351_FREQ_MULT) * MASTER_CLK_MULT;
// Set and enable both RX and TX local oscillator outputs.
si5351.set_freq(Clk2SetFreq, SI5351_CLK2);
si5351.set_freq(Clk1SetFreq, SI5351_CLK1);
si5351.output_enable(SI5351_CLK2, 1);
si5351.output_enable(SI5351_CLK1, 1);
}
/***** //AFP 10-11-22 all new
Purpose: Reset tuning to center
Parameter list:
void
Return value;
void
*****/
void ResetTuning()
{
currentFreq = centerFreq + NCOFreq; // currentFreqA changed to currentFreq. KF5N August 7, 2023
NCOFreq = 0L;
centerFreq = TxRxFreq = currentFreq ; //AFP 10-28-22 // currentFreqA changed to currentFreq. KF5N August 7, 2023
tft.writeTo(L2); // Clear layer 2. KF5N July 31, 2023
tft.clearMemory();
SetFreq(); // For new tuning scheme. KF5N July 22, 2023
DrawBandWidthIndicatorBar();
BandInformation();
ShowFrequency();
//centerTuneFlag = 1; Not necessary with new tuning scheme. KF5N July 22, 2023
}
// ===== End AFP 10-11-22
/*****
Purpose: SetFrequency
Parameter list:
void
Return value;
void
CAUTION: SI5351_FREQ_MULT is set in the si5253.h header file and is 100UL
*****/
void SetFreq() { //AFP 09-22-22 Revised July 7 KF5N
// NEVER USE AUDIONOINTERRUPTS HERE: that introduces annoying clicking noise with every frequency change
// SI5351_FREQ_MULT is 100ULL, MASTER_CLK_MULT is 4;
// The SSB LO frequency is always the same as the displayed transmit frequency.
// The CW LOT frequency must be shifted by 750 Hz due to the way the CW carrier is generated by a quadrature tone.
if (radioState == SSB_TRANSMIT_STATE) {
Clk1SetFreq = (TxRxFreq * SI5351_FREQ_MULT) * MASTER_CLK_MULT; // AFP 09-27-22
} else if (radioState == CW_TRANSMIT_STRAIGHT_STATE || radioState == CW_TRANSMIT_KEYER_STATE) {
if (bands[currentBand].mode == DEMOD_LSB) {
Clk1SetFreq = (((TxRxFreq + CWFreqShift + calFreqShift) * SI5351_FREQ_MULT)) * MASTER_CLK_MULT; // AFP 09-27-22; KF5N flip CWFreqShift, sign originally minus
} else {
if (bands[currentBand].mode == DEMOD_USB) {
Clk1SetFreq = (((TxRxFreq - CWFreqShift - calFreqShift) * SI5351_FREQ_MULT)) * MASTER_CLK_MULT; // AFP 10-01-22; KF5N flip CWFreqShift, sign originally plus
}
}
}
// The receive LO frequency is not dependent on mode or sideband. CW frequency shift is done in DSP code.
Clk2SetFreq = ((centerFreq * SI5351_FREQ_MULT) + IFFreq * SI5351_FREQ_MULT) * MASTER_CLK_MULT;
if (radioState == SSB_RECEIVE_STATE || radioState == CW_RECEIVE_STATE) { // Receive state
si5351.set_freq(Clk2SetFreq, SI5351_CLK2);
si5351.output_enable(SI5351_CLK1, 0); // CLK1 (transmit) off during receive to prevent birdies
si5351.output_enable(SI5351_CLK2, 1);
}
if (radioState == SSB_TRANSMIT_STATE || radioState == CW_TRANSMIT_STRAIGHT_STATE || radioState == CW_TRANSMIT_KEYER_STATE) { // Transmit state
si5351.set_freq(Clk1SetFreq, SI5351_CLK1);
si5351.output_enable(SI5351_CLK2, 0); // CLK2 (receive) off during transmit to prevent spurious outputs
si5351.output_enable(SI5351_CLK1, 1);
}
//===================== AFP 10-03-22 =================
DrawFrequencyBarValue();
}
/*****
Purpose: Places the Fast Tune cursor in the center of the spectrum display
Parameter list:
Return value;
void
*****/
void CenterFastTune()
{
tft.drawFastVLine(oldCursorPosition, SPECTRUM_TOP_Y + 20, SPECTRUM_HEIGHT - 27, RA8875_BLACK);
tft.drawFastVLine(newCursorPosition , SPECTRUM_TOP_Y + 20, SPECTRUM_HEIGHT - 27, RA8875_RED);
}
/*****
Purpose: Purpose is to sety VFOa to receive frequency and VFOb to the transmit frequency
Parameter list:
void
Return value;
int the offset as an int
CAUTION: SI5351_FREQ_MULT is set in the si5253.h header file and is 100UL
*****/
int DoSplitVFO()
{
char freqBuffer[15];
int val;
long chunk = SPLIT_INCREMENT;
long splitOffset;
tft.drawRect(INFORMATION_WINDOW_X - 10, INFORMATION_WINDOW_Y - 2, 260, 200, RA8875_MAGENTA);
tft.fillRect(INFORMATION_WINDOW_X - 8, INFORMATION_WINDOW_Y, 250, 185, RA8875_BLACK); // Clear volume field
tft.setFontScale( (enum RA8875tsize) 1);
tft.setCursor(INFORMATION_WINDOW_X + 10, INFORMATION_WINDOW_Y + 5);
tft.print("xmit offset: ");
splitOffset = chunk; // Set starting offset to 500Hz
tft.setTextColor(RA8875_GREEN);
tft.setCursor(INFORMATION_WINDOW_X + 60, INFORMATION_WINDOW_Y + 90);
tft.print(splitOffset);
tft.print("Hz ");
#ifdef G0ORX_FRONTPANEL_2
calibrateFlag=1;
#endif
while (true) {
if (filterEncoderMove != 0) { // Changed encoder?
splitOffset += filterEncoderMove * chunk;
tft.fillRect(INFORMATION_WINDOW_X + 60, INFORMATION_WINDOW_Y + 90, 150, 50, RA8875_BLACK);
tft.setCursor(INFORMATION_WINDOW_X + 60, INFORMATION_WINDOW_Y + 90);
tft.print(splitOffset);
tft.print("Hz ");
}
filterEncoderMove = 0L;
val = ReadSelectedPushButton(); // Read pin that controls all switches
val = ProcessButtonPress(val);
MyDelay(150L);
if (val == MENU_OPTION_SELECT) { // Make a choice??
Clk1SetFreq += splitOffset; // New transmit frequency // AFP 09-27-22
UpdateInfoWindow();
filterEncoderMove = 0L;
break;
}
}
#ifdef G0ORX_FRONTPANEL_2
calibrateFlag=0;
#endif
currentFreqB = currentFreqA + splitOffset;
FormatFrequency(currentFreqB, freqBuffer);
tft.fillRect(FREQUENCY_X_SPLIT, FREQUENCY_Y - 12, VFOB_PIXEL_LENGTH, FREQUENCY_PIXEL_HI, RA8875_BLACK);
tft.setCursor(FREQUENCY_X_SPLIT, FREQUENCY_Y);
tft.setFont(&FreeMonoBold24pt7b);
tft.setTextColor(RA8875_GREEN);
tft.print(freqBuffer); // Show VFO_A
tft.setFont(&FreeMonoBold18pt7b);
FormatFrequency(currentFreqA, freqBuffer);
tft.setTextColor(RA8875_LIGHT_GREY);
tft.setCursor(FREQUENCY_X, FREQUENCY_Y + 6);
tft.print(freqBuffer); // Show VFO_A
tft.useLayers(1); //mainly used to turn on layers!
tft.layerEffect(OR);
tft.writeTo(L2);
tft.clearMemory();
tft.writeTo(L1);
tft.setFont(&FreeMono9pt7b);
tft.setTextColor(RA8875_RED);
tft.setCursor(FILTER_PARAMETERS_X + 180, FILTER_PARAMETERS_Y + 6);
tft.print("Split Active");
tft.setFontDefault();
return (int) splitOffset; // Can be +/-
}
#endif