-
Notifications
You must be signed in to change notification settings - Fork 7
/
Arduino-LDMOS-SSPA-Controller-v1.5.ino
769 lines (640 loc) · 21.3 KB
/
Arduino-LDMOS-SSPA-Controller-v1.5.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
/*
Arduino Code (Version 1.5) for S21RC LDMOS Controller V1.1. This board is tested with DXWORLD-E protection board, DXWORLD-E LPF Board. Any LDMOS SSPA system with similar IO should work.
Display artwork courtesy of Head.n.Hand http://www.redbubble.com/people/limon
Created by Fazlay Rabby S21RC, July, 2022.
Released into the public domain.
Feel free to use/change the Gerber file for the PCB, TFT display file for the display and all codes here.
If you use any of the above - I will feel proud if you share your work in social media and tag/hashtag me to let me know #s21rc fb.me/s21rc
If you need any clarification or help drop me an email, I am ok in qrz database.
*/
/* For PCB Version 1.1, CODE V 1.5
* NOTE: V1.1 PCB has a small mistake, please swap pin A6 and A5 on the PCB by cutting the trace and using small wire. As A6 can not be used as digital communication
*/
/* V1.5: Bug fixed for disabling touch when transmitting */
#include <EEPROM.h>
#include <OneWire.h>
#include <DallasTemperature.h> //https://github.com/milesburton/Arduino-Temperature-Control-Library
#include "math.h"
#include "EasyNextionLibrary.h" // https://github.com/Seithan/EasyNextionLibrary
/* ======= Arduino NANO PIN assignment ======== */
// NOTE: V1.1 PCB has a small mistake, please swap pin A6 and A5 on the PCB by cutting the trace and using small wire. As A6 can not be used as digital communication
#define ROTARY_POS A7
#define PWR_FWD A2
#define PWR_REF A1
#define ID A6
#define LED_PO 3
#define LED_I 2
#define VCC A0
#define LED_SWR 4
#define BIAS_OFF 17 // D17/A3 connected to pin 5 of LM2596HVS bias regulator, or else put R1, Q15, D8 and use a 12v relay for BIAS OFF, use NC pins for 12v bias supply [R9 not used]
#define PTT 18 // D18/A4
#define band1 5
#define band2 6
#define band3 7
#define band4 8
#define band5 11
#define band6 12
#define band7 13
#define antenna2 10 //Antenna 2 relay pin of arduino
/* ======= Nextion Display ========
Below are the variables inside the nextion HMI display
Please see screenshot to understand better.
a1 : Antenna 2 switch (Dual state button)
r1 : Rotary enable (Dual state button/Touch Disabled)
b1 : Band 1 (Dual state button)
b2 : Band 2 (Dual state button)
b3 : Band 3 (Dual state button)
b4 : Band 4 (Dual state button)
b5 : Band 5 (Dual state button)
b6 : Band 6 (Dual state button)
b7 : Band 7 (Dual state button)
e1: On Air indicator (Dual state button/Touch Disabled)
e2: Over current indicator (Dual state button/Touch Disabled)
e3: High SWR indicator (Dual state button/Touch Disabled)
e4: High Tempo indicator (Dual state button/Touch Disabled)
e5: Over power indicator (Dual state button/Touch Disabled)
op: place to display owner callsign (Text, 7 char max)
Cw: (Number)
Cs: (Xfloat)
Ct: (Number)
Gw: watt bar (Progress bar)
Gs: SWR bar (Progress bar)
Gt: Temp bar (Progress bar)
Cv: Voltage (Xfloat)
Ca: Current (Xfloat)
Cb: Current band (Number)
Fs: Fan status (Text)
Remove UART when Arduino is connected to computer for programming, as they use same RX/TX port.
*/
EasyNex myNex(Serial);
/* ======= Tempareture ======== */
#define ONE_WIRE_BUS 19
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress tempDeviceAddress;
int resolution = 9;
unsigned long lastTempRequest = 0;
int delayInMillis = 0;
float temperature = 0.0;
/* ======= PWM FAN ======== */
const byte OC1A_PIN = 9;
//const byte OC1B_PIN = 10;
const word PWM_FREQ_HZ = 31000; //Set currently to 31kHZ for Dalas 12V 4 wire Fan
const word TCNT1_TOP = 16000000/(2*PWM_FREQ_HZ);
/* USER DEFINED VARIABLES, PUT AS PER YOUR BOARD */
int graph_maxWatt = 600; //Scale from 0 to 600, set as per your SSPA board
int graph_maxTemp = 55; //Scale from 0 to 55, set as per your PA board.
int graph_maxSwr = 2; // Scale of the SWR for display
int VdelayInMillis = 1000; // refresh V display every N mili sec, set as per your liking
int IdelayInMillis = 100; // refresh I display every N mili sec, set as per your liking
float Res_1=150000.00; //Set R1 of voltage devider (VR VM pot, center to VDD) (you can use 150K 1% tol resistor)
float Res_2=10000.00 ; //Set R2 of voltage devider (VR VM pot, center to GND) (you can use 10K 1% tol resistor)
// Calibration factors for SWR/PO
int calibrP = 58; // Assume 3.3v = 1000w in 50R. CalibrP = (3.3 / 5.0 x 1024 + Vdiode)x(3.3 / 5.0 x 1024 + Vdiode) / 1000w
int Vdiode = 60; // if we assume FWD voltage diode = 0,3v : Vdiode = 0,3 v / 5.0 v x 1024
int T_pepHOLD = 600; // msec pep hold time before return
/* ======== Other variables ======== */
bool touch_status = true;
bool PTT_status = false;
bool error_i_status = false;
bool error_swr_status = false;
bool error_po_status = false;
bool error_temp_status = false;
bool antenna2_status = false;
int current_band = 0;
int band_pos =0;
int temp_heatsink =0;
unsigned long lastVRequest =0;
unsigned long lastIRequest =0;
float Vin=0.00;
float Vout=0.00;
int graph_Watt = 0;
int graph_Temp = 0;
int graph_Swr = 0;
/* ======== power and swr related variable ======== */
long lastTpep = 0; // update PEP display
unsigned long power_fwd = 0; // power forward (watts)
unsigned long power_ref = 0; // power reflected (watts)
unsigned int power_fwd_max = 0; // power forward max (for peak hold)
unsigned int power_ref_max = 0; // power reflected max (for peak hold)
float SWR = 0; // SWR
float power_ratio = 0; // Power ratio P forward / P refl
int swr_display = 0; // swr x 10 showing in display
/* === PWM Function === */
void setPwmDuty(byte duty){
OCR1A = (word) (duty*TCNT1_TOP)/100;
}
/* === Volt meter Function === */
void read_volt(){
float vcc;
int v1_val=0;
int V = 0;
v1_val = analogRead(VCC);
Vout = (v1_val * 5.00) / 1024.00;
Vin = Vout / (Res_2/(Res_1+Res_2));
V = ((Vin * 10)+ 0.5);
if (millis() - lastVRequest >= VdelayInMillis)
{
myNex.writeNum("Cv.val", V);
lastVRequest = millis();
}
}
/* === SWR/Po calculation Function === */
void read_power(){
power_fwd = analogRead(PWR_FWD);
power_ref = analogRead(PWR_REF);
if (power_fwd > 5){ // only correct for diode voltage when more than zero
power_fwd = (power_fwd + Vdiode)*(power_fwd + Vdiode) / calibrP;
}
if (power_ref > 5){ // only correct for diode voltage when more than zero
power_ref = (power_ref + Vdiode)*(power_ref + Vdiode) / calibrP;
}
// detect SWR error / load mismatch
power_ratio = power_fwd / power_ref; // calculate ratio with raw data
SWR = abs ((1+sqrt(power_ratio)) / (1-sqrt(power_ratio))) ;
// hold peak
if (power_fwd >= power_fwd_max){
lastTpep = millis();
power_fwd_max = power_fwd;
}
if(millis() > (lastTpep + T_pepHOLD)){ // clear the peak after hold time
power_fwd_max = power_fwd;
}
swr_display = (SWR * 10) + 0.5; // Float x 10 and convert to int with rounding
if (swr_display < 10){ // SWR cannot be lower than 1.0
swr_display = 10 ;
}
//power_fwd_max is power output
// swr_display: swr value x 10
}
/* === SWR/Po display Function === */
void display_power(){
// power_fwd_max = 432; //Test value *********************************
myNex.writeNum("Cw.val", power_fwd_max);
float graph_limit_watt = (graph_maxWatt/100.00);
graph_Watt = (power_fwd_max / graph_limit_watt);
// graph_Watt = 80; //Test value ***************************
// swr_display = 15; //Test value ***************************
myNex.writeNum("Gw.val", graph_Watt);
myNex.writeNum("Cs.val", swr_display);
float graph_limit_swr = ((graph_maxSwr-1)/100.00);
graph_Swr = ((swr_display/10)-1) / (graph_limit_swr); // calculate from 1 to max swr.
//graph_Swr = 15; //Test value *******************************
myNex.writeNum("Gs.val", graph_Swr);
}
/* =========== Send band info to LCD ====================== */
void display_band(int Nband){
myNex.writeNum("Cb.val", Nband);
switch (Nband) {
case 1:
myNex.writeNum("b1.val", 1);
myNex.writeNum("b2.val", 0);
myNex.writeNum("b3.val", 0);
myNex.writeNum("b4.val", 0);
myNex.writeNum("b5.val", 0);
myNex.writeNum("b6.val", 0);
myNex.writeNum("b7.val", 0);
break;
case 2:
myNex.writeNum("b1.val", 0);
myNex.writeNum("b2.val", 1);
myNex.writeNum("b3.val", 0);
myNex.writeNum("b4.val", 0);
myNex.writeNum("b5.val", 0);
myNex.writeNum("b6.val", 0);
myNex.writeNum("b7.val", 0);
break;
case 3:
myNex.writeNum("b1.val", 0);
myNex.writeNum("b2.val", 0);
myNex.writeNum("b3.val", 1);
myNex.writeNum("b4.val", 0);
myNex.writeNum("b5.val", 0);
myNex.writeNum("b6.val", 0);
myNex.writeNum("b7.val", 0);
break;
case 4:
myNex.writeNum("b1.val", 0);
myNex.writeNum("b2.val", 0);
myNex.writeNum("b3.val", 0);
myNex.writeNum("b4.val", 1);
myNex.writeNum("b5.val", 0);
myNex.writeNum("b6.val", 0);
myNex.writeNum("b7.val", 0);
break;
case 5:
myNex.writeNum("b1.val", 0);
myNex.writeNum("b2.val", 0);
myNex.writeNum("b3.val", 0);
myNex.writeNum("b4.val", 0);
myNex.writeNum("b5.val", 1);
myNex.writeNum("b6.val", 0);
myNex.writeNum("b7.val", 0);
break;
case 6:
myNex.writeNum("b1.val", 0);
myNex.writeNum("b2.val", 0);
myNex.writeNum("b3.val", 0);
myNex.writeNum("b4.val", 0);
myNex.writeNum("b5.val", 0);
myNex.writeNum("b6.val", 1);
myNex.writeNum("b7.val", 0);
break;
case 7:
myNex.writeNum("b1.val", 0);
myNex.writeNum("b2.val", 0);
myNex.writeNum("b3.val", 0);
myNex.writeNum("b4.val", 0);
myNex.writeNum("b5.val", 0);
myNex.writeNum("b6.val", 0);
myNex.writeNum("b7.val", 1);
break;
}
}
/* =========== LPF Relay control ====================== */
void lpf_relay(int Nrelay){
EEPROM.put(0, Nrelay); //Update/write band info to Memory
switch (Nrelay){
case 0:
digitalWrite(band1, LOW);
digitalWrite(band2, LOW);
digitalWrite(band3, LOW);
digitalWrite(band4, LOW);
digitalWrite(band5, LOW);
digitalWrite(band6, LOW);
digitalWrite(band7, LOW);
break;
case 1:
digitalWrite(band1, HIGH);
digitalWrite(band2, LOW);
digitalWrite(band3, LOW);
digitalWrite(band4, LOW);
digitalWrite(band5, LOW);
digitalWrite(band6, LOW);
digitalWrite(band7, LOW);
break;
case 2:
digitalWrite(band1, LOW);
digitalWrite(band2, HIGH);
digitalWrite(band3, LOW);
digitalWrite(band4, LOW);
digitalWrite(band5, LOW);
digitalWrite(band6, LOW);
digitalWrite(band7, LOW);
break;
case 3:
digitalWrite(band1, LOW);
digitalWrite(band2, LOW);
digitalWrite(band3, HIGH);
digitalWrite(band4, LOW);
digitalWrite(band5, LOW);
digitalWrite(band6, LOW);
digitalWrite(band7, LOW);
break;
case 4:
digitalWrite(band1, LOW);
digitalWrite(band2, LOW);
digitalWrite(band3, LOW);
digitalWrite(band4, HIGH);
digitalWrite(band5, LOW);
digitalWrite(band6, LOW);
digitalWrite(band7, LOW);
break;
case 5:
digitalWrite(band1, LOW);
digitalWrite(band2, LOW);
digitalWrite(band3, LOW);
digitalWrite(band4, LOW);
digitalWrite(band5, HIGH);
digitalWrite(band6, LOW);
digitalWrite(band7, LOW);
break;
case 6:
digitalWrite(band1, LOW);
digitalWrite(band2, LOW);
digitalWrite(band3, LOW);
digitalWrite(band4, LOW);
digitalWrite(band5, LOW);
digitalWrite(band6, HIGH);
digitalWrite(band7, LOW);
break;
case 7:
digitalWrite(band1, LOW);
digitalWrite(band2, LOW);
digitalWrite(band3, LOW);
digitalWrite(band4, LOW);
digitalWrite(band5, LOW);
digitalWrite(band6, LOW);
digitalWrite(band7, HIGH);
break;
}
current_band=Nrelay;
display_band(Nrelay);
}
/* === Monitor and show PTT status on display === */
void onair(){
int PTT_en = digitalRead(PTT);
if (PTT_en==0 && PTT_status != true){
PTT_status = HIGH;
myNex.writeNum("e1.val", 1);
LCDband_disable();
}
else if(PTT_en==1 && PTT_status!= false){
myNex.writeNum("e1.val", 0);
PTT_status = LOW;
LCDband_enable();
}
}
/* === Monitor and show over current error on display === */
void error_i(){
int error_i_en = digitalRead(LED_I);
//error_i_en = 0; //test
if (error_i_en == LOW && error_i_status == false){
myNex.writeNum("e2.val", 1);
error_i_status = true;
}
else if (error_i_en == HIGH && error_i_status == true){
myNex.writeNum("e2.val", 0);
error_i_status = false;
}
}
/* === Monitor and show over SWR error on display === */
void error_swr(){
int error_swr_en = digitalRead(LED_SWR);
//error_swr_en = 0; //test
if (error_swr_en==LOW && error_swr_status == false){
//hmiSend("e3.val=",1);
myNex.writeNum("e3.val", 1);
error_swr_status = true;
}
else if(error_swr_en==HIGH && error_swr_status == true){
//hmiSend("e3.val=",0);
myNex.writeNum("e3.val", 0);
error_swr_status = false;
}
}
/* === Monitor and show over Power error on display === */
void error_po(){
int error_po_en = digitalRead(LED_PO);
// error_po_en = 0; //test ****************************************
if (error_po_en==LOW && error_po_status == false){
myNex.writeNum("e5.val", 1);
error_po_status = true;
}
else if (error_po_en==HIGH && error_po_status == true){
//hmiSend("e5.val=",0);
myNex.writeNum("e5.val", 0);
error_po_status = false;
}
}
/* === Over temp protection and show temp error=== */
void error_temp(bool highTemp){
if (error_temp_status == false && highTemp){
digitalWrite(BIAS_OFF, HIGH); // LM2596HVS PIN5
myNex.writeNum("e4.val", 1);
error_temp_status = true;
}
if (error_temp_status == true && !highTemp){
digitalWrite(BIAS_OFF, LOW);
myNex.writeNum("e4.val", 0);
error_temp_status = false;
}
}
/* === Monitor current from protection board === */
void read_ID(){
int I;
float Is;
float Idv;
float ref_vdd = (5.00/1024);
Idv=( analogRead(ID) * ref_vdd );
Is = (Idv*13000);
Is = (Is/4482);
I = ((Is * 10)+ 0.5);
// I = 123; //test value
if (millis() - lastIRequest >= IdelayInMillis)
{
myNex.writeNum("Ca.val", I);
lastIRequest = millis();
}
}
/* === Set FAN speed according to temp === */
void fanspeed(){
if(temperature>20.0 && temperature<40.0){
setPwmDuty(75);
myNex.writeStr("Fs.txt", "LOW");
}
else if(temperature>=40.0 && temperature<45.0){
setPwmDuty(50);
myNex.writeStr("Fs.txt", "MID");
}
else if(temperature>=45.0 && temperature<50.0){
setPwmDuty(25);
myNex.writeStr("Fs.txt", "HIGH");
}
else if(temperature>=50.0 && temperature<55.0 ){
setPwmDuty(0);
myNex.writeStr("Fs.txt", "*HOT");
}
}
/* === Tempareturn Monitor === */
void read_temp(){
if (millis() - lastTempRequest >= delayInMillis)
{
temperature = sensors.getTempCByIndex(0);
sensors.requestTemperatures();
lastTempRequest = millis();
}
if(temperature>=(graph_maxTemp-1)){
error_temp(1);
setPwmDuty(0);
myNex.writeStr("Fs.txt", "ALRM");
}
if(temperature<=(graph_maxTemp-5) && error_temp_status){
error_temp(0);
}
myNex.writeNum("Ct.val", temperature);
float graph_limit = (graph_maxTemp/100.00);
graph_Temp = (temperature / graph_limit);
myNex.writeNum("Gt.val", graph_Temp);
fanspeed();
}
/* === Enabling touch functions of Display === */
void LCDband_enable(){
if(touch_status != true){
myNex.writeStr("tsw b1,1");
myNex.writeStr("tsw b2,1");
myNex.writeStr("tsw b3,1");
myNex.writeStr("tsw b4,1");
myNex.writeStr("tsw b5,1");
myNex.writeStr("tsw b6,1");
myNex.writeStr("tsw b7,1");
myNex.writeStr("tsw a1,1");
touch_status = true;
}
}
/* === Disabling touch functions of Display === */
void LCDband_disable(){
if(touch_status != false){
myNex.writeStr("tsw 255,0");
touch_status = false;
}
}
/* === Rotary band switch === */
int band_switch(){
int band_select;
//read rotary value
int band_value = analogRead(ROTARY_POS);
if (band_value <=100){
myNex.writeStr("r1.val=0");
if (PTT_status != HIGH) LCDband_enable();
band_select = current_band;
}
else if (band_value>=101&& band_value <=200){
myNex.writeStr("r1.val=1");
LCDband_disable();
band_select=1;
}
else if (band_value>=201 && band_value <=350){
myNex.writeStr("r1.val=1");
LCDband_disable();
band_select=2;
}
else if (band_value>=351 && band_value <=500){
myNex.writeStr("r1.val=1");
LCDband_disable();
band_select=3;
}
else if (band_value>=501 && band_value <=650){
myNex.writeStr("r1.val=1");
LCDband_disable();
band_select=4;
}
else if (band_value>=651 && band_value <=800){
myNex.writeStr("r1.val=1");
LCDband_disable();
band_select=5;
}
else if (band_value>=801 && band_value <=950){
myNex.writeStr("r1.val=1");
LCDband_disable();
band_select=6;
}
else if (band_value>=951 && band_value <=1024){
myNex.writeStr("r1.val=1");
LCDband_disable();
band_select=7;
}
else {}
return band_select;
}
void band_position(){
band_pos = band_switch();
if (current_band != band_pos && PTT_status != HIGH ){
lpf_relay(band_pos);
}
}
void band_position_touch(){
if (current_band != band_pos && PTT_status != HIGH){
lpf_relay(band_pos);
}
}
/* === Trigger from Nextion Display === */
void trigger1(){
band_pos = 1;
band_position_touch();
}
void trigger2(){
band_pos = 2;
band_position_touch();
}
void trigger3(){
band_pos = 3;
band_position_touch();
}
void trigger4(){
band_pos = 4;
band_position_touch();
}
void trigger5(){
band_pos = 5;
band_position_touch();
}
void trigger6(){
band_pos = 6;
band_position_touch();
}
void trigger7(){
band_pos = 7;
band_position_touch();
}
//Antenna2 switch
void trigger8(){
if (antenna2_status == LOW){
digitalWrite(antenna2, HIGH);
myNex.writeNum("a1.val", 1);
antenna2_status = HIGH;
}
else {
digitalWrite(antenna2, LOW);
myNex.writeNum("a1.val", 0);
antenna2_status = LOW;
}
}
void setup() {
delay (1000); //wait for display initialization
myNex.begin(); // start Nextion Display
myNex.writeStr("op.txt", "AB12CD"); //Write your callsign here
/* === FAN PWM setup === */
pinMode(OC1A_PIN, OUTPUT); //fan pwm
// Clear Timer1 control and count registers
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
// Set Timer1 configuration
// COM1A(1:0) = 0b10 (Output A clear rising/set falling)
// COM1B(1:0) = 0b00 (Output B normal operation)
// WGM(13:10) = 0b1010 (Phase correct PWM)
// ICNC1 = 0b0 (Input capture noise canceler disabled)
// ICES1 = 0b0 (Input capture edge select disabled)
// CS(12:10) = 0b001 (Input clock select = clock/1)
TCCR1A |= (1 << COM1A1) | (1 << WGM11);
TCCR1B |= (1 << WGM13) | (1 << CS10);
ICR1 = TCNT1_TOP;
/* ==== Temp sensor setup ==== */
sensors.begin(); //Temp sensor
sensors.getAddress(tempDeviceAddress, 0);
sensors.setResolution(tempDeviceAddress, resolution);
sensors.setWaitForConversion(false);
sensors.requestTemperatures();
delayInMillis = 750 / (1 << (12 - resolution));
lastTempRequest = millis();
pinMode(band1, OUTPUT);
pinMode(band2, OUTPUT);
pinMode(band3, OUTPUT);
pinMode(band4, OUTPUT);
pinMode(band5, OUTPUT);
pinMode(band6, OUTPUT);
pinMode(band7, OUTPUT);
pinMode(BIAS_OFF, OUTPUT);
pinMode(PTT, INPUT_PULLUP);
pinMode(LED_PO, INPUT);
pinMode(LED_I, INPUT);
pinMode(LED_SWR, INPUT);
pinMode(VCC, INPUT);
EEPROM.get(0, current_band); // Load last band position to current_band variable from memory location 0
lpf_relay(current_band);
display_band(current_band);
}
void loop() {
if (PTT_status != HIGH) myNex.NextionListen();
band_position(); //LPF Band position
onair(); //Check PTT status
read_volt(); // Read V
read_ID(); //Read I
read_power(); //Read Po and SWR
display_power(); // Display power
read_temp(); // Read Temp
error_i(); // Check Error: I
error_swr(); // Check Error: SWR
error_po(); // Check Error: Po
}