-
Notifications
You must be signed in to change notification settings - Fork 0
/
Oberon.ino
867 lines (686 loc) · 33.3 KB
/
Oberon.ino
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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
/*
Oberon.ino - QRSS (slow speed CW) Beacon for PicoBallon using Si5351a and ATTINY85
Oberon is the mythical king of the fairies who appears as a character in William Shakespeare's play "A Midsummer Nights Dream".
This code was written during Midsummer of 2020 for project SPRiTE, so the name seemed appropriate.
SPRiTE (not the soft drink) stands for "Small, Propagation Research Transmitting Experiment". The idea is to build an ultra-lite
solar-powered QRSS beacon transmitter using an ATTINY85 processor controlling an Si5351a clock chip.
The majority of this code is derived from the QRSS/FSKCW/DFCW Beacon Keyer by Hans Summers, G0UPL(copyright 2012)
and used with his permission for this derivitive work. The original source code is from here :
https://qrp-labs.com/images/qrssarduino/qrss.ino
It was adapted by Michael, VE3WMB to use the Si5351a as a transmitter for Orion WSPR Beacon and ported to ATTINY85 for the
Sprite QRSS PicoBallon Project.
This code also uses some public domain Si5351a code written by Jerry Gaffke, KE7ER.
The transmit_glyph()function was provided by Graham, VE3GTC and modified slightly to fit our needs.
The orignal authors of various pieces of code used retain the rights to their own code. All new code is
Copyright (C) 2020 Michael Babineau <mbabineau.ve3wmb@gmail.com>
This code is targetted at an ATTINY85 with Arduino Bootloader installed and a Si5351a breakout board.
The communication between the two is via I2C using the Adafruit TinyWireM.h library. This code can also run
on other Arduinos such as the UNO and it will also support Software I2C (via SoftWire.h) to run on QRP Labs U3S clones.
How to configure
----------------
The software uses conditional compilation based on the OberonConfig.h parameters below to allow for optionality and reduce
code size.
For ATTINY85 :
#define TARGET_PROCESSOR_ATTINY85
For Arduino UNO/Nano etc :
//#define TARGET_PROCESSOR_ATTINY85 (will assume ATMEGA328p and H/W debugSerial and hardware I2C communication with Si5351a)
For U3S Clones uiing ATMEGA328p
//#define TARGET_PROCESSOR_ATTINY85
#define SI5351A_USES_SOFTWARE_I2C
In all cases #define OBERON_DEBUG_MODE will enable serialDebug, however debugSerial is not currently supported on the ATTINY85.
When #define OBERON_DEBUG_MODE is commented out the debug logging code becomes do-nothing code stubbs.
Required Libraries
------------------
Time (Library Manager) https://github.com/PaulStoffregen/Time - This provides a Unix-like System Time capability, only required if OBERON_DEBUG_MODE is defined.
SoftI2CMaster (Software I2C with SoftWire wrapper) https://github.com/felias-fogg/SoftI2CMaster/blob/master/SoftI2CMaster.h - Used if SI5351A_USES_SOFTWARE_I2C defined
NeoSWSerial (https://github.com/SlashDevin/NeoSWSerial) - Used for debugSerial if TARGET_PROCESSOR_ATTINY85 is defined.
Licensing
---------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "OberonConfig.h"
#define OBERON_CODE_VERSION "v0.06"
// We use TInyWireM.h for ATTINY85,the standard Wire.h for most others and Softwire.h
// for boards like the U3S and clones that don't use hardware I2C (SDA/SCL)
// The following uses conditional compilation to pick the correct libraries to include.
#if defined (SI5351A_USES_SOFTWARE_I2C) & !defined(TARGET_PROCESSOR_ATTINY85) // Assume this is for ATMEGA328p only
#include <SoftWire.h> // Needed for Software I2C on ATMEG328p otherwise include <Wire.h>
#else
#if defined (TARGET_PROCESSOR_ATTINY85) // Using ATTINY85 processor so we need TinyWireM
#include <TinyWireM.h> // Instead of Softwire or Wire
#define Wire TinyWireM // Replace all instances of Wire with TinyWireM so we don't have to modify I2C code
#else
#include <Wire.h> // Default to the standard Wire library
#endif
#endif
// debugSerial does not currently support ATTINY85
#if defined (OBERON_DEBUG_MODE) // We are using debug serial
#include <TimeLib.h> // We need this for timestamps
/*
#if defined (TARGET_PROCESSOR_ATTINY85) | defined (DEBUG_USES_SW_SERIAL)
#include <NeoSWSerial.h> // For ATTINY85 we must use Software Serial for debug
NeoSWSerial debugSerial(SOFT_SERIAL_RX_PIN,SOFT_SERIAL_TX_PIN); // RX, TX
#else
#define debugSerial Serial // Not ATTINY85 so use HW serial
#endif
*/
#if defined (DEBUG_USES_SW_SERIAL)
#include <NeoSWSerial.h>
NeoSWSerial debugSerial(SOFT_SERIAL_RX_PIN, SOFT_SERIAL_TX_PIN); // RX, TX
#else
#define debugSerial Serial // Not ATTINY85 so use HW serial
#endif
#endif
// Glyph timing parameters
#define GLYPH_SYMBOL_TIME 200 // in milliseconds 300
#define GLYPH_CHARACTER_SPACE 1200 // in milliseconds
#define GLYPH_TONE_SPACING 300 // 100 = 1 hz in 100'ths of hertz 300 or 220
#define GLYPH_TRANSMIT_OFFSET 100 // in hertz
/***************************************
SI5351a definitions and macros
****************************************/
uint64_t si5351bx_vcoa = (SI5351BX_XTAL*SI5351BX_MSA); // 25mhzXtal calibrate
int32_t si5351_correction = SI5351A_CLK_FREQ_CORRECTION; //Frequency correction factor
uint8_t si5351bx_rdiv = 0; // 0-7, CLK pin sees fout/(2**rdiv) // Note that 0 means divide by 1
uint8_t si5351bx_drive[3] = {3, 3, 3}; // 0=2ma 1=4ma 2=6ma 3=8ma for CLK 0,1,2 - Set CLK 0,1,2 to 8ma
uint8_t si5351bx_clken = 0xFF; // Private, all CLK output drivers off
uint64_t g_beacon_tx_frequency_hz; // This is used qrss_beacon() so that we can have a different frequency for regular CW vs QRSS Xmissions
// Macros used by the KE7ER Si5351 Code
#define BB0(x) ((uint8_t)x) // Bust int32 into Bytes
#define BB1(x) ((uint8_t)(x>>8))
#define BB2(x) ((uint8_t)(x>>16))
#define RFRAC_DENOM 1000000ULL
#define SI5351_CLK_ON true
#define SI5351_CLK_OFF false
// Si5351a forward definitions
// Turn the specified clock number on or off.
void si5351bx_enable_clk(uint8_t clk_num, bool on_off);
// Initialize the Si5351
void si5351bx_init();
// Set the frequency for the specified clock number
// Note that fout is in hertz x 100 (i.e. hundredths of hertz).
// Frequency range must be between 500 Khz and 109 Mhz
// Boolean tx_on specifies whether clock is enabled after frequency
// change.
void si5351bx_setfreq(uint8_t clknum, uint64_t fout, bool tx_on);
// Forward definitions for QRSS Beacon code
enum QrssMode {MODE_NONE, MODE_QRSS, MODE_FSKCW, MODE_DFCW};
enum QrssSpeed {s12wpm, QRSS3, QRSS6, QRSS10};
const char msg[] = QRSS_MESSAGE;
const char msg2[] = CW_BEACON_MESSAGE;
// This array is indexed by a parameter of type QrssSpeed
const unsigned int speeds[] = {1, 30, 60, 100}; // Speeds for: s12wpm, QRSS3, QRSS6, QRSS10
void qrss_beacon(QrssMode mode, QrssSpeed speed);
// Create an instance of Softwire named Wire if using Software I2C
#if defined (SI5351A_USES_SOFTWARE_I2C)
SoftWire Wire = SoftWire();
#endif// Create an instance of Softwire named Wire if using Software I2C
char *g_tx_msg_ptr = 0;
// Debug logging
enum debugLogType {STARTUP, GLYPH_TX, GLYPH_TX_STOP, QRSS_TX, QRSS_TX_STOP, WAIT};
void debugLog( debugLogType type, QrssMode mode, QrssSpeed speed);
/** ************* SI5315 routines - (tks Jerry Gaffke, KE7ER) ***********************
A minimalist standalone set of Si5351 routines originally written by Jerry Gaffke, KE7ER
but modified by VE3WMB for use with Software I2C and to provide sub-Hz resolution for WSPR
transmissions.
VCOA is fixed at 875mhz, VCOB not used.
The output msynth dividers are used to generate 3 independent clocks
with 1hz resolution to any frequency between 4khz and 109mhz.
Usage:
Call si5351bx_init() once at startup with no args;
Call si5351bx_setfreq(clknum, freq, tx_on) each time one of the
three output CLK pins is to be updated to a new frequency.
The bool tx_on determines whether the clock is enabled after the
frequency change.
A freq of 0 also serves to shut down that output clock or alternately a
call to si5351bx_enable_clk(uint8_t clk_num, bool on_off)
The global variable si5351bx_vcoa starts out equal to the nominal VCOA
frequency of 25mhz*35 = 875000000 Hz. To correct for 25mhz crystal errors,
the user can adjust this value. The vco frequency will not change but
the number used for the (a+b/c) output msynth calculations is affected.
Example: We call for a 5mhz signal, but it measures to be 5.001mhz.
So the actual vcoa frequency is 875mhz*5.001/5.000 = 875175000 Hz,
To correct for this error: si5351bx_vcoa=875175000;
Most users will never need to generate clocks below 500khz.
But it is possible to do so by loading a value between 0 and 7 into
the global variable si5351bx_rdiv, be sure to return it to a value of 0
before setting some other CLK output pin. The affected clock will be
divided down by a power of two defined by 2**si5351_rdiv
A value of zero gives a divide factor of 1, a value of 7 divides by 128.
This lightweight method is a reasonable compromise for a seldom used feature.
*/
// Write a single 8 bit value to an Si5351a register address
void i2cWrite(uint8_t reg, uint8_t val) { // write reg via i2c
Wire.beginTransmission(SI5351BX_ADDR);
Wire.write(reg);
Wire.write(val);
Wire.endTransmission();
}
// Write an array of 8bit values to an Si5351a register address
void i2cWriten(uint8_t reg, uint8_t *vals, uint8_t vcnt) { // write array
Wire.beginTransmission(SI5351BX_ADDR);
Wire.write(reg);
while (vcnt--) Wire.write(*vals++);
Wire.endTransmission();
}
// Turn the specified clock number on or off.
void si5351bx_enable_clk(uint8_t clk_num, bool on_off) {
if (on_off == SI5351_CLK_OFF ) { // Off Disable ClK
si5351bx_clken |= 1 << clk_num; // Set Bit to shut down the clock
}
else { // Enable CLK
si5351bx_clken &= ~(1 << clk_num); // Clear bit to enable clock
}
i2cWrite(3, si5351bx_clken);
}
// Initialize the Si5351a
void si5351bx_init() { // Call once at power-up, start PLLA
uint8_t reg; uint32_t msxp1;
Wire.begin();
i2cWrite(149, 0); // SpreadSpectrum off
i2cWrite(3, si5351bx_clken); // Disable all CLK output drivers
i2cWrite(183, ((SI5351BX_XTALPF << 6) | 0x12)); // Set 25mhz crystal load capacitance (tks Daniel KB3MUN)
msxp1 = 128 * SI5351BX_MSA - 512; // and msxp2=0, msxp3=1, not fractional
uint8_t vals[8] = {0, 1, BB2(msxp1), BB1(msxp1), BB0(msxp1), 0, 0, 0};
i2cWriten(26, vals, 8); // Write to 8 PLLA msynth regs
i2cWrite(177, 0x20); // Reset PLLA (0x80 resets PLLB)
}
// Set the frequency for the specified clock number
// Note that fout is in hertz x 100 (i.e. hundredths of hertz).
// Frequency range must be between 500 Khz and 109 Mhz
// An fout value of 0 will shutdown the specified clock.
void si5351bx_setfreq(uint8_t clknum, uint64_t fout, bool tx_on)
{
// Note that I am not being lazy here in naming variables. If you refer to SiLabs
// application note AN619 - "Manually Generating an Si5351 Register Map", the formulas
// within refer to calculating values named a,b,c and p1, p2, p3.
// For consistency I continue to use the same notation, even though the calculations appear
// a bit cryptic.
uint64_t a, b, c, ref_freq;
uint32_t p1, p2, p3;
uint8_t vals[8];
if ((fout < 50000000) || (fout > 10900000000)) { // If clock freq out of range 500 Khz to 109 Mhz
si5351bx_clken |= 1 << clknum; // shut down the clock
i2cWrite(3, si5351bx_clken);
}
else {
// Determine the integer part of feedback equation
ref_freq = si5351bx_vcoa;
ref_freq = ref_freq + (int32_t)((((((int64_t)si5351_correction) << 31) / 1000000000LL) * ref_freq) >> 31);
a = ref_freq / fout;
b = (ref_freq % fout * RFRAC_DENOM) / fout;
c = b ? RFRAC_DENOM : 1;
p1 = 128 * a + ((128 * b) / c) - 512;
p2 = 128 * b - c * ((128 * b) / c);
p3 = c;
// Setup the bytes to be sent to the Si5351a register
vals[0] = (p3 & 0x0000FF00) >> 8;
vals[1] = p3 & 0x000000FF;
vals[2] = (p1 & 0x00030000) >> 16;
vals[3] = (p1 & 0x0000FF00) >> 8;
vals[4] = p1 & 0x000000FF;
vals[5] = (((p3 & 0x000F0000) >> 12) | ((p2 & 0x000F0000) >> 16));
vals[6] = (p2 & 0x0000FF00) >> 8;
vals[7] = p2 & 0x000000FF;
i2cWriten(42 + (clknum * 8), vals, 8); // Write to 8 msynth regs
i2cWrite(16 + clknum, 0x0C | si5351bx_drive[clknum]); // use local msynth
if (tx_on == true)
si5351bx_clken &= ~(1 << clknum); // Clear bit to enable clock
else
si5351bx_clken |= 1 << clknum; // Set bit to shut down the clock
i2cWrite(3, si5351bx_clken); // Enable/disable clock
}
}
byte charCode(char c) {
// This function returns the encoded CW pattern for the character passed in.
// Binary encoding is left-padded. Unused high-order bits are all ones.
// The first zero is the start bit, which is discarded.
// Processing from higher to lower order, bits we skip over ones, then discard first 0 (start bit). The next bit is the first element.
// We process each element sending a DIT or DAH, until we reach the end of the pattern.
//
// Pattern encoding is 0 = DIT, 1 = DAH.
// So 'A' = B11111001, which is 1 1 1 1 1 (padding bits) 0 (start bit) 0 1 (dit, dah)
// This excellent encoding scheme was developed by Hans, G0UPL as noted above.
switch (c)
{
case 'A': return B11111001; break; // A .-
case 'B': return B11101000; break; // B -...
case 'C': return B11101010; break; // C -.-.
case 'D': return B11110100; break; // D -..
case 'E': return B11111100; break; // E .
case 'F': return B11100010; break; // F ..-.
case 'G': return B11110110; break; // G --.
case 'H': return B11100000; break; // H ....
case 'I': return B11111000; break; // I ..
case 'J': return B11100111; break; // J .---
case 'K': return B11110101; break; // K -.-
case 'L': return B11100100; break; // L .-..
case 'M': return B11111011; break; // M --
case 'N': return B11111010; break; // N -.
case 'O': return B11110111; break; // O ---
case 'P': return B11100110; break; // P .--.
case 'Q': return B11101101; break; // Q --.-
case 'R': return B11110010; break; // R .-.
case 'S': return B11110000; break; // S ...
case 'T': return B11111101; break; // T -
case 'U': return B11110001; break; // U ..-
case 'V': return B11100001; break; // V ...-
case 'W': return B11110011; break; // W .--
case 'X': return B11101001; break; // X -..-
case 'Y': return B11101011; break; // Y -.--
case 'Z': return B11101100; break; // Z --..
case '0': return B11011111; break; // 0 -----
case '1': return B11001111; break; // 1 .----
case '2': return B11000111; break; // 2 ..---
case '3': return B11000011; break; // 3 ...--
case '4': return B11000001; break; // 4 ....-
case '5': return B11000000; break; // 5 .....
case '6': return B11010000; break; // 6 -....
case '7': return B11011000; break; // 7 --...
case '8': return B11011100; break; // 8 ---..
case '9': return B11011110; break; // 9 ----.
case ' ': return B11101111; break; // Space - equal to 4 dah lengths
case '/': return B11010010; break; // / -..-.
default: return charCode(' ');
}
}
void setRfFsk(boolean rf_on, boolean setFSK_high)
{
uint8_t fsk_value;
// Determine if there is an FSK shift and if so adjust the frequency
// accordingly before turning on the Si5351a clock.
if (setFSK_high == true) {
fsk_value = FSK_HIGH;
}
else {
fsk_value = FSK_LOW;
}
if (rf_on == true) {
si5351bx_setfreq(SI5351A_TX_CLK_NUM, ((g_beacon_tx_frequency_hz + fsk_value) * 100ULL), SI5351_CLK_ON );
}
else {
si5351bx_enable_clk(SI5351A_TX_CLK_NUM, SI5351_CLK_OFF); // Disable the TX clock
}
}
//
bool qrss_transmit(QrssMode mode, QrssSpeed ditSpeed)
{
static byte timerCounter; // Counter to get to divide by 100 to get 10Hz
static int ditCounter; // Counter to time the length of each dit
static byte pause; // Generates the pause between characters
static byte character; // Bit pattern for the character being sent
static byte key; // State of the key
static byte charBit; // Which bit of the bit pattern is being sent
static boolean dah; // True when a dah is being sent
byte divisor; // Divide 1kHz by 100 normally, but by 33 when sending DFCW)
bool transmission_done = false;
// Set Divisor based on Mode
if (mode == MODE_DFCW) // Divisor is 33 for DFCW, to get the correct timing
divisor = 33; // (inter-symbol gap is 1/3 of a dit)
else
divisor = 100; // For ever other mode it is one dit length
timerCounter++; // 1000Hz at this point
if (timerCounter == divisor) // Divides by 100 (or 33 for DFCW)
{
timerCounter = 0; // 10 Hz here (30Hz for DFCW)
ditCounter++; // Generates the correct dit-length
if (ditCounter >= speeds[ditSpeed]) { // We have counted the duration of a dit
ditCounter = 0;
if (!pause) {
// Pause is set to 2 after the last element of the character has been sent
key--; // This generates the correct pause between characters (3 dits)
if ((!key) && (!charBit)) {
if (mode == MODE_DFCW)
pause = 3; // DFCW needs an extra delay to make it 4/3 dit-length
else
pause = 2;
}
} // end if (!pause)
else
pause--;
// Key becomes 255 when the last element (dit or dah) of the character has been sent
if (key == 255) {
// Done sending the last element (dit or dah) in the character
// If the last symbol of the character has been sent, get the next character
if (!charBit) {
// Increment the message character pointer to point to the next character to be sent
g_tx_msg_ptr ++;
// If we are at the end of the message flag transmission_done
if (! (*g_tx_msg_ptr)) {
transmission_done = true;
}
else {
// Get the encoded bit pattern for the morse character
character = charCode(*g_tx_msg_ptr);
// Start at the 7'th (leftmost) bit of the bit pattern
charBit = 7;
// Loop through bits looking for a 0, signifying start of coding bits
while (character & (1 << charBit)) charBit--;
}
} // end if (!charBit)
charBit--; // Move to the next rightermost bit of the pattern, this is the first element
if ((transmission_done == true) || (character == charCode(' ') )) { // Special case for space
key = 0;
dah = false;
}
else {
// Get the state of the current bit in the pattern
key = character & (1 << charBit);
if (key) { // If it's a 1, set this to a dah
key = 3;
dah = true;
}
else { // otherwise it's a dit
if (mode == MODE_DFCW) // Special case for DFCW - dit's and dah's are both
key = 3; // the same length.
else
key = 1;
dah = false;
}
}
} // end if (key == 255 )
if (!key) dah = false;
//
if (mode == MODE_FSKCW)
{
// in FSK/CW mode, the RF output is always ON
// and the FSK depends on the key state
setRfFsk(true, key);
}
else if (mode == MODE_QRSS)
{
// in QRSS mode, the RF output is keyed
// and the FSK is always off
setRfFsk(key, false);
}
else if (mode == MODE_DFCW)
{
// in DFCW mode, the RF output is keyed (ON during a dit or a dah)
// and the FSK depends on the key state
setRfFsk(key, dah);
}
else
setRfFsk(false, false);
} // end if (ditcounter >= speeds[ditspeed];
} // end if (timercounter == divisor)
if (transmission_done == true) {
// reset the static variables for the next transmission
timerCounter = 0;
ditCounter = 0;
pause = 0;
character = 0;
key = 0;
charBit = 0;
dah = false;
}
return transmission_done;
} // end qrss_transmit function
void qrss_beacon(QrssMode tx_mode, QrssSpeed tx_speed) {
static unsigned long milliPrev; // Static variable stores previous millisecond count
unsigned long milliNow;
bool done_transmission = false;
// Since we are using FSKCW, turn on the clock now to let it warm up, delay one second and then turn on TX
si5351bx_setfreq(SI5351A_TX_CLK_NUM, ((g_beacon_tx_frequency_hz) * 100ULL), SI5351_CLK_OFF );
delay(1000);
si5351bx_enable_clk(SI5351A_TX_CLK_NUM, SI5351_CLK_ON);
// Turn off the PARK clock
si5351bx_enable_clk(SI5351A_PARK_CLK_NUM, SI5351_CLK_OFF);
debugLog(QRSS_TX, tx_mode, tx_speed);
while (!done_transmission) {
milliNow = millis(); // Get millisecond counter value
if (milliNow != milliPrev) // If one millisecond has elapsed, call the beacon() function
{
milliPrev = milliNow;
done_transmission = qrss_transmit(tx_mode, tx_speed); // This gets called once per millisecond (i.e 1000 times per second)
}
} // end while (!done)
// Ensure that the Si5351a TX clock is shutdown
si5351bx_enable_clk(SI5351A_TX_CLK_NUM, SI5351_CLK_OFF);
// Re-enable the Park Clock
si5351bx_setfreq(SI5351A_PARK_CLK_NUM, (PARK_FREQ_HZ * 100ULL), SI5351_CLK_ON);
debugLog(QRSS_TX_STOP, tx_mode, tx_speed);
} // end qrss_beacon()
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Transmit GLYPH message
//
// This code is courtesy of Graham, VE3GTC.
//
// Each glyph character is defined as a set of pixels within a 5 column by 7 row matrix
//
// Each character is transmitted one pixel at a time starting with the character's left most column
// and least significant bit
//
// Each character is defined as five bytes each reprsenting one column of the transmitted glyph.
//
// For example: column1, column2, column3, column4, column5
//
// Within each of these bytes, bit 1 through bit 7 ( MSB ) is used where a 1 represents a pixel that is ON and 0 a pixel
// that is off. Note that bit 0 ( LSB ) is not used.
//
// As an example, the character C is defined as the five bytes 0x7C, 0x82, 0x82, 0x82, 0x44
//
// | b | b | b | b | b b b b b b
// | y | y | y | y | y y y y y y
// | t | t | t | t | t t t t t t
// | e | e | e | e | e e e e e e
// bit | 1 | 2 | 3 | 4 | 5 bit 1 2 3 4 5
// =========================== results in ==> ==================
// MSB 7 | 0 | 1 | 1 | 1 | 0 | MSB 7 * * *
// 6 | 1 | 0 | 0 | 0 | 1 | 6 * *
// 5 | 1 | 0 | 0 | 0 | 0 | 5 *
// 4 | 1 | 0 | 0 | 0 | 0 | 4 *
// 3 | 1 | 0 | 0 | 0 | 0 | 3 *
// 2 | 1 | 0 | 0 | 0 | 1 | 2 * *
// 1 | 0 | 1 | 1 | 1 | 0 | 1 * * *
// LSB 0 | 0 | 0 | 0 | 0 | 0 | LSB 0
//
// Each bit is offset upwards in frequency from the base transmit frequency.
//
// b b b b b
// y y y y y
// t t t t t
// e e e e e
// bit 1 2 3 4 5
// =================
// base frequency + ( 7 * tone spacing ) MSB 7 * * *
// base frequency + ( 6 * tone spacing ) 6 * *
// base frequency + ( 5 * tone spacing ) 5 *
// base frequency + ( 4 * tone spacing ) 4 *
// base frequency + ( 3 * tone spacing ) 3 *
// base frequency + ( 2 * tone spacing ) 2 * *
// base frequency + ( 1 * tone spacing ) 1 * * *
// LSB 0
//
// Character set:
//
// adapated from: http://www.banburyares.co.uk/TechGroup/Arduino/HELLSCHEIBER.pdf
// { 0x00, 0x00, 0x00, 0x00, 0x00, }, // <space>
// { 0x04, 0x08, 0x10, 0x20, 0x40, }, // 0 ZERO
// { 0x7C, 0x8A, 0x92, 0xA2, 0x7C, }, // / slash
// { 0x00, 0x42, 0xFE, 0x02, 0x00, }, // 1
// { 0x42, 0x86, 0x8A, 0x92, 0x62, }, // 2
// { 0x84, 0x82, 0xA2, 0xD2, 0x8C, }, // 3
// { 0x18, 0x28, 0x48, 0xFE, 0x08, }, // 4
// { 0xE4, 0xA2, 0xA2, 0xA2, 0x9C, }, // 5
// { 0x3C, 0x52, 0x92, 0x92, 0x0C, }, // 6
// { 0x80, 0x8E, 0x90, 0xA0, 0xC0, }, // 7
// { 0x6C, 0x92, 0x92, 0x92, 0x6C, }, // 8
// { 0x60, 0x92, 0x92, 0x94, 0x78, }, // 9
// { 0x7E, 0x88, 0x88, 0x88, 0x7E, }, // A
// { 0xFE, 0x92, 0x92, 0x92, 0x6C, }, // B
// { 0x7C, 0x82, 0x82, 0x82, 0x44, }, // C
// { 0xFE, 0x82, 0x82, 0x44, 0x38, }, // D
// { 0xFE, 0x92, 0x92, 0x92, 0x82, }, // E
// { 0xFE, 0x90, 0x90, 0x90, 0x80, }, // F
// { 0x7C, 0x82, 0x92, 0x92, 0x5E, }, // G
// { 0xFE, 0x10, 0x10, 0x10, 0xFE, }, // H
// { 0x00, 0x82, 0xFE, 0x82, 0x00, }, // I
// { 0x04, 0x02, 0x82, 0xFC, 0x80, }, // J
// { 0xFE, 0x10, 0x28, 0x44, 0x82, }, // K
// { 0xFE, 0x02, 0x02, 0x02, 0x02, }, // L
// { 0xFE, 0x40, 0x30, 0x40, 0xFE, }, // M
// { 0xFE, 0x20, 0x10, 0x08, 0xFE, }, // N
// { 0x7C, 0x82, 0x82, 0x82, 0x7C, }, // O
// { 0xFE, 0x90, 0x90, 0x90, 0x60, }, // P
// { 0x7C, 0x82, 0x8A, 0x84, 0x7A, }, // Q
// { 0xFE, 0x90, 0x98, 0x94, 0x62, }, // R
// { 0x62, 0x92, 0x92, 0x92, 0x8C, }, // S
// { 0x80, 0x80, 0xFE, 0x80, 0x80, }, // T
// { 0xFC, 0x02, 0x02, 0x02, 0xFC, }, // U
// { 0xF8, 0x04, 0x02, 0x04, 0xF8, }, // V
// { 0xFC, 0x02, 0x1C, 0x02, 0xFC, }, // W
// { 0xC6, 0x28, 0x10, 0x28, 0xC6,}, // X
// { 0xE0, 0x10, 0x0E, 0x10, 0xE0, }, // Y
// { 0x86, 0x8A, 0x92, 0xA2, 0xC2, }, // Z
// { 0xFE, 0x42, 0x10, 0x42, 0XFE }, // Dagal - Viking rune meaning hope/happiness (looks like "|><|" )
//
// Each character in the desired message is encoded in the glyph array rather tha search through a large predefined
// character for inividual characters in a message, this in the hopes of saving a bit of memory space so that this might
// be squeezed into an attiny85 microcontroller.
//
// For a six character message this would result in 6 x 5 = 30 bytes rather than 38 x 5 = 190 bytes.
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void transmit_glyph()
{
const uint16_t GLYPH_SymbolTime = GLYPH_SYMBOL_TIME;
const uint16_t GLYPH_ToneSpaceing = GLYPH_TONE_SPACING;
const uint16_t GLYPH_CharacterSpace = GLYPH_CHARACTER_SPACE;
unsigned long TransmitOffset;
unsigned long MEPT_Frequency;
unsigned long previous_millis;
byte glyphs[][5] = {
{ 0xF8, 0x04, 0x02, 0x04, 0xF8, } // V
};
TransmitOffset = GLYPH_TRANSMIT_OFFSET;
MEPT_Frequency = g_beacon_tx_frequency_hz;
si5351bx_setfreq( SI5351A_TX_CLK_NUM, MEPT_Frequency * 100, SI5351_CLK_OFF );
int row;
int column ;
int pixel;
debugLog(GLYPH_TX, 0 , 0);
for ( row = 0; row <= ( sizeof( glyphs ) / 5 - 1); row++ ) { // for each row in message glyphs[row][column]
for ( column = 0; column <= 4; column++ ) { // for each character pixel column glyphs[row][0] to [row][4]
for ( pixel = 1; pixel <= 7; pixel++ ) { // for each column bit from b1 to b7
if ( bitRead(glyphs[row][column], pixel ) == 1 ) { // pixel ON
si5351bx_setfreq( SI5351A_TX_CLK_NUM, ( MEPT_Frequency * 100 ) + ( pixel * GLYPH_ToneSpaceing ), SI5351_CLK_ON );
previous_millis = millis();
while ( millis() - previous_millis < GLYPH_SymbolTime ) {
// just loop til done!
}
// si5351.output_enable(SI5351_CLK0, TX_OFF);
si5351bx_enable_clk( SI5351A_TX_CLK_NUM, SI5351_CLK_OFF );
} else { // pixel OFF
previous_millis = millis();
while ( millis() - previous_millis < GLYPH_SymbolTime ) {
// just loop til done!
}
}
}
}
previous_millis = millis();
while ( millis() - previous_millis < GLYPH_CharacterSpace ) {
// just loop til done!
}
}
si5351bx_enable_clk( SI5351A_TX_CLK_NUM, SI5351_CLK_OFF );
debugLog(GLYPH_TX_STOP, 0 , 0);
}
// Debug Serial code conditionally compiled
#if defined (OBERON_DEBUG_MODE)
void print_date_time() {
debugSerial.print(year());
debugSerial.print(F("-"));
debugSerial.print(month());
debugSerial.print(F("-"));
debugSerial.print(day());
debugSerial.print(F(" "));
debugSerial.print(hour());
debugSerial.print(F(":"));
debugSerial.print(minute());
debugSerial.print(F(":"));
debugSerial.print(second());
debugSerial.print(F(" "));
}
void debugLog( debugLogType type, QrssMode mode, QrssSpeed speed) {
print_date_time();
switch (type) {
case STARTUP :
debugSerial.print(F(" *** Startup *** - Oberon Code Version & HW : "));
debugSerial.print(F(OBERON_CODE_VERSION));
debugSerial.println(F(BOARDNAME));
break;
case GLYPH_TX :
debugSerial.println(F(" Glyph Tx Start "));
break;
case GLYPH_TX_STOP :
debugSerial.println(F(" Glyph Tx Completed "));
break;
case QRSS_TX : {
unsigned long freq_hz = g_beacon_tx_frequency_hz; // To get around problem with typing and print.
debugSerial.print(F(" QRSS TX Start : "));
debugSerial.print(F("QrssMode: "));
debugSerial.print(mode);
debugSerial.print(F(" QrssSpeed: "));
debugSerial.print(speed);
debugSerial.print(F(" Freq_hz: "));
debugSerial.println(freq_hz);
}
break;
case QRSS_TX_STOP :
debugSerial.println(F(" QRSS TX Stop"));
break;
case WAIT :
debugSerial.println(F(" ... WAIT ..."));
break;
default :
break;
}
}
#else
// This is the do-nothing version of debugLog that is compiled when OBERON_DEBUG_MODE is not defined
void debugLog( debugLogType type, QrssMode mode, QrssSpeed speed) {
return;
}
#endif
// End of conditional compilation
/*************************
SETUP
************************/
void setup() {
#if defined (OBERON_DEBUG_MODE) // We are using debug serial
debugSerial.begin(MONITOR_SERIAL_BAUD);
#endif
// Setup the Si5351a
si5351bx_init();
delay (10000);
// Set the Park Clock Frequency and enable it
si5351bx_setfreq(SI5351A_PARK_CLK_NUM, (PARK_FREQ_HZ * 100ULL), SI5351_CLK_ON);
// Setup for QRSS FSKCW transmission
g_beacon_tx_frequency_hz = QRSS_BEACON_BASE_FREQ_HZ + QRSS_BEACON_FREQ_OFFSET_HZ;
g_tx_msg_ptr = &msg[0]; // Set the global transmit message pointer to the QRSS Message by default
debugLog(STARTUP, 0, 0);
}
/*************************
main body loop
************************/
void loop() {
transmit_glyph(); // Send a character glyph to help id the transmission
g_tx_msg_ptr = &msg[0]; // Set the global transmit message pointer to the QRSS Message;
qrss_beacon(MODE_FSKCW, QRSS6); // FSKCW at QRSS06 (i.e. 6 second dits)
// Setup for conventional CW transmission in hopes of getting RBN spots
//g_beacon_tx_frequency_hz = CW_BEACON_FREQ_HZ;
// g_tx_msg_ptr = &msg2[0]; // Set the global transmit message pointer to the CW Beacon Message
// qrss_beacon(MODE_QRSS, s12wpm); //CW at 12 wpm
debugLog(WAIT, 0, 0);
delay(POST_TX_DELAY_MS);
} // end loop