-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCurveTracerESP32_ILI9341_BMP_6_Osci_Mini_Touch.ino
4097 lines (3404 loc) · 136 KB
/
CurveTracerESP32_ILI9341_BMP_6_Osci_Mini_Touch.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
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//---------------------------------------------------------------
//
/*
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/>.
*/
//--------------------------------------------------------------------------------------------------------------------------------------
// 2023_03_16 copy from CurveTracer_2_DacV_20, but other dividers on A0,A1,A2,A3
// 2023_03_18 second encoder, only PIN_EB (not PIN_BE) for p-devices (pin 1 CCS normal high, switch automatically to low, if PIN_EB high)
// 2023_03-21 sign µ in 2/1 on position of tile (~)
// 2024_01_04 CurveTracerRP2040_Adafruit_ILI9341_SD_01: change µ-proceesor to RP2040
// 2024_01_04 CurveTracerRP2040_Adafruit_ILI9341_SD_02: test isr and encoder ("pio_encoder")
// 2024_01_16 CurveTracerESP32_ILI9341_SD_03: SD-Card , SerialBT instead of HM010
// 2024_04_20 CurveTracerESP32_ILI9341_BMP_5: SD-Card , SerialBT, new libs for MCP3204 and MCP4822, isr update
// 2024_06_01 CurveTracerESP32_ILI9341_BMP_6: s_zen: suppress zeo-point x-scale, start curve from volt s_zen
//--------------------------------------------------------------------------------------------------------------------------------------
#define TOUCH
//#define OSCI
#define DAC_INT
#define BLUE_T
#define BMP
#define IEPROM
//#define NAME_D
#define SD_C
//#define DEBUG 1
#if DEBUG == 1
#define debug(x) Serial.print(x);
#define debugb(x) Serial.print(x);Serial.print(" ");
#define debugln(x) Serial.print(x);Serial.print("\n");
#define debuglf() Serial.print("\n");
#else
#define debug(x)
#define debugb(x)
#define debugln(x)
#define debuglf()
#endif
#include <Arduino.h>
//#include <avr/pgmspace.h>
#include <SPI.h>
#ifdef SD_C
#include <SD.h> //###################
#endif
//SPISettings settingsT(10000000, MSBFIRST, SPI_MODE0); // TFT 12 MHz, cpu 240 MHz
#include "TFT_eSPI.h"
#include "Free_Fonts.h" // Include the header file attached to this sketch
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define TFT_GREY 0x5AEB
//#include <Fonts/GFXFF/FreeMonoBoldOblique12pt7b.h>
//#include "FreeSerif9pt7b.h" //## FF33 ###
#ifdef IEPROM // internal EEPROM
#include "EEPROM.h"
#define EEPROM_SIZE 256
#endif
#include "MCP_ADC.h"
// ESP32 PINS for HSPI : CLK=14, MISO=12, MOSI=13
// ESP32 PINS for VSPI : CLK=18, MISO=19, MOSI=23
MCP3204 MCP_A; // use HWSPI on ESP32 (apparently VSPI)
#include <Wire.h>
#include "Adafruit_MCP4725.h"
Adafruit_MCP4725 dac_i2c; // 12 bit DAC (I2C Addrees : 60
#ifdef BLUE_T
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
#endif
//#define EEPROM_I2C_ADDRESS 0x50 // EEPROM 24LC64 I2C Address //24LC
const int pin_DAC_CS = 0; // MCP4822 DAC
const int TX_D0 = 1; // TxD0 for send data to PC
const int pin_ADC_CS = 2; // MCP3204 ADC//GPIO2 on board LED, must be left floating or LOW to enter flashing mode
const int RX_D0 = 3; // RxD0 for TT
const int pin_EB = 4; // switch emitter / base (polarity)
//const int TFT_CS = 5; // V-SPI CS
// = 6; // Flash
// = 7; // Flash
// = 8; // Flash
// = 9; // Flash
// = 10; // Flash
// = 11; // Flash
const int pin_E_NEG = 12; // switch Emitter/Source/Kathode to Rs (near Gnd) ,Collector ... to Output TCA0372)(for npn-Tran,n-MOS
//free = 13; // free
const int pin_E_POS = 14; // switch Emitter/Source/Kathode to (output max+12V) (for pnp-Tran,p-MOS,p-JFET,Diode(backward biased))
const int pin_CV_SW = 15; // switch Constant-Current to Constant-Voltage for (Mos-Fet and J-Fet)
#ifdef SD_C
const int pin_SD_CS = 16; // SD_CS
#endif
//const int TFT_DC = 17; // V-SPI DC
//const int TFT_CLK = 18; // V-SPI CLK
//const int TFT_MISO = 19; // V-SPI MISO
// = 20; // ??? na
//const int I2C_SDA = 21; // SDA I2C for MCP4725 (DAC-base)
//const int I2C_SCL = 22; // SCL I2C for MCP4725 (DAC-base)
//const int TFT_MOSI = 23; // V-SPI MOSI
// = 24; // ??? na
#ifdef OSCI
#ifdef DAC_INT
const int pin_DAC1 = 25; // DAC1
#endif
#endif
//free = 26; // free DAC2
const int pin_TOUCH_CS = 27; // Touch-CS here not used
// = 28; // ??? na
// = 29; // ??? na
// = 30; // ??? na
// = 31; // ??? na
const int Pin_32_BUT = 32; // PushButton ISR-Pin
#ifdef OSCI
const int pin_ADC1_5 = 33; // ADC1_5
#endif
const int pin_ENC1_A = 34; // Encoder-1-A ISR-Pin, Pull-Up 10k ?
const int pin_ENC1_B = 35; // Encoder-1-B IST-Pin, Pull-Up 10k ?
const int pin_ENC2_A = 36; // Encoder-2-A ISR-Pin, Pull-Up 10k ?
const int pin_ENC2_B = 39; // Encoder-2-B ISR-Pin, Pull-Up 10k ?
const int pin_DAC_LDAC = -1; // MCP4822
//#include "MCP4822.h"
//MCP4822 dac = MCP4822(pin_DAC_CS);//,pin_DAC_LDAC);
#include "MCP_DAC.h"
// HSPI uses default SCLK=14, MISO=12, MOSI=13, SELECT=15
// VSPI uses default SCLK=18, MISO=19, MOSI=23, SELECT=5
SPIClass * myspi = new SPIClass(VSPI);
MCP4822 MCP_D(myspi); // HW SPI
const int TFT_WID = 320;
const int TFT_HGT = 240;
#ifdef OSCI
int16_t inpBuf2[TFT_WID];
int16_t inpBuf3[TFT_WID];
uint8_t newBuf2[TFT_WID], oldBuf2[TFT_WID];
uint8_t newBuf3[TFT_WID], oldBuf3[TFT_WID];
int pos = 0; // the next position in the value array to read
int count = 0; // the total number of times through the loop
unsigned long readStartTime = 0; // time when the current sampling started
int lastStart = 0; // the sample at which drawing started last time (need to know this to clear the old line properly)
int16_t val_A1 = 0,val_A2,val_A3;
// Used by vsprintf.
//char buffer[32];
uint16_t SineValues[256]; // an array to store our values for sine
#endif
//const int ADC_MAX = 4095; // 12 bit MCP3402 1024; // 10 bit arduino UNO
//const int DAC_MAX = 4095;
const int tsd = 1000;
const int mAmax = 50; // Ic for top of screen
const int Vmax = 12; // 12V right end of screen
const uint16_t col_t[] = {TFT_CYAN, TFT_YELLOW, TFT_MAGENTA,/* TFT_BRIGHTBLUE,*/ TFT_ORANGE,
TFT_PINK, /*TFT_LIGHTBLUE, TFT_LIGHTRED,*/ TFT_WHITE
};
const float count_to_mv = 5020.0 / 4096.0; // = 1.2129=Vref/maxcount ADC //Vref = 5.02V ?? not 4.968
//const float adc_refmaxcnt = 0.0049512; //4.0*5.07/4096.0; // MC3204 -Reference = U-5V/12bit ADC; divider 4: 30k/10k
//const float adc0_refmaxcnt = 0.0024756; // 4949; //2.0*5.07/4096.0; // MC3204 -Reference = U-5V/12bit ADC; divider 2: 10k/10k A0
//const float adc1_refmaxcnt = 0.0037134; // 4949; //3.0*5.07/4096.0; // MC3204 -Reference = U-5V/12bit ADC; divider 3: 20k/10k A1
//const float adc_refmaxcnt = 1.110.0/1024.0; // Internal-Reference NANO = 1.1V/10bit ADC; // divider 4.25V/1.1V ?
//const float adc_refmaxcnt = 4.41545/1024.0; // normal -Reference NANO = U-5V/10bit ADC; // ca 4.42V on USB
//const float adc_refmaxcnt = 4.0*5.07/4098.0; // MC3204 -Reference = U-5V/12bit ADC; divider
//const char seper = ','; // seperator for Bluetooth-transfer
uint8_t bmpPNP[] PROGMEM = {
21, 0, // width
30, 0, // height
0x3F, 0xFF, 0xF9, 0xFF, 0xFF, 0xCF, 0xFF, 0xFE, 0x7F, 0xFF, 0xF1, 0xFF, 0x3F, 0xC7, 0xF9, 0xFF,
0x1F, 0xCF, 0xFC, 0x7E, 0x7F, 0xF1, 0xF3, 0xFF, 0xC7, 0x9F, 0xFF, 0x1C, 0xFF, 0xFC, 0x67, 0xFF,
0xF1, 0x3F, 0xFF, 0xC1, 0xFF, 0xFF, 0x00, 0x1F, 0xFC, 0x00, 0xFF, 0x93, 0xFF, 0xF0, 0x9F, 0xFE,
0x0C, 0xFF, 0xC0, 0x67, 0xFC, 0x07, 0x3F, 0xF0, 0x39, 0xFF, 0x83, 0xCF, 0xF8, 0x1E, 0x7F, 0x8D,
0xF3, 0xF8, 0xFF, 0x9F, 0xCF, 0xFF, 0xFE, 0x7F, 0xFF, 0xF3, 0xFF, 0xFF, 0x9F, 0xFF, 0xFC
};
uint8_t bmpNPN[] PROGMEM = {
21, 0, // width
30, 0, // height
0xFF, 0xFF, 0xE7, 0xFF, 0xFF, 0x3F, 0xFF, 0xF9, 0xFF, 0xFF, 0xCF, 0xE7, 0xFC, 0x7F, 0x3F, 0xC7,
0xF9, 0xFC, 0x7F, 0xCF, 0xC7, 0xFE, 0x7C, 0x7F, 0xF3, 0xC7, 0xFF, 0x9C, 0x7F, 0xFC, 0xC7, 0xFF,
0xE4, 0x7F, 0xFF, 0x07, 0xFC, 0x00, 0x7F, 0xE0, 0x03, 0xFF, 0xFE, 0x0F, 0xFF, 0xF2, 0x3B, 0xFF,
0x98, 0x9F, 0xFC, 0xE0, 0x7F, 0xE7, 0x83, 0xFF, 0x38, 0x0F, 0xF9, 0x80, 0x7F, 0xCF, 0x01, 0xFE,
0x7E, 0x0F, 0xF3, 0xFC, 0x3F, 0xFF, 0xF9, 0xFF, 0xFF, 0xCF, 0xFF, 0xFE, 0x7F, 0xFF, 0xF0
};
uint8_t bmpNMOSFET[] PROGMEM = {
23, 0, // width
34, 0, // height
0xFF, 0xFF, 0xF9, 0xFF, 0xFF, 0xF3, 0xFF, 0xFF, 0xE7, 0xFF, 0xFF, 0xCF, 0xFF, 0xFF, 0x9F, 0xFF,
0xFF, 0x3F, 0xFF, 0xFE, 0x7F, 0xFF, 0xFC, 0xFE, 0x60, 0x01, 0xFC, 0xC0, 0x03, 0xF9, 0x9F, 0xFF,
0xF3, 0x3F, 0xFF, 0xE7, 0xFF, 0xFF, 0xCF, 0xFB, 0xFF, 0x99, 0xC7, 0xFF, 0x32, 0x0F, 0xFE, 0x60,
0x01, 0xFC, 0xC0, 0x03, 0xF9, 0x90, 0x67, 0xF3, 0x38, 0xCF, 0xE7, 0xFD, 0x9F, 0xCF, 0xFF, 0x3F,
0x99, 0xFE, 0x7F, 0x33, 0xFC, 0x00, 0x60, 0x00, 0x00, 0xC0, 0x03, 0xFF, 0xFF, 0xE7, 0xFF, 0xFF,
0xCF, 0xFF, 0xFF, 0x9F, 0xFF, 0xFF, 0x3F, 0xFF, 0xFE, 0x7F, 0xFF, 0xFC, 0xFF, 0xFF, 0xF9, 0xFF,
0xFF, 0xF0
};
uint8_t bmpPMOSFET[] PROGMEM = {
23, 0, // width
34, 0, // height
0x3F, 0xFF, 0xFE, 0x7F, 0xFF, 0xFC, 0xFF, 0xFF, 0xF9, 0xFF, 0xFF, 0xF3, 0xFF, 0xFF, 0xE7, 0xFF,
0xFF, 0xCF, 0xFF, 0xFF, 0x9F, 0xFF, 0xFF, 0x00, 0x0C, 0xFE, 0x00, 0x19, 0xFF, 0xFF, 0x33, 0xFF,
0xFE, 0x67, 0xFF, 0xFF, 0xCF, 0xFF, 0xBF, 0x9F, 0xFC, 0x73, 0x3F, 0xE0, 0xE6, 0x7F, 0x80, 0x0C,
0xFE, 0x00, 0x19, 0xFC, 0x07, 0x33, 0xF9, 0x8E, 0x67, 0xF3, 0xDF, 0xCF, 0xE7, 0xFF, 0x9F, 0xCF,
0xF3, 0x3F, 0x9F, 0xE6, 0x7F, 0x00, 0x0C, 0x00, 0x00, 0x18, 0x00, 0xFF, 0xFF, 0xF9, 0xFF, 0xFF,
0xF3, 0xFF, 0xFF, 0xE7, 0xFF, 0xFF, 0xCF, 0xFF, 0xFF, 0x9F, 0xFF, 0xFF, 0x3F, 0xFF, 0xFE, 0x7F,
0xFF, 0xFC
};
uint8_t bmpNJFET[] PROGMEM = {
21, 128, // width (run-length encoded)
30, 0, // height
0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x05, 0x02, 0x0C,
0x02, 0x05, 0x02, 0x0C, 0x09, 0x0C, 0x09, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x06, 0x01, 0x0C, 0x02, 0x04,
0x03, 0x0C, 0x02, 0x02, 0x05, 0x05, 0x2C, 0x05, 0x02, 0x02, 0x05, 0x05, 0x02, 0x05, 0x02, 0x04, 0x03, 0x05, 0x02, 0x0D,
0x01, 0x05, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13
};
uint8_t bmpPJFET[] PROGMEM = {
21, 128, // width (run-length encoded)
30, 0, // height
0x00, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x0C, 0x02, 0x05,
0x02, 0x0C, 0x02, 0x05, 0x02, 0x0C, 0x09, 0x0C, 0x09, 0x0C, 0x02, 0x13, 0x02, 0x13, 0x02, 0x0F, 0x01, 0x03, 0x02, 0x0D,
0x03, 0x03, 0x02, 0x0B, 0x05, 0x03, 0x02, 0x07, 0x2A, 0x04, 0x05, 0x03, 0x02, 0x05, 0x02, 0x06, 0x03, 0x03, 0x02, 0x05,
0x02, 0x08, 0x01, 0x0A, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02, 0x13, 0x02
};
uint8_t bmpPDiodeBig[] PROGMEM = {
20, 128, // width run-length encoded
24, 0, // height
0x00, 0x09, 0x02, 0x12, 0x02, 0x12, 0x02, 0x12, 0x02, 0x12, 0x02, 0x12, 0x02, 0x09, 0x14, 0x01, 0x12, 0x03, 0x10, 0x05,
0x0E, 0x07, 0x0C, 0x09, 0x0A, 0x0B, 0x08, 0x0D, 0x06, 0x0F, 0x04, 0x11, 0x02, 0x09, 0x28, 0x09, 0x02, 0x12, 0x02, 0x12,
0x02, 0x12, 0x02, 0x12, 0x02, 0x12, 0x02, 0x09
};
uint8_t bmpNDiodeBig[] PROGMEM = {
20, 128, // width run-length encoded
24, 0, // height
0x00, 0x09, 0x02, 0x12, 0x02, 0x12, 0x02, 0x12, 0x02, 0x12, 0x02, 0x12, 0x02, 0x09, 0x28, 0x09, 0x02, 0x11, 0x04, 0x0F,
0x06, 0x0D, 0x08, 0x0B, 0x0A, 0x09, 0x0C, 0x07, 0x0E, 0x05, 0x10, 0x03, 0x12, 0x01, 0x14, 0x09, 0x02, 0x12, 0x02, 0x12,
0x02, 0x12, 0x02, 0x12, 0x02, 0x12, 0x02, 0x09
};
const char* txp[6] = {"min: ", "incr:", "max: ", "mist ", "inst ", "mast "};
const char* txt[9] = {"I-base [uA]", "V-gate [0.1V] ", "V-gate [0.1V] ", "Bluet.", "CCS", "x-scale[V] : ", "y-scale[mA]: ", "Batt:", "I-diode [mA]"};
const char* txc[5] = {"pnp/npn", "MosFET", "J-FET ", "n-DEPL", "Diode"};
const char* txf[9] = {"CurveTracer", "Curve+Bluetooth", "Curve+SD-Card", "Curve+Bluet.+SD-C", "const.Voltage", "const.Current", "cC:Step-Up/Down", "cC:Step-Up", "cC:Step-Down"};
const char* txk[10] = {" ", " npn", " n-Mosfet", " n-jFet", " n-Diode", " pnp", " p-Mosfet", " p-jFet", " p-Diode", " n-Depl.Mos"};
const char* sdi[2] = {"SD-Card inserted ?", "SD-initial. done"};
const char* sdo[3] = {"sd000001.txt", "SD opened: ", "SD not opned: "};
/*
const char* pmosf = "p-MOSFET";
const char* nmosf = "n-MOSFET";
const char* pjfet = "p-JFET";
const char* njfet = "n-JFET";
const char* pdiod = "pDiode";
const char* ndiod = "nDiode";
*/
const int8_t lf = 10; // linefeed
const uint16_t ft[4][10] =
//---- 0---1---2---3---4---5---6---7---8---9---
{ 19, 37, 37, 19, 19, 19, 19, 19, 19, 37, // h
82, 123, 263, 289, 129, 129, 129, 280, 280, 162, // x
7, 0, 0, 100, 98, 148, 198, 148, 198, 0, // y
32, 38, 38, 20, 36, 36, 44, 35, 40, 98
}; // w 36/43 33/40 8:34
//---- 0---1---2---3---4---5---6---7---8---9---
const int8_t xs_t[] = {0, 1, 2, 3, 4, 6, 12}; // x_scale
const int8_t ys_t[] = {0, 2, 5, 10, 20, 50, 100}; // y_scale
//-----------------0-------1-------2-----------3--------4--------5-------6--------7----------8----
enum TkindDUT {tkNothing, tkNPN, tkNMOSFET, tkNJFET, tkNDIODE, tkPNP, tkPMOSFET, tkPJFET, tkPDIODE};
//-----------------0-------1-------2-----------3--------4--------5-------6--------7----------8----
int8_t /*TkindDUT*/ curkind;
//enum TclassDUT {tcBipolar, tcMOSFET, tcJFET};//0,1,2
int8_t tcBipolar = 0;
int8_t tcMOSFET = 1;
int8_t tcJFET = 2;
int8_t CurDUTclass = tcBipolar, class_o = tcBipolar;
uint8_t idev, run_nr = 0, error_i = 0; //,nr_l=0;
uint16_t back_col, curve_col = TFT_BLACK, text_col = TFT_WHITE, col = 0, xo, yo, wo, ho, xa = 280, ya = 196, wa = 32, ha = 19;
bool retc;
char sign, devPol = 'N';
char buf[6]; // 12
char name_t[7], txtv[16], txcv[8];
char filen_t[13];
#ifdef SD_C
File dataFile;
//String dataString = "";
#endif
#ifdef NAME_D
int8_t l_devna = 0; // devname
#endif
int8_t cxs = 0, cys = 0, l_ch = 4, nrk, dcl;
uint8_t x_scale = 12; // 1V, 2V, 3V, 4V, 6V, 12V default: 12V
uint8_t y_scale = 50; // 2mA, 5mA, 10mA, 20mA, 50mA, 100mA default: 50mA
int16_t ifc, ifi;
int base, igain = 0, iohm = 0, ibc = 0, ild, ith, x_old = 0, y_old = 0, i_CVS_A, i_CVS_B;
int DacVcc, incDacA, incDacB;
int incpix, maxpix, minpix, para, paro;
int val = 0, ila, imax = 480; //(600/48) * 50;
int incB = 0, minB = 0, maxB = 0, xlp, ylp;
int8_t s_ohm = 0, z_ohm, s_pos, iw, s_tt = 0, s_auto = 0, s_new = 0, s_old = 0;
volatile int enc1_State, enc1_State_o, newPos1, oldPos1 = -1999;
volatile int enc2_State, enc2_State_o, newPos2, oldPos2 = -1999;
volatile int8_t s_isr = 0, s_isr1, s_isr2, s_isr32 = 0, s_two1, s_two2, efnr, rota2 = 0, rota1 = 0, s_9 = 0;
volatile long time_l = 0, time1_o = 0, time2_o = 0;
unsigned long seconds = 1000L; //Notice the L
unsigned long minutes = seconds * 60;
int delay_CCS, delay_CCS_bas, delay_CCS_pow;
//delay(minutes); //for 60,000 milliseconds
int value;
/*
int MinIbase = 0; // 0µA
int MaxIbase = 500; // 100µA
int IncIbase = 10; // 10 µA
int MinVgatm = 0;
int MaxVgatm = 120; // = 12V
int IncVgatm = 10; // 0.1V (10 µA x 10 k)
int MinVgate = 0;
int MaxVgate = 120; // = 12V
int IncVgate = 10; // 0.1V (10 µA x 10 k)
*/
int mini = 0, maxi = 0, inci = 0, minst = 1, incst = 1, maxst = 10;
byte i = 0, s_blue = 0, s_sdcard = 0, s_first = 1, s_depl = 0, s_diode = 7, s_dsign = 0;
byte s_milli, s_stair = 0, s_idss = 0, s_thresh = 0, s_pinch = 0, s_stop = 0, s_comp = 0, s_compl = 0;
int16_t s_delay1=0,s_delay2=0,s_zen=0;
int8_t s_touch = 0,s_osci = 0,s_curve = 0,s_chan1=0,s_chan2=0,s_offs1=0,s_offs2=0;
float fce, fi, fib, fid, fidio, fidss, fir, fpinch, fuc, fui = 12.0, fur, fvgate, fvthr, ubat = 0.0,ua2=0.0;
float fimax, finc; // 0.319/x_scale //= 1023.33 * (float) x_scale; //1023 * 12 = 12280 mV
float f_gain=1.0,f_gain1=1.0,f_gain2=1.0;
uint8_t yct[320];
#define RGB(r, g, b) (((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3))
#define TFT_PAPAYA RGB(255, 239, 213)
#define TFT_PEACH RGB(255, 218, 185)
#define TFT_LIGHTGREY RGB(192, 192, 192)
#define TFT_LIGHTBLUE RGB( 40, 80, 255)
#define TFT_BRIGHTBLUE RGB(128, 255, 255)
#define TFT_LIGHTRED RGB(255, 100, 150)
#define TFT_UDARKGREY RGB( 64, 64, 64)
#define TFT_BLACKALMOST RGB( 25, 25, 25)
#define TFT_WHITEALMOST RGB(208, 208, 208)
#define TFT_LIGHTTUERK RGB(127, 255, 80)
void DrawPixel(uint16_t x, uint16_t y, uint16_t color) {
tft.drawPixel(x, y, color);
}
void DrawString(const char *s, uint8_t tsi, uint16_t color) { //
tft.setTextColor(color);
tft.setTextSize(tsi);
tft.print(s);
}
void DrawStringAt(uint16_t x, uint16_t y, const char *s, uint8_t tsi, uint16_t color) { //
tft.setTextColor(color);
tft.setTextSize(tsi);
tft.setCursor(x, y);
tft.print(s);
}
void DrawCharAt(uint16_t x, uint16_t y, char c, uint8_t tsi, uint16_t color) { //
tft.setTextColor(color);
tft.setTextSize(tsi);
tft.setCursor(x, y);
tft.print(c);
}
void DrawChar(char c, uint8_t tsi, uint16_t color) { //
tft.setTextColor(color);
tft.setTextSize(tsi);
tft.print(c);
}
void DrawInt(int i, uint8_t tsi, uint16_t color) { //
tft.setTextColor(color);
tft.setTextSize(tsi);
tft.print(i);
}
void DrawIntAt(uint16_t x, uint16_t y, int i, uint8_t tsi, uint16_t color) { //
tft.setTextColor(color);
tft.setTextSize(tsi);
tft.setCursor(x, y);
tft.print(i);
}
void DrawFloat(float floatNumber, int dp, uint8_t tsi, uint16_t color) { //
tft.setTextColor(color);
tft.setTextSize(tsi);
tft.print(floatNumber, dp);
}
void DrawFloatAt(uint16_t x, uint16_t y, float floatNumber, int dp, uint8_t tsi, uint16_t color) { //
tft.setTextColor(color);
tft.setTextSize(tsi);
tft.setCursor(x, y);
tft.print(floatNumber, dp);
}
void DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) {
tft.drawLine(x1, y1, x2, y2, color);
}
void DrawHLine(uint16_t x, uint16_t y, uint16_t h, uint16_t color) {
tft.drawFastHLine(x , y, h, color);
}
void DrawVLine(uint16_t x, uint16_t y, uint16_t h, uint16_t color) {
tft.drawFastVLine(x , y, h, color);
}
void ILI9341SetCursor(uint16_t x, uint16_t y) {
tft.setCursor(x, y);
}
void DrawBox(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color) {
tft.fillRect( x, y, w, h, color);
}
void DrawFrame(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color) {
tft.drawRect( x, y, w, h, color);
}
/*
void EEPROM.writeCharEEPROM(int address, byte val, int i2c_address) // 24LC Function to EEPROM.writeChar to EEPROOM
{
Wire.beginTransmission(i2c_address); // Begin transmission to I2C EEPROM
Wire.write((int)(address >> 8)); // MSB // Send memory address as two 8-bit bytes
Wire.write((int)(address & 0xFF)); // LSB // Send memory address as two 8-bit bytes
Wire.write(val); // Send data to be stored
Wire.endTransmission(); // End the transmission
delay(5); // Add 5ms delay for EEPROM
}
*/
/*
byte readEEPROM(int address, int i2c_address) //24LC Function to read from EEPROM
{
byte rcvData = 0xFF; // Define byte for received data
Wire.beginTransmission(i2c_address); // Begin transmission to I2C EEPROM
Wire.write((int)(address >> 8)); // MSB // Send memory address as two 8-bit bytes
Wire.write((int)(address & 0xFF)); // LSB // Send memory address as two 8-bit bytes
Wire.endTransmission(); // End the transmission
Wire.requestFrom(i2c_address, 1); // Request one byte of data at current memory address
rcvData = Wire.read(); // Read the data and assign to variable
return rcvData; // Return the data as function output
}
*/
void IRAM_ATTR isr_but32() { // push-button pressed
s_isr32 = 1;
s_isr1 = 0;
s_isr2 = 0;
// long time_a = millis();
// if (time_a > time_l + 5) { //3 // time_e
// s_isr = 1;
// time_l = time_a;
// }
}
void IRAM_ATTR isr_ENC1() {
if ((millis() - time1_o) < 50) // debounce time is 50ms
return;
s_isr1 = 1;
if (digitalRead(pin_ENC1_B) == HIGH) {
// the encoder is rotating in counter-clockwise direction => decrease the counter
newPos1--;
rota1 = -1;
// direction = DIR_CCW;
} else {
// the encoder is rotating in clockwise direction => increase the counter
newPos1++;
rota1 = 1;
// direction = DIR_CW;
}
time1_o = millis();
}
void IRAM_ATTR isr_ENC2() {
if ((millis() - time2_o) < 50) // debounce time is 50ms
return;
// s_isr1 = 0;
s_isr2 = 1;
if (digitalRead(pin_ENC2_B) == HIGH) {
// the encoder is rotating in counter-clockwise direction => decrease the counter
newPos2--;
rota2 = -1;
// dir2 = DIR_CCW;
} else {
// the encoder is rotating in clockwise direction => increase the counter
newPos2++;
rota2 = 1;
// dir2 = DIR_CW;
}
time2_o = millis();
}
//-------------------------------------------------------------------------
// DrawKindStr
// draws the kind of the DUT at the top of the screen
//-------------------------------------------------------------------------
void DrawKindStr(int8_t /*TkindDUT*/ kind) {
// debug("DrawKindstr: ");debugln(kind);
int ix = 146; //(TFT_WID - 28)/2; // Bitmap
int ixb = 140; //(TFT_WID - 39)/2; // bipolar
int ixm = 120; //(TFT_WID - 80)/2; // Mosfet
int ixj = 130; //(TFT_WID - 59)/2; // J-Fet
tft.setFreeFont(NULL); // NULL: use (old/)5tandard font GLCD.h //??
if (s_thresh > 1 or s_idss > 1 or s_pinch > 1) DrawBox(201, 4, 75, 42, TFT_BLACK); // for idss,vpinch,...
if (idev == 84) { // 84==T// kind == tkNPN or kind == tkPNP) { // bipolar
if (s_diode == 1) {
DrawBox(139, 3, 59, 18, TFT_BLACK);
DrawBox(142, 22, 26, 34, TFT_BLACK);
tft.setCursor(ixb, 3); // 15
if (kind == tkPNP) {
DrawString(txk[8]/*pdiod*/, 2, TFT_YELLOW); // size
#ifdef BMP
DrawBitmapMono(ix, 25, bmpPDiodeBig, TFT_YELLOW);
#endif
}
else {
DrawString(txk[4]/*ndiod*/, 2, TFT_YELLOW); // size
#ifdef BMP
DrawBitmapMono(ix, 25, bmpNDiodeBig, TFT_YELLOW);
#endif
}
return;
} // diode
// pnp/npn-transistor
tft.setCursor(ixb, 3);
if (kind == tkPNP) {
DrawString("PNP", 2, TFT_YELLOW);
#ifdef BMP
DrawBitmapMono(ix, 25, bmpPNP, TFT_YELLOW);
#endif
}
else {
DrawString("NPN", 2, TFT_YELLOW);
#ifdef BMP
DrawBitmapMono(ix, 25, bmpNPN, TFT_YELLOW);
#endif
}
return;
}
tft.setCursor(ixm, 3);
if (kind == tkPMOSFET ) {
DrawString(txk[6]/*pmosf*/, 2, TFT_YELLOW);
#ifdef BMP
DrawBitmapMono(ix, 25, bmpPMOSFET, TFT_YELLOW);
#endif
return;
}
if (kind == tkNMOSFET) {
DrawString(txk[2]/*nmosf*/, 2, TFT_YELLOW);
#ifdef BMP
DrawBitmapMono(ix, 25, bmpNMOSFET, TFT_YELLOW);
#endif
return;
}
tft.setCursor(ixj, 3);
if (kind == tkPJFET) {
DrawString(txk[7]/*pjfet*/, 2, TFT_YELLOW);
#ifdef BMP
DrawBitmapMono(ix, 25, bmpPJFET, TFT_YELLOW);
#endif
return;
}
if (kind == tkNJFET) {
if (s_depl == 0) { // normal j-Fet
DrawString(txk[3]/*njfet*/, 2, TFT_YELLOW);
#ifdef BMP
DrawBitmapMono(ix, 25, bmpNJFET, TFT_YELLOW);
#endif
return;
}
else { // depletion-mode MOS-FET
// txcv = txc[3];
DrawString(txc[3], 2, TFT_YELLOW);
#ifdef BMP
DrawBitmapMono(ix, 25, bmpNMOSFET, TFT_YELLOW);
#endif
DrawVLine(157, 34, 17, TFT_YELLOW); // 20 ??
DrawVLine(158, 34, 17, TFT_YELLOW); // 20 ??
return;
}
}
/*
case tkPDIODE:
case tkNDIODE:
DrawStringAt((TFT_WID - 47) / 2, 15, "Diode", 2, TFT_YELLOW);
#ifdef BMP
DrawBitmapMono((TFT_WID - 20) / 2, 25, bmpPDiodeBig, TFT_YELLOW);
#endif
break;
default: // unknown
*/
// DrawStringAt(151/*(TFT_WID - 117) / 2*/, 15, "Curve Tracer", 2, TFT_YELLOW);
}
/***************************************************************************************
** Function name: DrawBitmapMono
** Description: Draw a black and white image stored in an array on the TFT
***************************************************************************************/
void DrawBitmapMono(int16_t x, int16_t y, uint8_t *bitmap, uint16_t color) {
uint8_t *bmp;
int16_t w;
bmp = bitmap;
w = pgm_read_byte(bmp++);
w = pgm_read_byte(bmp++);
if ((w & 0x80) > 0)
DrawBitmapMonoRLE(x, y, bitmap, color);
else
DrawBitmapMonoBits(x, y, bitmap, color);
}
/***************************************************************************************
** Function name: DrawBitmapMonoBits
** Description: Draw a black and white image stored as an array of bits
***************************************************************************************/
void DrawBitmapMonoBits(int16_t x, int16_t y, const uint8_t *bitmap, uint16_t color) {
int16_t i, j, bits, n, w, h;
w = pgm_read_byte(bitmap++);
w = w | (pgm_read_byte(bitmap++) << 8);
h = pgm_read_byte(bitmap++);
h = h | (pgm_read_byte(bitmap++) << 8);
//tft_fastSetup();
n = 0;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++ ) {
if (n % 8 == 0)
bits = pgm_read_byte(bitmap++);
if ((bits & 0x80) == 0) DrawPixel(x + i, y + j, color);
// if ((bits & 0x80) == 0) tft_fastPixel(x + i, y + j, color);
bits = bits << 1;
n++;
}
}
}
void DrawBitmapMonoRLE(int16_t x, int16_t y, const uint8_t *bitmap, uint16_t color) {
int16_t i, j, nb, w, h;
bool CurIsBlack;
w = pgm_read_byte(bitmap++);
w = w | (pgm_read_byte(bitmap++) << 8);
w = w & 0x7FFF;
h = pgm_read_byte(bitmap++);
h = h | (pgm_read_byte(bitmap++) << 8);
// tft_fastSetup();
nb = 0;
CurIsBlack = true;
j = 0;
i = 0;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++ ) {
while (nb == 0) {
nb = pgm_read_byte(bitmap++);
CurIsBlack = !CurIsBlack;
}
if (!CurIsBlack) DrawPixel(x + i, y + j, color);
// if (!CurIsBlack) tft_fastPixel(x + i, y + j, color);
nb--;
}
}
}
//-------------------------------------------------------------------------
// TurnOffLoad
// sets load current to zero
//-------------------------------------------------------------------------
void TurnOffLoad() {
digitalWrite(pin_E_NEG, LOW); // disconnect Emitter/Source/Cathode from ground
//delay(4);
digitalWrite(pin_E_POS, LOW); // disconnect Emitter/Source/Anode from V+
// delay(4);
// digitalWrite(pin_BE, LOW); // disconnect current-source
// delay(4);
digitalWrite(pin_EB, LOW); // switch current-source to p-device
// delay(4);
// digitalWrite(pin_POW_CCS , LOW); // used for ccs-i2c, use pin_E_NEG /pin_E_POS : truncate power from CVS(TCA0372)-board
//delay(10);
digitalWrite(pin_CV_SW, LOW); // switch to constant-current source PinA2 bipolar
delayMicroseconds(15);
// Serial.println("vor settingsD");
MCP_D.setSPIspeed(12000000); // SPI.beginTransaction(settingsD); // DAC: 12MHz
// Serial.println("nach settingsD");
MCP_D.fastWriteA(0); // MCP4822
MCP_D.fastWriteB(0); // MCP4822
delay(20);
// Serial.println("vor i2c.setvolt");
dac_i2c.setVoltage(0, false); // MCP4725
delayMicroseconds(20); //delay(1); // 10;
// Serial.println("vor settingsT");
// SPI.beginTransaction(settingsT); // TFT: 20MHz
// Serial.println("nach settingsT");
}
/*
// Send value to DAC channel (0 or 1) MCP4822
void setValue_DAC(byte channel, uint16_t val) {
uint16_t data = val;
//data <<= SHIFT_BITS_CNT; //0 for MCP4822
data |= (((uint16_t)channel << CHANNEL_BIT_POS)
| ((uint16_t)GAIN_1X << GAIN_BIT_POS)
| ((uint16_t)MCP48X2_CH_ACTIVE << SHDN_BIT_POS));
digitalWrite(pin_DAC_CS, LOW); // Select chip (active low)
SPI.beginTransaction(SPISettings(ADC_CLK, MSBFIRST, SPI_MODE0));
SPI.transfer16(data);
SPI.endTransaction();
digitalWrite(pin_DAC_CS, HIGH); // deselect chip (active low)
}
*/
//-------------------------------------------------------------------------
// InitGraph
// draws the grid background of the graph
//-------------------------------------------------------------------------
void InitGraph(int8_t /*TkindDUT*/ kind) {
long ix, x = 0, iy, y, iw;
float fx = 0;
uint8_t s_min = 0;
if (devPol == 'P') s_min = 1; //neg.scale //if (kind >== tkPNP || kind == tkPMOSFET || kind == tkPJFET || kind == tkPDIODE) s_min = 1; // neg.scale
tft.fillScreen(TFT_BLACK);// ClearDisplay(TFT_BLACK);
tft.setFreeFont(NULL); // NULL: use (old/)5tandard font GLCD.h
tft.setTextSize(1);
DrawBox(286, 80, 34, 80, TFT_BLACK); // Blackalmost
DrawLine(0, 0, 0, TFT_HGT, TFT_UDARKGREY);
DrawLine(0, TFT_HGT - 1, TFT_WID, TFT_HGT - 1, TFT_UDARKGREY);
uint16_t disx = 312 / 12; // 26 vertical grid
uint16_t max_scale = Vmax; // 12
for (ix = 1; ix <= max_scale; ix++) { // vertical lines of the grid
x += disx; // #################// 26,13,3
DrawLine(x, 0, x, TFT_HGT - 10, TFT_UDARKGREY);
}
for (iy = 1; iy <= 9; iy++) { // horizontal lines of the grid
uint8_t y_h = 240 - iy * 24;
DrawLine(12 , y_h, TFT_WID, y_h, TFT_UDARKGREY);
}
if (s_osci == 1) {
// s_osci = 0;
return;
}
tft.setTextColor(TFT_LIGHTGREY);
tft.setCursor(2, TFT_HGT - 11);
if (s_zen > 0) tft.print(s_zen); //s_zen
else tft.print('0'); //DrawCharAt(2, TFT_HGT - 4, '0', 1, TFT_LIGHTGREY); //string
uint16_t scq = max_scale / x_scale; // 1,2,
x = 0;
tft.setTextColor(TFT_LIGHTGREY);
for (ix = 1; ix <= max_scale; ix++) { // x-scale
x += disx; // #################// 26,13,3
// DrawLine(x, 0, x, TFT_HGT - 10, TFT_UDARKGREY);
if (s_zen > 0) fx = (float) s_zen + (float)(ix) * 0.2; //??????
else fx = (float) ix / (float)scq; //??????
tft.setCursor(x - 4, TFT_HGT - 11); //HGT - 3
if (ix < max_scale) tft.print(fx, 1); //DrawFloat(fx, 1, 1, TFT_LIGHTGREY);
}
tft.setTextColor(TFT_LIGHTGREY);
tft.setCursor(301, TFT_HGT - 11); // 3
if (s_min == 1) tft.print('-'); //DrawCharAt(300, TFT_HGT - 3, '-', 1, TFT_LIGHTGREY); //string
tft.print('V'); //DrawCharAt(310, TFT_HGT - 3, 'V', 1, TFT_LIGHTGREY); //string
// y_scale = 100;//mAmax; // 50mA ,100mA 10 mA
uint8_t y_div = 10;
if (y_scale < 10) y_div = y_scale;
for (iy = 0; iy < y_scale; iy += y_scale / y_div) { //0,10,20,30,40,50 0,20,40,60,80
y = TFT_HGT - 1 - iy * TFT_HGT / y_scale;
tft.setCursor(2, y + 3);
if (iy > 0) tft.print(iy); //DrawIntAt(2, y + 3, iy, 1, TFT_LIGHTGREY);
// DrawLine(12 , y, TFT_WID, y, TFT_UDARKGREY);
}
tft.setTextColor(TFT_LIGHTGREY);
tft.setCursor(2, 8);
if ( s_min == 1) tft.print('-'); //DrawCharAt(2, 8, '-', 1, TFT_LIGHTGREY); //string
tft.print("mA"); //DrawString("mA", 1, TFT_LIGHTGREY);
DrawKindStr(kind);
tft.setFreeFont(FF33); // tft.setFreeFont(&FreeSerif9pt7b);
// Serial.println("initGraph end");
}
void EndScan(int8_t /*TkindDUT*/ kind) {
DrawKindStr(kind);
tft.setFreeFont(FF33); // tft.setFreeFont(&FreeSerif9pt7b); // font??
if (idev == 77) { // 77=M //kind == tkPMOSFET or kind == tkNMOSFET) {
// DrawKindStr(kind);
if (s_thresh == 2) {
tft.setCursor(202,38);
DrawString(" Vth=", 1, TFT_CYAN);
DrawFloat(fvthr, 1, 1, TFT_CYAN);
// fvthr = 0.0;
s_thresh = 0;
}
return;
}
if (idev == 70) { // 70==F // kind == tkPJFET or kind == tkNJFET) {
if (s_idss == 2) {
tft.setCursor(202,38);
DrawString(" Idss=", 1, TFT_CYAN); // 2
DrawFloat(fidss, 1, 1, TFT_CYAN); // 2
// fidss = 0.0;
s_idss = 0;
}
if (s_pinch == 2) {
tft.setCursor(202, 14);
DrawString(" Vp=", 1, TFT_CYAN);
if (kind == tkNJFET) DrawChar('-', 1, TFT_CYAN);//string
DrawFloat(fpinch, 1, 1, TFT_CYAN);
// fpinch = 0.0;
s_pinch = 0;
}
}
}
void changePolar(int8_t /*TkindDUT*/ kind) { //
s_compl = 1;
int8_t iki = /*(int)*/ kind;
// debug("switch from old-p/n-kind");debug(kind);
if (iki <= 4) iki = iki + 4; // from 'n' to 'p': 5,6,7,8
else iki = iki - 4; // from 'p' to 'n': 1,2,3,4
kind = /*(TkindDUT)*/ iki;
curkind = kind;
devPol = 'N';
if (kind >= 5) devPol = 'P';
// debug("to new-n/p-kind");debugln(kind);
}
void nextDevice(int8_t /*TkindDUT*/ kind) { // stopCurves or compare/complemenary-mode
int8_t ic;
char* txm[4] = {"Stop ?", "Param ?", "Compare ?", "Complem. ?"};
#ifdef SD_C
if (s_sdcard == 1) {
dataFile.print(0x04); // EOF 0x1A ?
dataFile.close();
}
#endif
tft.setFreeFont(FF33); // tft.setFreeFont(&FreeSerif9pt7b); // font??
s_isr2 = 0;
s_isr32 = 0;
while (1) {
for (ic = 0; ic <= 3; ic++) {
DrawBox(27, 53, 92, 18, TFT_BLACK);//DARKGREY);
// tft.setCursor(27, 65); tft.setTextColor(TFT_WHITE);tft.print(txm[ic]);
DrawStringAt(27, 65,txm[ic], 1, TFT_WHITE);
delay(1200);
if (s_isr2 == 1 or s_isr32 == 1) {
s_isr2 = 0;
s_isr32 = 0;
if (ic == 0) s_stop = 1;
else if (ic == 1) s_stop = 2;
else if (ic == 2) s_comp = 1;
else if (ic == 3) changePolar(kind); // s_compl = 1
return;
} // if
} // for
} // while
}
void setDac_A_B() {
int idelay = 1, ifco = 0, isa, isb, isba=0,isi = 1, ianz = 1;
float fis = 0;
ifc = 0;
ifco = 0;
ifi = 0;
// Serial.println("setDac_A_B");
MCP_D.setSPIspeed(12000000); // SPI.beginTransaction(settingsD); // DAC: 2 wegen ADC, max: 12MHz
//dac.setGain1X_B(); //xx 0...2048mV, 0.5 mV/step ###
//dac.setGain1X_A(); //xx 0...2048mV, 0.5 mV/step ###
MCP_D.fastWriteA(0);
MCP_D.fastWriteB(0);
delay(10); // 50
if (s_blue == 4) { // constVoltage 2 sd_c
MCP_D.fastWriteA(i_CVS_A); // 4000 = 80mV
delay(30);
if (i_CVS_B > 0) {
MCP_D.fastWriteB(i_CVS_B); //## 2000 mV steps 40mV
delay(60);
}
delay(10000);
return;
}
if (devPol == 'P') idelay = 10;
//intToBLE(tsd+65); // Serial.write('A'); // analogwerte =ta ##############################
isba = 0;
if (s_zen > 0) isba = s_zen * 200;
for (isb = isba; isb < 4000; isb += 400) { // 2V steps
//
MCP_D.fastWriteB(isb); //## 2000 mV steps
// Serial.println(isb);