-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckPins.ino
1469 lines (1425 loc) · 59.5 KB
/
CheckPins.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
//#include <avr/io.h>
//#include <stdlib.h>
//#include "Transistortester.h"
//#include "Makefile.h" //J-L
#ifdef FET_Idss
uint16_t expand_FET_quadratic(uint16_t v0, uint16_t v1, uint16_t ii)
// assuming a datapoint of Vgs=v1, Id=ii, tries to calculate Idss (i.e., Id at Vgs=0)
// v0 must be the Vgs at which Id=0
{
// Quadratic current curve can be calculated by:
// v1 = v0 - v1;
// return (uint32_t)((uint16_t)((uint32_t)(ii * v0) / v1) * v0) / v1;
// But this simpler code need 100 bytes more flash than the following code!
uint8_t drv, dri; // needed for rounding
v1 = v0 - v1;
drv = 0;
dri = 0;
for (;;) {
uint8_t dv, di;
dv = (v1 + drv) >> 8;
drv = (v1 + drv) & 0xff; // remainder of voltage division by 256
// if (dv == 0) dv = 1; // prevent infinite loop
v1 += dv; // increase v by 0.4 %; unfortunately the compiler doesn't do this very smartly, insists on creating a 16-bit temporary variable for d
di = (ii + dri) >> 8;
dri = (ii + dri) & 0xff; // remainder of current division by 256
ii += di;
ii += di; // increase ii by 0.8 %
if (di > (60000>>8)) {
return 0;
}
// no Idss measurement if Idss exceeds 40 mA, the ATmega's maximum pin current
// note that this is actually quite safe, since by the time there's 40 mA running, the Vgs will be 40mA * 20 ohm = 0.8 V, so quite far from 0, so Id will be less than those 40 mA
if (v1 > v0) return ii; // V exceeds Vp, so we've reached Vgs=0 without Id exceeding 40 mA, so we can safely do the Idss measurement
}
}
#endif
//******************************************************************
void CheckPins(uint8_t HighPin, uint8_t LowPin, uint8_t TristatePin)
{
/*
Function for checking the characteristic of a component with the following pin assignment
parameters:
HighPin: Pin, which will be switched to VCC at the beginning
LowPin: Pin, which will be switch to GND at the beginning
TristatePin: Pin, which will be undefined at the beginning
TristatePin will be switched to GND and VCC also .
*/
struct {
unsigned int lp_otr;
unsigned int lp_otrh;
unsigned int vCEs;
unsigned int hp1;
unsigned int hp2;
unsigned int hp3;
unsigned int hp4;
unsigned int rhp;
unsigned int lp1;
unsigned int lp2;
unsigned int tp1;
unsigned int tp2;
unsigned int rtp;
}adc;
uint8_t LoPinRL; // mask to switch the LowPin with R_L
#if FLASHEND > 0x1fff
uint8_t LoPinRH; // mask to switch the LowPin with R_H
#endif
uint8_t TriPinRL; // mask to switch the TristatePin with R_L
uint8_t TriPinRH; // mask to switch the TristatePin with R_H
uint8_t HiPinRL; // mask to switch the HighPin with RL
uint8_t HiPinRH; // mask to switch the HighPin with R_H
uint8_t HiADCp; // mask to switch the ADC port High-Pin
uint8_t LoADCp; // mask to switch the ADC port Low-Pin
#ifdef SHOW_R_DS
uint8_t TriADCp; // mask to switch the ADC port Tristate-Pin
#endif
uint8_t HiADCm; // mask to switch the ADC DDR port High-Pin
uint8_t LoADCm; // mask to switch the ADC DDR port Low-Pin
uint8_t PinMSK;
uint8_t update_pins; // flag for updating the trans.ebc pins, 1=update
uint8_t ii; // temporary variable
unsigned int tmp16; // temporary variable
const uint8_t *addr;
#ifdef COMMON_EMITTER
unsigned long e_hfe; // current amplification factor with common emitter
#else
#warning "hFE measurement without common emitter circuit"
#endif
#ifndef COMMON_COLLECTOR
#warning "hFE measurement without common collector circuit"
#endif
#ifdef COMMON_COLLECTOR
unsigned long c_hfe; // amplification factor for common Collector (Emitter follower)
#endif
unsigned int volt_dif;
/*
switch HighPin directls to VCC
switch R_L port for LowPin to GND
TristatePin remains switched to input , no action required
*/
wdt_reset();
addr = &PinRLRHADCtab[LowPin-TP_MIN]; // Address of combined RL / RH / ADC pin table
LoPinRL = pgm_read_byte(addr); // instruction for LowPin R_L
#if FLASHEND > 0x1fff
#if (((PIN_RL1 + 1) != PIN_RH1) || ((PIN_RL2 + 1) != PIN_RH2) || ((PIN_RL3 + 1) != PIN_RH3))
addr += 3; // address of PinRHtab[LowPin]
LoPinRH = pgm_read_byte(addr); // instruction for LowPin R_H
#else
LoPinRH = LoPinRL + LoPinRL; // instruction for LowPin R_H
#endif
addr += 3; // address of PinADCtab[LowPin]
#else // LoPinRH not used for ATmega8
#if (((PIN_RL1 + 1) != PIN_RH1) || ((PIN_RL2 + 1) != PIN_RH2) || ((PIN_RL3 + 1) != PIN_RH3))
addr += 6; // address of PinADCtab[LowPin]
#else
addr += 3; // address of PinADCtab[LowPin], table PinRHtab is missing
#endif
#endif
LoADCp = pgm_read_byte(addr); // instruction for ADC Low-Pin, including | TXD_VAL
addr = &PinRLRHADCtab[TristatePin-TP_MIN];
TriPinRL = pgm_read_byte(addr); // instruction for TristatePin R_L
#if (((PIN_RL1 + 1) != PIN_RH1) || ((PIN_RL2 + 1) != PIN_RH2) || ((PIN_RL3 + 1) != PIN_RH3))
addr += 3; // address of PinRLtab[TristatePin]
TriPinRH = pgm_read_byte(addr); // instruction for TristatePin R_H
#else
TriPinRH = TriPinRL + TriPinRL; // instruction for TristatePin R_H
#endif
#ifdef SHOW_R_DS
addr += 3; // address of PinADCtab[TristatePin]
TriADCp = pgm_read_byte(addr); // instruction for ADC Tristate-Pin, including | TXD_VAL
#endif
addr = &PinRLRHADCtab[HighPin-TP_MIN];
HiPinRL = pgm_read_byte(addr); // instruction for HighPin R_L
#if (((PIN_RL1 + 1) != PIN_RH1) || ((PIN_RL2 + 1) != PIN_RH2) || ((PIN_RL3 + 1) != PIN_RH3))
addr += 3; // address of PinRHtab[HighPin]
HiPinRH = pgm_read_byte(addr); // instruction for HighPin R_H
#else
HiPinRH = HiPinRL + HiPinRL; // instruction for HighPin R_H
#endif
addr += 3; // address of PinADCtab[HighPin]
HiADCp = pgm_read_byte(addr); // instruction for ADC High-Pin, including | TXD_VAL
HiADCm = HiADCp | TXD_MSK;
LoADCm = LoADCp | TXD_MSK;
//setting of Pins
#if (PROCESSOR_TYP != 8)
#define EXACT_OTR
// with option EXACT_OTR the vCE0 and vCEs is determined with common emitter circuit for
// PNP and NPN transistors. Without this option set the circuit is common emitter for PNP and
// common collector for NPN.
#endif
#ifndef EXACT_OTR
R_PORT = 0; //resistor-Port outputs to 0
R_DDR = LoPinRL; //Low-Pin to output and across R_L to GND
ADC_DDR = HiADCm; //High-Pin to output
ADC_PORT = HiADCp; //High-Pin fix to Vcc
//for some MOSFET the gate (TristatePin) must be discharged
R_DDR = LoPinRL | TriPinRL;
adc.vCEs = W5msReadADC(LowPin); // lp1 is the voltage at 680 Ohm with - Gate
R_DDR = LoPinRL;
adc.lp_otr = W5msReadADC(LowPin); //read voltage of Low-Pin , without Gate current (-)
R_DDR = 0;
wait5ms(); // release all current (clear TRIAC and Thyristor)
R_PORT = TriPinRL;
R_DDR = LoPinRL | TriPinRL; // start current again
adc.lp2 = W5msReadADC(LowPin); // lp2 is the voltage at 680 Ohm with + Gate
R_DDR = LoPinRL;
R_PORT = 0;
if (adc.lp2 < adc.vCEs) {
adc.lp_otr = W5msReadADC(LowPin); //read voltage of Low-Pin again, without Gate current (+)
if ((adc.lp2+288) > adc.vCEs) goto checkDiode; // no significant change
adc.vCEs = adc.lp2;
} else {
if ((adc.vCEs+288) > adc.lp2) goto checkDiode; // no significant change
}
#else
// first try the common emitter circuit for P-Channel type
uint16_t v_change_n;
uint16_t v_change_p;
R_PORT = TriPinRL; //resistor-Port TriState to 1
R_DDR = LoPinRL | TriPinRL; // resistor-Port Low-Pin to 0
ADC_DDR = HiADCm; //High-Pin to output
ADC_PORT = HiADCp; //High-Pin fix to Vcc
//for some MOSFET the gate (TristatePin) must be discharged
adc.vCEs = W5msReadADC(LowPin); // lp1 is the voltage at 680 Ohm with + Gate
#ifdef WITH_PUT
R_PORT = TriPinRL | TriPinRH;
R_DDR = LoPinRL | TriPinRH;
adc.lp_otrh = W5msReadADC(LowPin); //read voltage of Low-Pin , with tri-state ping to plus via RH; prevents accidental triggering of PUT
#endif
R_DDR = LoPinRL; // resistor-Port Low-Pin to 0
adc.lp_otr = W5msReadADC(LowPin); //read voltage of Low-Pin , without Gate current (+)
R_DDR = 0;
wait10ms(); // release all current (clear TRIAC and Thyristor)
R_PORT = 0;
R_DDR = LoPinRL | TriPinRL; // start current again
adc.lp2 = W5msReadADC(LowPin); // lp2 is the voltage at 680 Ohm with - Gate
v_change_p = abs_diff(adc.lp2, adc.vCEs);
// switch to common emitter for NPN or N-channel FET
ADC_DDR = LoADCm; //Low-Pin to output
ADC_PORT = TXD_VAL; //Low-Pin fix to GND
R_PORT = HiPinRL | TriPinRL;
R_DDR = HiPinRL | TriPinRL; // resistor-Port High-Pin and TriState-Pin to 1
adc.hp1 = vcc_diff(W5msReadADC(HighPin)); // voltage at 680 Ohm with + Gate
R_PORT = 0; // clear Thyristor
wait10ms(); // release all current (clear TRIAC and Thyristor)
R_PORT = HiPinRL; //resistor-Port High-Pin to +, TriState to 0
adc.hp2 = vcc_diff(W5msReadADC(HighPin)); // voltage at 680 Ohm with - Gate
R_DDR = HiPinRL; // resistor-Port High-Pin to 1, TriState open
adc.hp3 = vcc_diff(W5msReadADC(HighPin)); // voltage at 680 Ohm with open Gate
v_change_n = abs_diff(adc.hp1, adc.hp2);
#if DebugOut == 5
lcd_clear_line2();
lcd_data('T');
lcd_data('T');
lcd_testpin(LowPin);
lcd_data(',');
lcd_testpin(HighPin);
lcd_space();
lcd_data('-');
mVOut(adc.vCEs);
lcd_data('o');
mVOut(adc.lp_otr);
lcd_data('+');
mVOut(adc.lp2);
lcd_data('o');
lcd_data('h');
mVOut(adc.lp_otrh);
lcd_line3();
lcd_data('-');
mVOut(adc.hp2);
lcd_data('o');
mVOut(adc.hp3);
lcd_data('+');
mVOut(adc.hp1);
#endif
#if 0
// if (adc.lp2 < adc.vCEs) {
if (adc.lp2 < (adc.vCEs+288)) {
// current is lower with Gate switched to 0
// if ((adc.lp2+288) > adc.vCEs) goto checkDiode; // no significant change
// if ((adc.lp2+288) > adc.vCEs) goto checkDiode; // no significant change
if (abs_diff(adc.hp1, adc.vCEs) < 288) goto checkDiode; // no significant change
#ifdef WITH_PUT
adc.lp_otrh = adc.lp_otr;
#endif
} else {
// if ((adc.vCEs+288) > adc.lp2) goto checkDiode; // no significant change
if (abs_diff(adc.lp2, adc.vCEs) < 288) goto checkDiode; // no significant change
}
#endif
if ((v_change_n < 288) && (v_change_p < 288)) goto checkDiode; // no significant change
// if ((v_change_n+150) > (v_change_p + adc.hp3))
if ((adc.hp2 + v_change_p) < (adc.vCEs + v_change_n))
{
#if DebugOut == 5
lcd_data('c');
lcd_data('N');
#endif
adc.vCEs = adc.hp2; // voltage at + 680 Ohm with - Gate
adc.lp_otr = adc.hp3; // voltage at + 680 Ohm with open Gate
}
#endif
// ChargePin10ms(TriPinRL,0); //discharge for N-Kanal
// adc.lp_otr = W5msReadADC(LowPin); //read voltage of Low-Pin
// if(adc.lp_otr >= 977) { //no current now?
// ChargePin10ms(TriPinRL,1); //else: discharge for P-channel (Gate to VCC)
// adc.lp_otr = ReadADC(LowPin); //read voltage of Low-Pin again
// }
#if DebugOut == 5
lcd_clear_line2();
#endif
update_pins = 1; // if a part is found, always update the pins
// the tester will never find more that two transistors
// a TRIAC is marked as two transistors at least (2 or 3)
// both of NPN transistors (normal and inverse) are found, if ntrans.count == 2
// both of PNP transistors (normal and inverse) are found, if ptrans.count == 2
// If Transistor with protection diode is checked, all results are found,
// if ntrans.count == 1 and ptrans.count == 1
if ((ntrans.count + ptrans.count) > 1) {
// all transistors found, no more search is needed
// but TRIAC can be detected as NPNp with same pins as PNPn
if (!((ntrans.count == 1) && (ntrans.b == ptrans.b))) {
goto checkDiode;
}
}
// if(adc.lp_otr > 92) { //there is some current without TristatePin current
// Look for Source/Drain current without gate current.
// Germanium transistors have also high collector current with higher temperature.
// But this current is lower, if the base is hold at emitter level (adc.hp1).
// Additional checking of adc.lp1 will prevent to detect a PNP as P-JFET.
// if((PartMode <= PART_MODE_P_JFET) && (adc.lp_otr > 455) && (adc.vCEs > 455))
// if((adc.lp_otr > 455) && (adc.vCEs > 455))
// if((adc.vCEs > 115) && ((adc.vCEs+100) > adc.lp_otr))
if((adc.vCEs > 115) && ((adc.vCEs+adc.vCEs+20) > adc.lp_otr))
{ //there is more than 650uA current without TristatePin current
// can be JFET or D-FET
//Test if N-JFET or if self-conducting N-MOSFET
#ifdef EXACT_OTR
ADC_DDR = HiADCm; //High-Pin to output
ADC_PORT = HiADCp; //High-Pin fix to Vcc
#endif
R_DDR = LoPinRL | TriPinRH; //switch R_H for Tristate-Pin (probably Gate) to GND
adc.lp1 = W10msReadADC(LowPin); //measure voltage at the assumed Source
adc.tp1 = ReadADC(TristatePin); // measure Gate voltage
R_PORT = TriPinRH; //switch R_H for Tristate-Pin (probably Gate) to VCC
adc.lp2 = W10msReadADC(LowPin); //measure voltage at the assumed Source again
#if DebugOut == 5
lcd_testpin(LowPin);
lcd_data('f');
lcd_testpin(HighPin);
lcd_space();
mVOut(adc.lp2);
mVOut(adc.lp1);
lcd_line3();
mVOut(adc.vCEs);
mVOut(adc.lp_otr);
#endif
//If it is a self-conducting MOSFET or JFET, then must be: adc.lp2 > adc.lp1
if(adc.lp2>(adc.lp1+599)) {
//measure voltage at the Gate, differ between MOSFET and JFET
ADC_PORT = TXD_VAL;
ADC_DDR = LoADCm; //Low-Pin fix to GND
R_DDR = TriPinRH | HiPinRL; //High-Pin to output
R_PORT = TriPinRH | HiPinRL; //switch R_L for High-Pin to VCC
adc.lp2 = W10msReadADC(TristatePin); //read voltage of assumed Gate
#if DebugOut == 5
lcd_data('N');
#endif
if(adc.lp2>3911) { //MOSFET
PartFound = PART_FET; //N-Kanal-MOSFET
PartMode = PART_MODE_MOS|N_CHANNEL|D_MODE; //Depletion-MOSFET
#if DebugOut == 5
lcd_data('D');
#endif
} else { //JFET (pn-passage between Gate and Source is conducting )
PartFound = PART_FET; //N-Kanal-JFET
PartMode = PART_MODE_JFET|N_CHANNEL|D_MODE;
#if DebugOut == 5
lcd_data('J');
#endif
}
#if DebugOut == 5
lcd_space();
#endif
// if ((PartReady == 0) || (adc.lp1 > ntrans.uBE))
// there is no way to find out the right Source / Drain
ntrans.uBE = adc.lp1;
ntrans.gthvoltage = unsigned_diff(adc.lp1, adc.tp1); //voltage GS (Source - Gate)
ntrans.current = (unsigned int)(((unsigned long)adc.lp1 * 10000) / RR680MI); // Id 1uA
#ifdef SHOW_ICE
// Test for cutoff Voltage, idea from Pieter-Tjerk
R_DDR = LoPinRH | TriPinRH;
R_PORT = 0; // Low + Tristate Pin with 470k to 0V
ADC_DDR = HiADCm;
ADC_PORT = HiADCp; // High Pin to VCC
ntrans.ice0 = unsigned_diff(W10msReadADC(LowPin), ReadADC(TristatePin)); // Gate-Source Voltage
#ifdef FET_Idss
#if DebugOut == 5
lcd_line4();
lcd_data('N');
lcd_data('j');
lcd_space();
#endif
if ((PartMode&0x0f) == PART_MODE_JFET)
{
uint16_t i16;
// extrapolate the quadratic relationship between Id and Vgs, to estimate Idss
i16 = expand_FET_quadratic(ntrans.ice0,ntrans.gthvoltage,ntrans.current);
#if DebugOut == 5
DisplayValue(i16,-6,' ',3);
#endif
// i16=0 if estimated Idss would exceed 40 mA, so don't measure then
if (i16 != 0) {
// R_PORT = 0;
R_DDR = TriPinRH; // gate to ground via RH
// ADC_PORT = HiADCp; // drain to Vcc, source to gnd, both without resistors
ADC_DDR = HiADCm|LoADCp;
adc.lp2 = W10msReadADC(LowPin); //measure voltage at the Source; this is the voltage drop across the pin's ~20 ohm internal resistance!
ADC_DDR = TXD_MSK; // disconnect drain and source immediately after measurement, since quite a lot of current may flow
// this is almost the Idss, since the gate-source voltage is almost 0 (only the voltage drop across that 20 ohm resistance)
i16 = (unsigned int)(((unsigned long)adc.lp2 * 10000) / pin_rmi); // Idss 1uA
#if DebugOut == 5
DisplayValue(i16,-6,' ',3);
#endif
i16 = expand_FET_quadratic(ntrans.ice0,adc.lp2,i16);
#if DebugOut == 5
DisplayValue(i16,-6,' ',3);
#endif
}
ntrans.uBE = i16;
}
#endif
#ifdef SHOW_R_DS
if ((PartMode&0x0f) != PART_MODE_JFET)
{
// For depletion MOSFET we try to put the Gate to the same level as Source.
// The source level is higher than 0V because of the Port output resistance and current.
// When the Drain-Source resistance is low, we can get nearly the same voltage increase
// at the Gate with current from the 680 Ohm Port (RL).
ADC_PORT = TXD_VAL;
ADC_DDR = LoADCm | TriADCp; //Low-Pin and Tristate-Pin fix to GND
// R_DDR = TriPinRL | HiPinRL; // L-Resistor High-Pin and Tristate-Pin to output
R_DDR = HiPinRL; // L-Resistor High-Pin and Tristate-Pin to output
R_PORT = TriPinRL | HiPinRL; //switch R_L for High-Pin and Tristate-Pin to VCC
adc.hp2 = W5msReadADC(HighPin); //measure the voltage at the Drain
adc.rhp = vcc_diff(adc.hp2); // voltage at the Drain resistor
adc.lp2 = ReadADC(LowPin); // voltage at the Source
ntrans.uBE = RR680PL * (unsigned long)unsigned_diff(adc.hp2, adc.lp2) / adc.rhp; // DS resistance in 0.1 OHm
}
#endif
#endif /* end SHOW_ICE */
#if DebugOut == 5
lcd_data('#');
#endif
ntrans.count++; // count as two, the inverse is identical
goto saveNresult; // save Pin numbers and exit
} /* end selfconducting N-channel mode */
ADC_PORT = TXD_VAL; // direct outputs to GND
//Test, if P-JFET or if self-conducting P-MOSFET
ADC_DDR = LoADCm; //switch Low-Pin (assumed Drain) direct to GND,
//R_H for Tristate-Pin (assumed Gate) is already switched to VCC
R_DDR = TriPinRH | HiPinRL; //High-Pin to output
R_PORT = TriPinRH | HiPinRL; //High-Pin across R_L to Vcc
adc.hp1 = W10msReadADC(HighPin); //measure voltage at assumed Source
adc.tp1 = ReadADC(TristatePin); // measure Gate voltage
R_PORT = HiPinRL; //switch R_H for Tristate-Pin (assumed Gate) to GND
adc.hp2 = W10msReadADC(HighPin); //read voltage at assumed Source again
//if it is a self-conducting P_MOSFET or P-JFET , then must be: adc.hp1 > adc.hp2
if(adc.hp1>(adc.hp2+599)) {
//read voltage at the Gate , to differ between MOSFET and JFET
ADC_PORT = HiADCp; //switch High-Pin directly to VCC
ADC_DDR = HiADCm; //switch High-Pin to output
adc.tp2 = W10msReadADC(TristatePin); //read voltage at the assumed Gate
#if DebugOut == 5
lcd_data('P');
#endif
if(adc.tp2<977) { //MOSFET
PartFound = PART_FET; //P-Kanal-MOSFET
PartMode = PART_MODE_MOS|P_CHANNEL|D_MODE; //Depletion-MOSFET
#if DebugOut == 5
lcd_data('D');
#endif
} else { //JFET (pn-passage between Gate and Source is conducting)
PartFound = PART_FET; //P-Kanal-JFET
PartMode = PART_MODE_JFET|P_CHANNEL|D_MODE;
#if DebugOut == 5
lcd_data('J');
#endif
}
#if DebugOut == 5
lcd_space();
#endif
ptrans.gthvoltage = unsigned_diff(adc.tp1, adc.hp1); //voltage GS (Gate - Source)
ptrans.current = (unsigned int)(((unsigned long)vcc_diff(adc.hp1) * 10000) / RR680PL); // Id 1uA
#ifdef SHOW_ICE
// Test for cutoff Voltage, idea from Pieter-Tjerk
ADC_PORT = TXD_VAL; // direct outputs to GND
ADC_DDR = LoADCm; //switch Low-Pin (assumed Drain) direct to GND,
R_DDR = TriPinRH | HiPinRH; //High-Pin to output
R_PORT = TriPinRH | HiPinRH; //High-Pin and Tristate-Pin across R_H to Vcc
ptrans.ice0 = unsigned_diff(W10msReadADC(TristatePin), ReadADC(HighPin)); //measure voltage at assumed Source
#ifdef FET_Idss
#if DebugOut == 5
lcd_line4();
lcd_data('P');
lcd_data('J');
#endif
if ((PartMode&0x0f) == PART_MODE_JFET)
{
uint16_t i16;
// extrapolate the quadratic relationship between Id and Vgs, to estimate Idss
i16 = expand_FET_quadratic(ptrans.ice0,ptrans.gthvoltage,ptrans.current);
#if DebugOut == 5
DisplayValue(i16,-6,' ',3);
#endif
// i16=0 if estimated Idss would exceed 40 mA, so don't measure then
if (i16 != 0) {
R_PORT = TriPinRH;
R_DDR = TriPinRH; // gate to VCC via RH
ADC_PORT = HiADCp; // drain to GND, source to VCC, both without resistors
ADC_DDR = HiADCm|LoADCm;
adc.hp3 = vcc_diff(W10msReadADC(HighPin)); //measure voltage at the Source; this is the voltage drop across the pin's ~20 ohm internal resistance!
ADC_DDR = TXD_MSK; // disconnect drain and source immediately after measurement, since quite a lot of current may flow
// this is almost the Idss, since the gate-source voltage is almost 0 (only the voltage drop across that 20 ohm resistance)
i16 = (unsigned int)(((unsigned long)adc.hp3 * 10000) / pin_rpl); // Idss 1uA
#if DebugOut == 5
DisplayValue(i16,-6,' ',3);
#endif
i16 =expand_FET_quadratic(ptrans.ice0,adc.hp3,i16);
#if DebugOut == 5
DisplayValue(i16,-6,' ',3);
#endif
}
ptrans.uBE = i16;
} /* end if ((PartMode&0x0f) == PART_MODE_JFET) */
#endif
#ifdef SHOW_R_DS
if ((PartMode&0x0f) != PART_MODE_JFET)
{
// For depletion MOSFET we try to put the Gate to the same level as Source.
// The source level is higher than 0V because of the Port output resistance and current.
// When the Drain-Source resistance is low, we can get nearly the same voltage increase
// at the Gate with current from the 680 Ohm Port (RL).
ADC_PORT = HiADCp | TriADCp; //switch High-Pin and Tristate-Pin to VCC
ADC_DDR = HiADCm | TriADCp; //switch High-Pin and Tristate-Pin to output
R_PORT = 0; // switch R-Ports to 0
R_DDR = TriPinRL | HiPinRL; // L-Resistor High-Pin and Tristate-Pin to output
adc.hp2 = W5msReadADC(HighPin); //measure the voltage at the Source
adc.lp1 = ReadADC(LowPin); // voltage at the Drain
ptrans.uBE = RR680MI * (unsigned long)unsigned_diff(adc.hp2, adc.lp1) / adc.lp1; // DS resistance in 0.1 OHm
} /* end if ((PartMode&0x0f) != PART_MODE_JFET) */
#endif
#endif
ptrans.count++; // count as two, the inverse is identical
goto savePresult; // save pin numbers and exit
}
// no JFET or D-MOS
goto checkDiode;
} // end component has current without TristatePin signal
//there is less than 650uA current without TristatePin current
#ifdef COMMON_COLLECTOR
// Test circuit with common collector (Emitter follower) PNP
ADC_PORT = TXD_VAL;
ADC_DDR = LoADCm; // Collector direct to GND
#if 0
R_PORT = HiPinRL; // switch R_L port for HighPin (Emitter) to VCC
R_DDR = TriPinRL | HiPinRL; // Base resistor R_L to GND
adc.hp1 = W5msReadADC(HighPin); // voltage at the Emitter resistor
adc.rhp = vcc_diff(adc.hp1); // voltage at the Emitter resistor
adc.tp1 = ReadADC(TristatePin); // voltage at the base resistor (RL)
#if DebugOut == 5
lcd_line4();
lcd_data('P');
#endif
// #############################################################
if (adc.tp1 < 10) {
R_DDR = 0;
wait_about5ms(); // clear TRIAC and Thyristor
// c_hfe with 1% resolution for optocoupler
// compute c_hfe with RH base resistor
#ifdef LONG_HFE
#if DebugOut == 5
lcd_data('H'); // PHcc
#endif
c_hfe = ((unsigned long)adc.rhp * (unsigned long)(((unsigned long)R_H_VAL * 10000) /
(unsigned int)RR680PL)) / (unsigned int)adc.tp1;
#else
#if DebugOut == 5
lcd_data('h'); // Phcc
#endif
c_hfe = ((adc.rhp / ((RR680PL+500)/1000)) * (R_H_VAL/500)) / (adc.tp1/5);
#endif
} else {
#if DebugOut == 5
lcd_data('L'); // PLcc
#endif
// compute c_hfe with RL Base resistor
c_hfe = (unsigned long)((unsigned long)unsigned_diff(adc.rhp, adc.tp1) * 100) / adc.tp1;
}
#else
R_PORT = HiPinRL; // switch R_L port for HighPin (Emitter) to VCC
R_DDR = TriPinRH | HiPinRL; // Tripin=RH-
adc.hp1 = W5msReadADC(HighPin);
adc.rhp = vcc_diff(adc.hp1); // voltage at the Emitter resistor
adc.tp1 = ReadADC(TristatePin); // voltage at base resistor
#if DebugOut == 5
lcd_line4();
lcd_data('P');
#endif
if (adc.rhp > (100+adc.lp_otr)) {
tmp16 = unsigned_diff(adc.rhp, adc.lp_otr); // subtract residual current
#ifdef LONG_HFE
#if DebugOut == 5
lcd_data('H'); // PHcc
#endif
c_hfe = ((unsigned long)tmp16 * (unsigned long)(((unsigned long)R_H_VAL * 10000) /
(unsigned int)RR680PL)) / (unsigned int)adc.tp1;
#else
#if DebugOut == 5
lcd_data('h'); // Phcc
#endif
c_hfe = ((tmp16 / ((RR680PL+500)/1000)) * (R_H_VAL/500)) / (adc.tp1/5);
#endif
} else {
tmp16 = unsigned_diff(adc.rhp, adc.lp_otr);
R_DDR = TriPinRL | HiPinRL; // Base resistor R_L to GND
adc.hp1 = W5msReadADC(HighPin); // voltage at the Emitter resistor
adc.rhp = vcc_diff(adc.hp1); // voltage at the Emitter resistor
adc.tp1 = ReadADC(TristatePin); // voltage at the base resistor (RL)
#if DebugOut == 5
lcd_data('L'); // PLcc
#endif
// compute c_he with RL Base resistor
c_hfe = (unsigned long)((unsigned long)unsigned_diff(tmp16, adc.tp1) * 100) / adc.tp1;
}
#endif
#if DebugOut == 5
lcd_data('c');
lcd_data('c');
lcd_space();
lcd_data('e');
mVOut(adc.rhp);
lcd_data('o');
mVOut(adc.lp_otr);
lcd_data('b');
mVOut(adc.tp1);
lcd_data('B');
lcd_data('=');
DisplayValue(c_hfe,-2,' ',3);
#endif
#endif /* COMMON_COLLECTOR */
//set Pins again for circuit with common Emitter PNP
R_DDR = 0; //all Resistor Ports to Input
R_PORT = 0; //switch all resistor ports to GND
ADC_PORT = HiADCp; //switch High-Pin to VCC
ADC_DDR = HiADCm; //switch High-Pin to output
// R_DDR = LoPinRL; //switch R_L port for Low-Pin to output (GND)
wait_about5ms();
#ifndef WITH_PUT
// if(adc.lp_otr < 1977)
#else
// if(adc.lp_otrh < 1977)
#endif
{
//if the component has no connection between HighPin and LowPin
#if DebugOut == 5
lcd_line4();
lcd_testpin(LowPin);
lcd_data('E');
lcd_testpin(HighPin);
lcd_space();
#endif
//Test to PNP
R_DDR = LoPinRL | TriPinRL; //switch R_L port for Tristate-Pin to output (GND), for Test of PNP
adc.lp1 = W5msReadADC(LowPin); //measure voltage at LowPin
if(adc.lp1 > 3422) {
//component has current => PNP-Transistor or equivalent
// R_DDR = 0;
// wait_about5ms(); // clear TRIAC and Thyristor
//compute current amplification factor in both directions
//#if FLASHEND > 0x1fff
// R_DDR = LoPinRL | TriPinRL; //switch R_L port for Tristate-Pin (Base) to output (GND)
// wait_about5ms(); // load gate capacitor
// R_DDR = LoPinRL | TriPinRH; //switch R_H port for Tristate-Pin (Base) to output (GND)
// adc.lp1 = W5msReadADC(LowPin); //measure voltage at LowPin (assumed Collector)
//#else
R_DDR = LoPinRL | TriPinRH; //switch R_H port for Tristate-Pin (Base) to output (GND)
adc.lp1 = W10msReadADC(LowPin); //measure voltage at LowPin (assumed Collector)
//#endif
adc.tp2 = ReadADC(TristatePin); //measure voltage at TristatePin (Base)
adc.hp2 = ReadADC(HighPin); //measure voltage at HighPin (assumed Emitter)
if(adc.tp2 > 2000) {
#ifdef WITH_PUT
// most likely it's a PNP transistor, but it might be a PUT (Programmable Unijunction Transistor)
// to check this, make Tri-Pin (assumed base) high again; PNP will stop conducting, PUT won't
R_PORT = TriPinRH;
tmp16 = W10msReadADC(LowPin); //measure voltage at LowPin (assumed Collector)
if ((tmp16 >= 1024) && (PartFound < PART_TRANSISTOR)) {
// compiler could optimize this to an 8-bit compare, but doesn't :-(
#if DebugOut == 5
lcd_data('P');
lcd_data('U');
lcd_data('T');
lcd_space();
mVOut(tmp16);
#endif
// still conducts, can't be a PNP
PartFound = PART_PUT;
ptrans.uBE = unsigned_diff(adc.hp2, adc.tp2); // "Offset Voltage"
goto savePresult;
}
#endif
//PNP-Transistor is found (Base voltage moves with Emitter to VCC)
PartFound = PART_TRANSISTOR;
PartMode = PART_MODE_PNP;
update_pins = 0; // only update pins, if hFE is higher or Thyristor
#ifdef COMMON_EMITTER
//compute current amplification factor for circuit with common Emitter
//e_hFE = B = Collector current / Base current
#if DebugOut == 5
lcd_line4();
lcd_data('P');
#endif
tmp16 = adc.lp1;
if (tmp16 > adc.lp_otr) {
tmp16 -= adc.lp_otr;
}
// e_hfe with 1% resolution for optocoupler
#ifdef LONG_HFE
#if DebugOut == 5
lcd_data('H'); // PHce
#endif
e_hfe = ((unsigned int)tmp16 * (unsigned long)(((unsigned long)R_H_VAL * 10000) /
(unsigned int)RR680MI)) / (unsigned int)adc.tp2;
#else
#if DebugOut == 5
lcd_data('h'); // Phce
#endif
e_hfe = ((tmp16 / ((RR680MI+500)/1000)) * (R_H_VAL/500)) / (adc.tp2/5);
#endif
#if DebugOut == 5
lcd_data('c');
lcd_data('e');
lcd_space();
lcd_data('c');
mVOut(adc.lp1);
lcd_data('o');
mVOut(adc.lp_otr);
lcd_data('b');
mVOut(adc.tp2);
lcd_data('B');
lcd_data('=');
DisplayValue(e_hfe,-2,' ',3);
#endif
// first hFE or e_hfe is greater than last hfe ?
if ((ptrans.count == 0) || (e_hfe > ptrans.hfe)){
ptrans.hfe = e_hfe; // hFE with common emitter
#if FLASHEND > 0x1fff /* at least ATmega16 */
ptrans.current = (unsigned int)(((unsigned long)adc.lp1 * 10000) / RR680MI); // Ic 1uA
#endif
ptrans.uBE = unsigned_diff(adc.hp2, adc.tp2); // Base Emitter Voltage
update_pins = 1; // trans.ebc must be updated
}
#endif
#ifdef COMMON_COLLECTOR
//current amplification factor for common Collector (Emitter follower)
// c_hFE = (Emitter current - Base current) / Base current
#ifdef COMMON_EMITTER
// also with COMMON_EMITTER, is c_hfe greater than the last hFE?
if (c_hfe > ptrans.hfe) // trans.hfe is allready e_hfe or last c_hFE
#else
// without COMMON_EMITTER , c_hFE is first or greater than the old one?
if ((ptrans.count == 0) || (c_hfe > ptrans.hfe))
#endif
{
ptrans.hfe = c_hfe; // c_hfe is the best
ptrans.uBE = unsigned_diff(adc.hp1, adc.tp1); // Base Emitter Voltage common collector
#if FLASHEND > 0x1fff /* at least ATmega16 */
ptrans.current = (unsigned int)(((unsigned long)adc.rhp * 10000) / RR680PL); // Ie 1uA
ptrans.current += 10000; // current at emitter!
#endif
update_pins = 1; // trans.ebc must be updated
}
#endif /* end COMMON_COLLECTOR */
#if DebugOut == 5
lcd_data('B');
#endif
#ifdef SHOW_ICE
if (update_pins != 0) {
// update residual collector current without base current
ptrans.ice0 = (unsigned int)(((unsigned long)adc.lp_otr * 10000) / RR680MI); // ICE0 1uA
ptrans.ices = (unsigned int)(((unsigned long)adc.vCEs * 10000) / RR680MI); // ICEs 1uA
}
#endif
goto savePresult; // marke P type, save Pins and exit
} /* end if(adc.tp2 > 2000) */
// is probably a P-E-MOS, check voltage
if((adc.lp_otr < 97) && (adc.lp1 > 2000)) {
//is flow voltage low enough in the closed state?
//(since D-Mode-FET would be by mistake detected as E-Mode )
PartFound = PART_FET; //P-Kanal-MOSFET is found (Basis/Gate moves not to VCC)
PartMode = PART_MODE_MOS|P_CHANNEL|E_MODE;
if (adc.hp2 > (adc.lp1+250)) {
#if DebugOut == 5
lcd_line4();
lcd_data('P');
lcd_data('I');
lcd_data('G');
lcd_space();
mVOut(adc.hp2);
mVOut(adc.lp1);
#endif
//Drain-Source Voltage to high, must be a IGBT
PartMode = PART_MODE_IGBT|P_CHANNEL|E_MODE;
#ifdef SHOW_R_DS
} else {
ptrans.uBE = RR680MI * (unsigned long)unsigned_diff(adc.hp2, adc.lp1) / adc.lp1; // DS resistance in 0.1 OHm
#endif
} /* end if (adc.hp2 > (adc.lp1+250)) */
//measure the Gate threshold voltage
//Switching of Drain is monitored with digital input
// Low level is specified up to 0.3 * VCC
// High level is specified above 0.6 * VCC
PinMSK = LoADCm & 7;
ADMUX = TristatePin | (1<<REFS0); // switch to TristatePin, Ref. VCC
tmp16 = 1; // round up ((1*4)/9)
for(ii=0;ii<11;ii++) {
wdt_reset();
ChargePin10ms(TriPinRL,1);
R_DDR = LoPinRL | TriPinRH; //switch R_H for Tristate-Pin (Basis) to GND
while (!(ADC_PIN&PinMSK)); // Wait, until the MOSFET switches and Drain moves to VCC
// 1 is detected with more than 2.5V (up to 2.57V) with tests of mega168 and mega328
R_DDR = LoPinRL;
ADCSRA |= (1<<ADSC); // Start Conversion
while (ADCSRA&(1<<ADSC)); // wait
tmp16 += (1023 - ADCW); // Add Tristatepin-Voltage
}
tmp16 *= 4; // is equal to 44*ADCW
ptrans.gthvoltage = tmp16 / 9; // gives resolution in mV
ptrans.count++; // count FET as two for accelerate searching
#if DebugOut == 5
lcd_data('F');
#endif
goto savePresult;
} /* end P-E-MOS check */
} /* end component has current => PNP if(adc.lp1 > 3422) */
#ifdef COMMON_COLLECTOR
#if 0
// Low-Pin=RL- HighPin=VCC
R_DDR = LoPinRL | TriPinRL;
R_PORT = TriPinRL; // TriPin=RL+ NPN with common Collector
adc.lp1 = W5msReadADC(LowPin); // voltage at Emitter resistor
adc.tp1 = ReadADC(TristatePin); // voltage at the Base
adc.rtp = vcc_diff(adc.tp1); // voltage at Base resistor
#if DebugOut == 5
lcd_line4();
lcd_data('N');
#endif
if (adc.rtp < 10) {
R_DDR = 0;
wait_about5ms(); // clear TRIAC and Thyristor
R_DDR = LoPinRL | TriPinRH;
R_PORT = TriPinRH; // Tripin=RH+
adc.lp1 = W5msReadADC(LowPin);
adc.tp1 = ReadADC(TristatePin); // voltage at the Base
adc.rtp = vcc_diff(adc.tp1); // voltage at Base resistor
// c_hfe with 1% resolution for optocoupler
// compute c_hfe with RH Base resistor
tmp16 = adc.lp1;
if (tmp16 > adc.lp_otr) {
tmp16 -= adc.lp_otr;
}
#ifdef LONG_HFE
#if DebugOut == 5
lcd_data('H'); // NHcc
#endif
c_hfe = ((unsigned long)tmp16 * (unsigned long)(((unsigned long)R_H_VAL * 10000) /
(unsigned int)RR680MI)) / (unsigned int)adc.rtp;
#else
#if DebugOut == 5
lcd_data('h'); // Nhcc
#endif
c_hfe = ((tmp16 / ((RR680MI+500)/1000)) * (R_H_VAL/500)) / (adc.tp2/5);
#endif
} else {
#if DebugOut == 5
lcd_data('L'); // NLcc
#endif
// compute c_hfe with RL Base resistor
c_hfe = (unsigned long)((unsigned long)unsigned_diff(adc.lp1, adc.rtp) * 100) / adc.rtp;
}
#else
#if DebugOut == 5
lcd_line4();
lcd_data('N');
#endif
// first try to get hFE with RH
R_DDR = LoPinRL | TriPinRH;
R_PORT = TriPinRH; // Tripin=RH+
adc.lp1 = W5msReadADC(LowPin);
adc.tp1 = ReadADC(TristatePin); // voltage at the Base
adc.rtp = vcc_diff(adc.tp1); // voltage at Base resistor
if (adc.lp1 > (100+adc.lp_otr)) {
// c_hfe with 1% resolution for optocoupler
// compute c_hfe with RH Base resistor
tmp16 = unsigned_diff(adc.lp1, adc.lp_otr);
#ifdef LONG_HFE
#if DebugOut == 5
lcd_data('H'); // NHcc
#endif
c_hfe = ((unsigned long)tmp16 * (unsigned long)(((unsigned long)R_H_VAL * 10000) /
(unsigned int)RR680MI)) / (unsigned int)adc.rtp;
#else
#if DebugOut == 5
lcd_data('h'); // Nhcc
#endif
c_hfe = ((tmp16 / ((RR680MI+500)/1000)) * (R_H_VAL/500)) / (adc.tp2/5);
#endif
} else {
// Low-Pin=RL- HighPin=VCC
R_DDR = LoPinRL | TriPinRL;
R_PORT = TriPinRL; // TriPin=RL+ NPN with common Collector
adc.lp1 = W5msReadADC(LowPin); // voltage at Emitter resistor
adc.tp1 = ReadADC(TristatePin); // voltage at the Base
adc.rtp = vcc_diff(adc.tp1); // voltage at Base resistor
#if DebugOut == 5
lcd_data('L'); // NLcc
#endif
tmp16 = adc.lp1;
if (tmp16 > adc.lp_otr) {
tmp16 -= adc.lp_otr;
}
// compute c_hfe with RL Base resistor
c_hfe = (unsigned long)((unsigned long)unsigned_diff(tmp16, adc.rtp) * 100) / adc.rtp;
}
#endif
#if DebugOut == 5
lcd_data('c');
lcd_data('c');
lcd_space();
lcd_data('e');
mVOut(adc.lp1);
lcd_data('o');
mVOut(adc.lp_otr);
lcd_data('b');
mVOut(adc.rtp);
lcd_data('B');
lcd_data('=');
DisplayValue(c_hfe,-2,' ',3);
#endif
#endif
//Tristate (can be Base) to VCC, Test if NPN
ADC_DDR = LoADCm; //Low-Pin to output 0V
ADC_PORT = TXD_VAL; //switch Low-Pin to GND
R_DDR = TriPinRL | HiPinRL; //RL port for High-Pin and Tristate-Pin to output
// vCEs is already measured correctly with common emitter circuit
R_PORT = TriPinRL | HiPinRL; //RL port for High-Pin and Tristate-Pin to Vcc
adc.hp1 = W5msReadADC(HighPin); //measure voltage at High-Pin (Collector)
#ifdef WITH_THYRISTOR_GATE_V
adc.tp2 = ReadADC(TristatePin); //voltage of gate
adc.lp2 = ReadADC(LowPin); //voltage of Cathode
#endif
// if(adc.hp1 < 1600)
// if(adc.hp1 < 4500) /* limit for opto-coupler with low hFE */
if(adc.hp1 < 4400) /* limit for opto-coupler with low hFE */
{
//component has current => NPN-Transistor or somthing else
//Test auf Thyristor:
//Gate discharge
// ChargePin10ms(TriPinRL,0); //Tristate-Pin (Gate) across R_L 10ms to GND
// TRIAC's can be triggered with gate and A1 (C) swapped. The current remains after triggering
// from gate to A2 (A) instead of A1 to A2. I have found that in this state the current will be lower,
// if the Tristatepin (A1) is switched to GND.
R_PORT = HiPinRL;
adc.hp4 = W5msReadADC(HighPin); //read voltage with switched back base
R_DDR = HiPinRL; // base to input
adc.hp3 = W5msReadADC(HighPin); //read voltage at High-Pin (probably Anode) again
//current should still flow, if not,
// no Thyristor or holding current to low
R_PORT = 0; //switch R_L for High-Pin (probably Anode) to GND (turn off)
wait_about5ms();
R_PORT = HiPinRL; //switch R_L for High-Pin (probably Anode) again to VCC
adc.hp2 = W5msReadADC(HighPin); //measure voltage at the High-Pin (probably Anode) again
#if DebugOut == 5
lcd_line4();
lcd_data('y');
lcd_space();
mVOut(adc.hp3);
mVOut(adc.hp2);
mVOut(adc.hp1);
#endif
if((adc.hp3 < 1600) && (adc.hp2 > 4400)
// additional check the voltage hp4 at A with gate hold at GND level
&& ((adc.hp1+150) > adc.hp4)
) {
//if the holding current was switched off the thyristor must be switched off too.
//if Thyristor was still swiched on, if gate was switched off => Thyristor
PartFound = PART_THYRISTOR;
#if DebugOut == 5
lcd_line4();
lcd_testpin(LowPin);
lcd_data('Y');
lcd_testpin(HighPin);
lcd_space();
#endif
ntrans.count++; // mark as two N-type transistors
#ifdef WITH_THYRISTOR_GATE_V
ntrans.uBE = unsigned_diff(adc.tp2, adc.lp2); // Gate - Cathode Voltage
ntrans.gthvoltage = unsigned_diff(adc.hp1, adc.lp2); // Anode-Cathode Voltage
#endif
//Test if Triac
R_DDR = 0;