-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
1340 lines (1063 loc) · 33.6 KB
/
main.c
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
/* ************************************************************************
*
* main part
*
* (c) 2012-2015 by Markus Reschke
* based on code from Markus Frejek and Karl-Heinz Kübbeler
*
* ************************************************************************ */
/*
* local constants
*/
/* source management */
#define MAIN_C
/*
* include header files
*/
/* local includes */
#include "config.h" /* global configuration */
#include "common.h" /* common header file */
#include "variables.h" /* global variables */
#include "HD44780.h" /* HD44780 LCD module */
#include "functions.h" /* external functions */
/*
* local variables
*/
/* programm control */
uint8_t RunsPassed; /* counter for successful measurements */
uint8_t RunsMissed; /* counter for failed/missed measurements */
/* ************************************************************************
* output found components
* ************************************************************************ */
/*
* show pinout for semiconductor
*
* required:
* - character for pin A
* - character for pin B
* - character for pin C
*/
void Show_SemiPinout(uint8_t A, uint8_t B, uint8_t C)
{
uint8_t i, j; /* counter */
unsigned char Pin[3]; /* component pins */
unsigned char ID[3]; /* component pin IDs */
/* copy probe pin numbers */
Pin[0] = Semi.A;
Pin[1] = Semi.B;
Pin[2] = Semi.C;
/* copy pin characters/IDs */
ID[0] = A;
ID[1] = B;
ID[2] = C;
/* display: 123 */
for (i = 0; i <= 2; i++)
{
LCD_ProbeNumber(i);
}
/* display: = */
LCD_Char('=');
/* display pin IDs */
for (i = 0; i <= 2; i++) /* loop through probe pins */
{
for (j = 0; j <= 2; j++) /* loop through component pins */
{
if (i == Pin[j]) /* probe pin matches */
{
LCD_Char(ID[j]); /* show ID */
}
}
}
}
/*
* show failed test
*/
void Show_Fail(void)
{
/* display info */
LCD_EEString(Failed1_str); /* display: No component */
LCD_NextLine_EEString(Failed2_str); /* display: found!*/
/* display numbers of diodes found */
if (Check.Diodes > 0) /* diodes found */
{
LCD_Space(); /* display space */
LCD_Char(Check.Diodes + '0'); /* display number of diodes found */
LCD_Space(); /* display space */
LCD_EEString(Diode_AC_str); /* display: -|>|- */
}
RunsMissed++; /* increase counter */
RunsPassed = 0; /* reset counter */
}
/*
* show error
*/
void Show_Error()
{
if (Check.Type == TYPE_DISCHARGE) /* discharge failed */
{
LCD_EEString(DischargeFailed_str); /* display: Battery? */
/* display probe number and remaining voltage */
LCD_NextLine();
LCD_ProbeNumber(Check.Probe);
LCD_Char(':');
LCD_Space();
DisplayValue(Check.U, -3, 'V');
}
}
/*
* show single (first) resistor
*
* requires:
* - ID1 pin ID character
* - ID2 pin ID character
*/
void Show_SingleResistor(uint8_t ID1, uint8_t ID2)
{
Resistor_Type *Resistor; /* pointer to resistor */
Resistor = &Resistors[0]; /* pointer to first resistor */
/* show pinout */
LCD_Char(ID1);
LCD_EEString(Resistor_str);
LCD_Char(ID2);
/* show resistance value */
LCD_Space();
DisplayValue(Resistor->Value, Resistor->Scale, LCD_CHAR_OMEGA);
}
/*
* show resistor(s)
*/
void Show_Resistor(void)
{
Resistor_Type *R1; /* pointer to resistor #1 */
Resistor_Type *R2; /* pointer to resistor #2 */
uint8_t Pin; /* ID of common pin */
R1 = &Resistors[0]; /* pointer to first resistor */
if (Check.Resistors == 1) /* single resistor */
{
R2 = NULL; /* disable second resistor */
Pin = R1->A; /* make B the first pin */
}
else /* multiple resistors */
{
R2 = R1;
R2++; /* pointer to second resistor */
if (Check.Resistors == 3) /* three resistors */
{
Resistor_Type *Rmax; /* pointer to largest resistor */
/*
* 3 resistors mean 2 single resistors and both resistors in series.
* So we have to single out that series resistor by finding the
* largest resistor.
*/
Rmax = R1; /* starting point */
for (Pin = 1; Pin <= 2; Pin++)
{
if (CmpValue(R2->Value, R2->Scale, Rmax->Value, Rmax->Scale) == 1)
{
Rmax = R2; /* update largest one */
}
R2++; /* next one */
}
/* get the two smaller resistors */
if (R1 == Rmax) R1++;
R2 = R1;
R2++;
if (R2 == Rmax) R2++;
}
/* find common pin of both resistors */
if ((R1->A == R2->A) || (R1->A == R2->B)) Pin = R1->A;
else Pin = R1->B;
}
/*
* display the pins
*/
/* first resistor */
if (R1->A != Pin) LCD_ProbeNumber(R1->A);
else LCD_ProbeNumber(R1->B);
LCD_EEString(Resistor_str);
LCD_ProbeNumber(Pin);
if (R2) /* second resistor */
{
LCD_EEString(Resistor_str);
if (R2->A != Pin) LCD_ProbeNumber(R2->A);
else LCD_ProbeNumber(R2->B);
}
/*
* display the values
*/
/* first resistor */
LCD_NextLine();
DisplayValue(R1->Value, R1->Scale, LCD_CHAR_OMEGA);
if (R2) /* second resistor */
{
LCD_Space();
DisplayValue(R2->Value, R2->Scale, LCD_CHAR_OMEGA);
}
#ifdef SW_INDUCTOR
else /* single resistor */
{
/* get inductance and display if relevant */
if (MeasureInductor(R1) == 1)
{
LCD_Space();
DisplayValue(Inductor.Value, Inductor.Scale, 'H');
}
}
#endif
}
/*
* show capacitor
*/
void Show_Capacitor(void)
{
Capacitor_Type *MaxCap; /* pointer to largest cap */
Capacitor_Type *Cap; /* pointer to cap */
#ifdef SW_ESR
uint16_t ESR; /* ESR (in 0.01 Ohms) */
#endif
uint8_t Counter; /* loop counter */
/* find largest cap */
MaxCap = &Caps[0]; /* pointer to first cap */
Cap = MaxCap;
for (Counter = 1; Counter <= 2; Counter++)
{
Cap++; /* next cap */
if (CmpValue(Cap->Value, Cap->Scale, MaxCap->Value, MaxCap->Scale) == 1)
{
MaxCap = Cap;
}
}
/* display pinout */
LCD_ProbeNumber(MaxCap->A); /* display pin #1 */
LCD_EEString(Cap_str); /* display capacitor symbol */
LCD_ProbeNumber(MaxCap->B); /* display pin #2 */
/* show capacitance */
LCD_NextLine(); /* move to next line */
DisplayValue(MaxCap->Value, MaxCap->Scale, 'F');
#ifdef SW_ESR
/* show ESR */
ESR = MeasureESR(MaxCap); /* measure ESR */
if (ESR > 0) /* if successfull */
{
// LCD_NextLine_EEString_Space(ESR_str); /* display: ESR */
LCD_Space();
DisplayValue(ESR, -2, LCD_CHAR_OMEGA); /* display ESR */
}
#endif
}
/*
* display capacitance of a diode
*
* requires:
* - pointer to diode structure
*/
void Show_Diode_Cap(Diode_Type *Diode)
{
/* sanity check */
if (Diode == NULL) return;
/* get capacitance (opposite of flow direction) */
MeasureCap(Diode->C, Diode->A, 0);
/* and show capacitance */
DisplayValue(Caps[0].Value, Caps[0].Scale, 'F');
}
/*
* show diode
*/
void Show_Diode(void)
{
Diode_Type *D1; /* pointer to diode #1 */
Diode_Type *D2 = NULL; /* pointer to diode #2 */
uint8_t CapFlag = 1; /* flag for capacitance output */
uint8_t A = 5; /* ID of common anode */
uint8_t C = 5; /* ID of common cothode */
uint8_t R_Pin1 = 5; /* B_E resistor's pin #1 */
uint8_t R_Pin2 = 5; /* B_E resistor's pin #2 */
uint16_t I_leak; /* leakage current */
D1 = &Diodes[0]; /* pointer to first diode */
/*
* figure out which diodes to display
*/
if (Check.Diodes == 1) /* single diode */
{
C = D1->C; /* make anode first pin */
}
else if (Check.Diodes == 2) /* two diodes */
{
D2 = D1;
D2++; /* pointer to second diode */
if (D1->A == D2->A) /* common anode */
{
A = D1->A; /* save common anode */
/* possible PNP BJT with low value B-E resistor and flyback diode */
R_Pin1 = D1->C;
R_Pin2 = D2->C;
}
else if (D1->C == D2->C) /* common cathode */
{
C = D1->C; /* save common cathode */
/* possible NPN BJT with low value B-E resistor and flyback diode */
R_Pin1 = D1->A;
R_Pin2 = D2->A;
}
else if ((D1->A == D2->C) && (D1->C == D2->A)) /* anti-parallel */
{
A = D1->A; /* anode and cathode */
C = A; /* are the same */
CapFlag = 0; /* skip capacitance */
}
}
else if (Check.Diodes == 3) /* three diodes */
{
uint8_t n;
uint8_t m;
/*
* Two diodes in series are additionally detected as third big diode:
* - Check for any possible way of 2 diodes be connected in series.
* - Only once the cathode of diode #1 matches the anode of diode #2.
*/
for (n = 0; n <= 2; n++) /* loop for first diode */
{
D1 = &Diodes[n]; /* get pointer of first diode */
for (m = 0; m <= 2; m++) /* loop for second diode */
{
D2 = &Diodes[m]; /* get pointer of second diode */
if (n != m) /* don't check same diode :-) */
{
if (D1->C == D2->A) /* got match */
{
n = 5; /* end loops */
m = 5;
}
}
}
}
if (n < 5) D2 = NULL; /* no match found */
C = D1->C; /* cathode of first diode */
A = 3; /* in series mode */
}
else /* to much diodes */
{
D1 = NULL; /* don't display any diode */
Show_Fail(); /* and tell user */
return;
}
/*
* display pins
*/
/* first Diode */
if (A < 3) LCD_ProbeNumber(D1->C); /* common anode */
else LCD_ProbeNumber(D1->A); /* common cathode */
if (A < 3) LCD_EEString(Diode_CA_str); /* common anode */
else LCD_EEString(Diode_AC_str); /* common cathode */
if (A < 3) LCD_ProbeNumber(A); /* common anode */
else LCD_ProbeNumber(C); /* common cathode */
if (D2) /* second diode */
{
if (A <= 3) LCD_EEString(Diode_AC_str); /* common anode or in series */
else LCD_EEString(Diode_CA_str); /* common cathode */
if (A == C) LCD_ProbeNumber(D2->A); /* anti parallel */
else if (A <= 3) LCD_ProbeNumber(D2->C); /* common anode or in series */
else LCD_ProbeNumber(D2->A); /* common cathode */
}
/* check for B-E resistor for possible BJT */
if (R_Pin1 < 5) /* possible BJT */
{
if (CheckSingleResistor(R_Pin1, R_Pin2) == 1) /* found B-E resistor */
{
/* show: PNP/NPN? */
LCD_Space();
if (A < 3) LCD_EEString(PNP_str);
else LCD_EEString(NPN_str);
LCD_Char('?');
LCD_NextLine(); /* go to line #2 */
R_Pin1 += '1'; /* convert to character */
R_Pin2 += '1';
Show_SingleResistor(R_Pin1, R_Pin2); /* show resistor */
CapFlag = 0; /* skip capacitance */
}
}
/*
* display:
* - Uf (forward voltage)
* - reverse leakage current (for single diodes)
* - capacitance (not for anti-parallel diodes)
*/
/* display Uf */
LCD_NextLine_EEString_Space(Vf_str); /* display: Vf */
/* first diode */
DisplayValue(D1->V_f, -3, 'V');
LCD_Space();
/* display low current Uf and reverse leakage current for a single diode */
if (D2 == NULL) /* single diode */
{
/* display low current Uf if it's quite low (Ge/Schottky diode) */
if (D1->V_f2 < 250)
{
LCD_Char('(');
DisplayValue(D1->V_f2, 0, 0);
LCD_Char(')');
}
/* reverse leakage current */
UpdateProbes(D1->C, D1->A, 0); /* reverse diode */
I_leak = GetLeakageCurrent(); /* get current (in µA) */
if (I_leak > 0) /* show if not zero */
{
LCD_NextLine_EEString_Space(I_R_str); /* display: I_R */
DisplayValue(I_leak, -6, 'A'); /* display current */
}
}
else /* two diodes */
{
/* show Uf of second diode */
DisplayValue(D2->V_f, -3, 'V');
}
/* display capacitance */
if (CapFlag == 1) /* if requested */
{
LCD_NextLine_EEString_Space(DiodeCap_str); /* display: C */
Show_Diode_Cap(D1); /* first diode */
LCD_Space();
Show_Diode_Cap(D2); /* second diode (optional) */
}
}
/*
* show intrinsic/freewheeling diode of transistor
*/
void Show_FlybackDiode(void)
{
LCD_Space(); /* display space */
/* first pin */
if (Check.Found == COMP_FET) /* FET */
{
LCD_Char('D'); /* drain */
}
else /* BJT/IGBT */
{
LCD_Char('C'); /* collector */
}
/* diode */
if (Check.Type & TYPE_N_CHANNEL) /* n-channel/NPN */
{
/*
* anode pointing to source/emitter
* cathode pointing to drain/collector
*/
LCD_Char(LCD_CHAR_DIODE_CA); /* |<| */
}
else /* p-channel/PNP */
{
/*
* anode pointing to drain/collector
* cathode pointing to source/emitter
*/
LCD_Char(LCD_CHAR_DIODE_AC); /* |>| */
}
/* second pin */
if (Check.Found == COMP_FET) /* FET */
{
LCD_Char('S'); /* source */
}
else /* BJT/IGBT */
{
LCD_Char('E'); /* emitter */
}
}
/*
* show BJT
*/
void Show_BJT(void)
{
Diode_Type *Diode; /* pointer to diode */
unsigned char *String; /* display string pointer */
uint8_t Counter; /* counter */
uint8_t A_Pin; /* pin acting as anode */
uint8_t C_Pin; /* pin acting as cathode */
uint16_t V_BE; /* V_BE */
int16_t Slope; /* slope of forward voltage */
/*
* Mapping for Semi structure:
* A - Base pin
* B - Collector pin
* C - Emitter pin
* U_1 - U_BE (mV)
* I_1 - I_CE0 (µA)
* F_1 - hFE
*/
/* preset stuff based on BJT type */
if (Check.Type & TYPE_NPN) /* NPN */
{
String = (unsigned char *)NPN_str; /* "NPN" */
/* direction of B-E diode: B -> E */
A_Pin = Semi.A; /* anode at base */
C_Pin = Semi.C; /* cathode at emitter */
}
else /* PNP */
{
String = (unsigned char *)PNP_str; /* "PNP" */
/* direction of B-E diode: E -> B */
A_Pin = Semi.C; /* anode at emitter */
C_Pin = Semi.A; /* cathode at base */
}
/* display type */
LCD_EEString_Space(BJT_str); /* display: BJT */
LCD_EEString(String); /* display: NPN / PNP */
/* parasitic BJT (freewheeling diode on same substrate) */
if (Check.Type & TYPE_PARASITIC)
{
LCD_Char('+');
}
LCD_NextLine(); /* move to line #2 */
/* display pinout */
Show_SemiPinout('B', 'C', 'E');
/* optional freewheeling diode */
if (Check.Diodes > 2) /* transistor is a set of two diodes :-) */
{
Show_FlybackDiode(); /* show diode */
}
LCD_NextLine(); /* next line */
/* display either optional B-E resistor or hFE & V_BE */
if (CheckSingleResistor(C_Pin, A_Pin) == 1) /* found B-E resistor */
{
Show_SingleResistor('B', 'E');
}
else /* no B-E resistor found */
{
/* hFE and V_BE */
/* display hFE */
LCD_EEString_Space(hFE_str); /* display: h_FE */
DisplayValue(Semi.F_1, 0, 0);
/* display V_BE (taken from diode forward voltage) */
Diode = &Diodes[0]; /* get pointer of first diode */
Counter = 0;
while (Counter < Check.Diodes) /* check all diodes */
{
/* if the diode matches the transistor's B-E diode */
if ((Diode->A == A_Pin) && (Diode->C == C_Pin))
{
LCD_NextLine_EEString_Space(V_BE_str); /* display: V_BE */
/*
* Vf is quite linear for a logarithmicly scaled I_b.
* So we may interpolate the Vf values of low and high test current
* measurements for a virtual test current. Low test current is 10µA
* and high test current is 7mA. That's a logarithmic scale of
* 3 decades.
*/
/* calculate slope for one decade */
Slope = Diode->V_f - Diode->V_f2;
Slope /= 3;
/* select V_BE based on hFE */
if (Semi.F_1 < 100) /* low hFE */
{
/*
* BJTs with low hFE are power transistors and need a large I_b
* to drive the load. So we simply take Vf of the high test current
* measurement (7mA).
*/
V_BE = Diode->V_f;
}
else if (Semi.F_1 < 250) /* mid-range hFE */
{
/*
* BJTs with a mid-range hFE are signal transistors and need
* a small I_b to drive the load. So we interpolate Vf for
* a virtual test current of about 1mA.
*/
V_BE = Diode->V_f - Slope;
}
else /* high hFE */
{
/*
* BJTs with a high hFE are small signal transistors and need
* only a very small I_b to drive the load. So we interpolate Vf
* for a virtual test current of about 0.1mA.
*/
V_BE = Diode->V_f2 + Slope;
}
DisplayValue(V_BE, -3, 'V');
Counter = 10; /* end loop */
}
else /* diode doesn't match */
{
Counter++; /* increase counter */
Diode++; /* next one */
}
}
}
/* I_CEO: collector emitter cutoff current (leakage) */
if (Semi.I_1 > 0) /* show if not zero */
{
LCD_NextLine_EEString_Space(I_CEO_str); /* display: I_CE0 */
DisplayValue(Semi.I_1, -6, 'A'); /* display current */
}
}
/*
* show MOSFET/IGBT extras
* - diode
* - V_th
* - Cgs
*/
void Show_FET_Extras(void)
{
/* show instrinsic/freewheeling diode */
if (Check.Diodes > 0) /* diode found */
{
Show_FlybackDiode(); /* show diode */
}
/* skip remaining stuff for depletion-mode FETs/IGBTs */
if (Check.Type & TYPE_DEPLETION) return;
/* gate threshold voltage */
if (Semi.U_2 != 0)
{
LCD_NextLine_EEString_Space(Vth_str); /* display: Vth */
DisplaySignedValue(Semi.U_2, -3, 'V'); /* display V_th in mV */
}
/* display gate-source capacitance */
LCD_NextLine_EEString_Space(GateCap_str); /* display: Cgs */
MeasureCap(Semi.A, Semi.C, 0); /* measure capacitance */
/* display value and unit */
DisplayValue(Caps[0].Value, Caps[0].Scale, 'F');
}
/*
* show FET/IGBT channel type
*/
void Show_FET_Channel(void)
{
LCD_Space(); /* display space */
/* channel type */
if (Check.Type & TYPE_N_CHANNEL) /* n-channel */
{
LCD_Char('N');
}
else /* p-channel */
{
LCD_Char('P');
}
LCD_EEString(Channel_str); /* display: -ch */
}
/*
* show FET/IGBT mode
*/
void Show_FET_Mode(void)
{
LCD_Space();
if (Check.Type & TYPE_ENHANCEMENT) /* enhancement mode */
{
LCD_EEString(Enhancement_str);
}
else /* depletion mode */
{
LCD_EEString(Depletion_str);
}
}
/*
* show FET
*/
void Show_FET(void)
{
/*
* Mapping for Semi structure:
* A - Gate pin
* B - Drain pin
* C - Source pin
* U_2 - V_th (mV)
*/
/* display type */
if (Check.Type & TYPE_MOSFET) /* MOSFET */
{
LCD_EEString(MOS_str); /* display: MOS */
}
else /* JFET */
{
LCD_Char('J'); /* display: J */
}
LCD_EEString(FET_str); /* display: FET */
/* display channel type */
Show_FET_Channel();
/* display mode for MOSFETs*/
if (Check.Type & TYPE_MOSFET) Show_FET_Mode();
/* pinout */
LCD_NextLine(); /* move to line #2 */
if (Check.Type & TYPE_SYMMETRICAL) /* symmetrical Drain and Source */
{
/* we can't distinguish D and S */
Show_SemiPinout('G', 'x', 'x'); /* show pinout */
}
else /* unsymmetrical Drain and Source */
{
Show_SemiPinout('G', 'D', 'S'); /* show pinout */
}
/* show diode, V_th and Cgs for MOSFETs */
if (Check.Type & TYPE_MOSFET) Show_FET_Extras();
}
/*
* show IGBT
*/
void Show_IGBT(void)
{
/*
* Mapping for Semi structure:
* A - Gate pin
* B - Collector pin
* C - Emitter pin
* U_2 - V_th (mV)
*/
LCD_EEString(IGBT_str); /* display: IGBT */
Show_FET_Channel(); /* display channel type */
Show_FET_Mode(); /* display mode */
LCD_NextLine(); /* move to line #2 */
Show_SemiPinout('G', 'C', 'E'); /* show pinout */
Show_FET_Extras(); /* show diode, V_th and C_GE */
}
/*
* show special components like Thyristor and Triac
*/
void Show_Special(void)
{
/*
* Mapping for Semi structure:
* A - Gate pin
* B - Anode/MT2 pin
* C - Cathode/MT1 pin
* U_1 - V_GT (mV)
*/
/* display component type any pinout */
if (Check.Found == COMP_THYRISTOR) /* SCR */
{
LCD_EEString(Thyristor_str); /* display: thyristor */
LCD_NextLine(); /* move to line #2 */
Show_SemiPinout('G', 'A', 'C'); /* display pinout */
}
else /* Triac */
{
LCD_EEString(Triac_str); /* display: triac */
LCD_NextLine(); /* move to line #2 */
Show_SemiPinout('G', '2', '1'); /* display pinout */
}
/* show V_GT (gate trigger voltage) */
if (Semi.U_1 > 0) /* show if not zero */
{
LCD_NextLine_EEString_Space(V_GT_str); /* display: V_GT */
DisplayValue(Semi.U_1, -3, 'V'); /* display V_GT in mV */
}
}
/* ************************************************************************
* the one and only main()
* ************************************************************************ */
/*
* main function
*/
int main(void)
{
uint16_t U_Bat; /* voltage of power supply */
uint8_t Test; /* test value */
/*
* init
*/
/* switch on power to keep me alive */
CONTROL_DDR = (1 << POWER_CTRL); /* set pin as output */
CONTROL_PORT = (1 << POWER_CTRL); /* set pin to drive power management transistor */
/* setup MCU */
MCUCR = (1 << PUD); /* disable pull-up resistors globally */
ADCSRA = (1 << ADEN) | ADC_CLOCK_DIV; /* enable ADC and set clock divider */
#ifdef HW_RELAY
/* init relay (safe mode) */
/* ADC_PORT should be 0 */
ADC_DDR = (1 << TP_REF); /* short circuit probes */
#endif
/* catch watchdog */
Test = (MCUSR & (1 << WDRF)); /* save watchdog flag */
MCUSR &= ~(1 << WDRF); /* reset watchdog flag */
wdt_disable(); /* disable watchdog */
/* init LCD module */
LCD_BusSetup(); /* setup bus */
LCD_Init(); /* initialize LCD */
LCD_NextLine_Mode(MODE_NONE); /* reset line mode */
/*
* watchdog was triggered (timeout 2s)
* - This is after the MCU done a reset driven by the watchdog.
* - Does only work if the capacitor at the base of the power management
* transistor is large enough to survive a MCU reset. Otherwise the
* tester simply loses power.
*/
if (Test)
{
LCD_Clear(); /* display was initialized before */
LCD_EEString(Timeout_str); /* display: timeout */
LCD_NextLine_EEString(Error_str); /* display: error */
MilliSleep(2000); /* give user some time to read */
CONTROL_PORT = 0; /* power off myself */
return 0; /* exit program */
}
/*
* operation mode selection
*/
Config.SleepMode = SLEEP_MODE_PWR_SAVE; /* default: power save */
UI.TesterMode = MODE_CONTINOUS; /* set default mode: continous */
Test = 0; /* key press */
/* catch long key press */
if (!(CONTROL_PIN & (1 << TEST_BUTTON))) /* if test button is pressed */
{