در این پست گام به گام نحوه ساخت یک تستر ترانزیستور را آموزش خواهیم داد.
برای ساخت این این دستگاه به تجهیزات زیر نیاز دارید.
تجهیزات لازم
- آردوینو UNO
- ال سی دی استاندارد 2*16
- سوئیچ پوش باتن 12 میلی متری
- برد بورد
- سیم جامپر
- مقاومت 680 اهم
- مقاومت 1k ohm
- مقاومت 10k ohm
- مقاومت 470k ohm
درباره این پروژه
این یک تستر خودکار ترانزیستور برای شناسایی پایه ها و مشخصات مختلف نیمه هادی های گسسته (ترانزیستورهای NPN ، PNP ، MOSFET ها و غیره) است. همچنین مقاومت ها، خازن ها، القاگرها و غیره … را نیز ارزیابی می کند.
نحوه استفاده از تستر
برای آزمایش تجهیز مورد نظر آن را به یکی از پایه های تست TP2، TP1 یا TP3 متصل کنید. تجهیز می تواند ترانزیستورهای NPN ،PNP ، FET، مقاومت ها، خازن ها، دیودها، LED و موارد دیگر باشد.
هشدار: فقط خازنی را که قبلاً تخلیه کرده اید آزمایش کنید!
سپس دکمه TEST را فشار دهید و نتیجه تست را روی LCD 2 X 16 بخوانید.
مثالی از تست دستگاه با یک ترانزیستور
برای به دست آوردن پارامترهای بیشتر یا یک تست جدید، دوباره دکمه TEST را فشار دهید.
فشار دادن طولانی دکمه TEST پس از انجام یک تست، یک انتخاب منو به شما می دهد: برای پیمایش در انتخاب منو، دوباره دکمه TEST را فشار دهید و دکمه TEST را به مدت طولانی فشار دهید تا یک تابع خاص انتخاب شود.
موارد بیشتر در مورد توابع منو در زیر آمده است.
f-Generator (خروجی موج مربعی با فرکانس قابل انتخاب در TP 2) (تست پین 2)
PWM ده بیتی (فرکانس با خروجی چرخه کاری قابل انتخاب در TP 2)
در صورت گم شدن در فهرست، کلید ریست Arduino UNO را فشار دهید.
کد مربوط تستر
کد مربوط به تستر در زیر آورده شده است. کد را در Arduino IDE کپی کنید و یک sketch با اسم مناسب بسازید و آن را ذخیره کنید. سپس Arduino / Genuino Uno Board را انتخاب کنید، تأیید کنید و کد را بر روی برد آردوینو بارگذاری کنید. آردوینو استفاده شده در این پروژه برد آردوینو Uno دارای پردازنده مرکزی ATmega328 و چیپ مبدل CH340G است.
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 |
//Test with program in #include <avr/io.h> #include <util/delay.h> #include <avr/sleep.h> #include <stdlib.h> #include "stdint.h" //JLG #include <string.h> #include <avr/eeprom.h> #include <avr/pgmspace.h> #include <avr/wdt.h> #include <math.h> #define MAIN_C #include "Makefile.h" //JLG #include "Transistortester.h" #include "config.h" #include "part_defs.h" #include "lcd_routines.h" #include "lcd_defines.h" #include "wait1000ms.h" #include "autoconf.h" #include "tt_function.h" #include "tt_resistor.h" #include "bitmaps.h" #include "font.h" #include "24x32update_bitmaps.h" /* defines global variables in RAM and EEprom from file tt_globals.h */ /* removed ifdef MAIN_C because always defined */ #define COMMON #ifdef AUTO_CAL const int8_t RefDiff EEMEM = REF_R_KORR; // correction of internal Reference Voltage // const uint16_t cap_null EEMEM = C_NULL; // Zero offset of capacity measurement const int16_t ref_offset EEMEM = REF_C_KORR; // default correction of internal reference voltage for capacity measurement // the zero offset for capacity measurement for all pin combinations // LoPin:HiPin 2:1 3:1 1:2 marker 3:2 1:3 2:3 const uint8_t c_zero_tab[] EEMEM = { C_NULL,C_NULL,C_NULL+TP2_CAP_OFFSET,C_NULL+2,C_NULL+TP2_CAP_OFFSET,C_NULL,C_NULL }; //table of zero offsets // if the marker position of c_zero_tab is not equal the first position, the calibration has not run before #endif #ifdef SamplingADC const uint16_t c_zero_tab2_lo[] EEMEM = { C_NULL*100,C_NULL*100,C_NULL*100,C_NULL*100,C_NULL*100,C_NULL*100,C_NULL*100 }; // zero offsets for SamplingADC capacitance measurement, in 0.01 pF, lo voltage const uint16_t c_zero_tab2_hi[] EEMEM = { C_NULL*100,C_NULL*100,C_NULL*100,C_NULL*100,C_NULL*100,C_NULL*100,C_NULL*100 }; // same, hi voltage #endif #ifdef WITH_MENU const int8_t big_cap_corr EEMEM = C_H_KORR; // default correction for big capacity measurement #if defined(WITH_FREQUENCY_DIVIDER) && !defined(NO_FREQ_COUNTER) #ifndef FREQ_SCALER #define FREQ_SCALER 0 // 1<<0 = 1 #endif const uint8_t f_scaler EEMEM = FREQ_SCALER; // default scaler for frequency measurement #endif #endif const uint8_t EE_ESR_ZEROtab[] EEMEM = {ESR_ZERO, ESR_ZERO, ESR_ZERO, ESR_ZERO}; // zero offset of ESR measurement #ifdef WITH_ROTARY_SWITCH // const uint8_t EE_RotarySwitch EEMEM = 0; // rotation switch is not detected #endif #if ((LCD_ST_TYPE == 7565) || (LCD_ST_TYPE == 1306) || (LCD_ST_TYPE == 8812) || (LCD_ST_TYPE == 8814) || defined(LCD_DOGM)) const uint8_t EE_Volume_Value EEMEM = VOLUME_VALUE; // Volume Value for ST7565 controller #endif #ifdef LCD_CHANGE_COLOR const uint8_t EE_BG_COLOR1 EEMEM = LCD_BG_COLOR & 0xff; // lower bits of background color const uint8_t EE_BG_COLOR2 EEMEM = LCD_BG_COLOR >> 8; // higher bits of background color const uint8_t EE_FG_COLOR1 EEMEM = LCD_FG_COLOR & 0xff; // lower bits of foreground color const uint8_t EE_FG_COLOR2 EEMEM = LCD_FG_COLOR >> 8; // higher bits of foreground color #endif struct Diode_t { uint8_t Anode[6]; uint8_t Cathode[6]; unsigned int Voltage[6]; }; COMMON struct Diode_t diodes; struct Switch_t { union { unsigned long Pw; // combined Mask uint8_t R[4]; // mask to switch a Pin with R_L, mask to switch a Pin with R_H } Pin; }; COMMON uint8_t NumOfDiodes; COMMON uint8_t diode_sequence; typedef struct { unsigned long hfe; //current amplification factor unsigned int uBE; //B-E-voltage of the Transistor or RDS for E-MOS; Idss for JFET unsigned int current; // current of Drain in 1uA unsigned int ice0; // for BJT ICEO in 1uA; for FET cut-off voltage in mV unsigned int gthvoltage; //Gate-threshold voltage // for bipolar gthvoltage is ICEs in 1uA #define ices gthvoltage // note: don't change the total size of the above fields, since the offsets of the following 3 fields are hard-coded in PinLayout.S uint8_t b,c,e; //pins of the Transistor uint8_t count; }trans_t; COMMON trans_t ptrans; // parameters of P type transistor COMMON trans_t ntrans; // parameters of N type transistor COMMON trans_t *_trans; // pointer to trans_t structure COMMON uint8_t tmpval, tmpval2; COMMON unsigned int ref_mv; //Reference-voltage in mV units (as read with ADC) COMMON unsigned int ref_mv_offs; //Reference-voltage in mV units with eeprom offset for C COMMON unsigned int adc_internal_reference; //internal reference voltage of ADC in mV units COMMON unsigned int adc_vcc_reference; // reference voltage of ADC,if switched to VCC in mV units COMMON unsigned int RHmultip; // Multiplier for capacity measurement with R_H (470KOhm) #ifdef WITH_MENU COMMON union t_frq{ unsigned long dw; uint16_t w[2]; uint8_t b[4]; } ext_freq; // external frequency //COMMON unsigned long ext_period; COMMON unsigned int pinchange_count; COMMON unsigned int pinchange_max; #endif COMMON struct cap_t { // Attention! If you change this structure, you must also change defines in GetESR.S !!!! unsigned long cval; // capacitor value unsigned long cval_max; //capacitor with maximum value union t_combi{ unsigned long dw; // capacity value without corrections uint16_t w[2]; } cval_uncorrected; #if FLASHEND > 0x1fff unsigned int esr; // serial resistance of C in 0.01 Ohm unsigned int v_loss; // voltage loss 0.1% #endif uint8_t ca, cb; //pins of capacitor int8_t cpre; //Prefix for capacitor value -12=p, -9=n, -6=µ, -3=m int8_t cpre_max; //Prefix of the biggest capacitor } cap; unsigned int cell_mv[3]; //remaining load voltages after discharge cycle #ifndef INHIBIT_SLEEP_MODE /* with sleep mode we need a global ovcnt16 */ COMMON volatile uint16_t ovcnt16; COMMON volatile uint8_t unfinished; #endif COMMON int16_t load_diff; // difference voltage of loaded capacitor and internal reference COMMON uint8_t WithReference; // Marker for found precision voltage reference = 1 COMMON uint8_t PartFound; // type of the found part COMMON uint8_t PartMode; // description of the found part COMMON char outval[10]; // String for ASCII-output i2lcd, u2lcd //COMMON char OutBuffer[10]; // String for ASCII-output DisplayValue COMMON uint8_t empty_count; // counter for max count of empty measurements COMMON uint8_t mess_count; // counter for max count of nonempty measurements COMMON struct ADCconfig_t { uint8_t Samples; // number of ADC samples to take uint8_t RefFlag; // save Reference type VCC of IntRef uint16_t U_Bandgap; // Reference Voltage in mV uint16_t U_AVCC; // Voltage of AVCC } ADCconfig; #ifdef AUTO_CAL COMMON uint8_t pin_combination; // coded Pin-combination 2:1,3:1,1:2,x:x,3:2,1:3,2:3 COMMON uint16_t resis680pl; // port output resistance + 680 COMMON uint16_t resis680mi; // port output resistance + 680 COMMON uint16_t pin_rmi; // port output resistance to GND side, 0.1 Ohm units COMMON uint16_t pin_rpl; // port output resistance to VCC side, 0.1 Ohm units COMMON uint8_t UnCalibrated; // 0, if the tester is calibrated #endif #ifdef WITH_ROTARY_SWITCH #define ROT_MSK 0x03 /* must be power of two - 1: 3,7,15 */ struct Rotary_t { uint8_t state[(ROT_MSK+1)]; // coded state history of the rotatry switch, bit 0 == state of A-switch, bit 1 = state of B-switch uint8_t ind; // index to the last entry of the state history (rotary switch) int8_t count; // count of right steps, negative if left steps uint8_t incre; // absolute value of step count #if WITH_ROTARY_SWITCH == 4 // no rotary switch connected, UP and DOWN key is present uint8_t a_state; // history of switch A state for single UP switch uint8_t b_state; // history of switch B state for single DOWN switch #endif }; COMMON struct Rotary_t rotary; COMMON uint8_t rotary_switch_present; // is set to 1, if rotary switch movement is detected // COMMON const uint8_t EE_RotarySwitch; // rotation switch is detected #endif #if FLASHEND > 0x1fff COMMON uint8_t DC_Pwr_mode; #endif COMMON uint8_t lcd_text_line; COMMON uint8_t _lcd_column; COMMON uint8_t last_line_used; //#if POWER_OFF+0 > 1 COMMON unsigned int display_time; // display time of measurement in ms units //#endif #if (LCD_ST_TYPE == 7920) COMMON uint8_t lcd_bit_mem[64][16]; #endif #if ((LCD_ST_TYPE == 7565) || (LCD_ST_TYPE == 1306) || defined(LCD_DOGM)) COMMON const uint8_t EE_Volume_Value EEMEM; // Volume Value for ST7565 controller #endif #ifdef LCD_CHANGE_COLOR COMMON union { uint16_t w; uint8_t b[2]; } lcd_bg_color; #endif #if defined(LCD_CHANGE_COLOR) || defined(LCD_ICON_COLOR) COMMON union { uint16_t w; uint8_t b[2]; } lcd_fg_color; #endif #if defined(LCD_ICON_COLOR) COMMON union { uint16_t w; uint8_t b[2]; } lcd_fg2_color; #endif /* END defines global variables in RAM and EEprom from file tt_globals.h */ #ifndef INHIBIT_SLEEP_MODE // prepare sleep mode EMPTY_INTERRUPT(TIMER2_COMPA_vect); #endif #if !defined(INHIBIT_SLEEP_MODE) || defined(SamplingADC) // ADC_vect is always required by samplingADC() EMPTY_INTERRUPT(ADC_vect); #endif /************************************************** *** begin of transistortester program ***************************************************/ void setup() { #ifdef WITH_HARDWARE_SERIAL Serial.begin(115200); // Serial Monitor #endif //#ifdef ARDUINO_UNO // pinMode(A3,INPUT_PULLUP);// avoids external 10K Pullup //#endif uint8_t ii; unsigned int max_time; #ifdef SEARCH_PARASITIC unsigned long n_cval; // capacitor value of NPN B-E diode, for deselecting the parasitic Transistor int8_t n_cpre; // capacitor prefix of NPN B-E diode #endif #ifdef WITH_GRAPHICS unsigned char options; #endif uint8_t vak_diode_nr; // number of the protection diode of BJT union { uint16_t pw; uint8_t pb[2]; } rpins; uint8_t x, y, z; //switch on ON_DDR = (1<<ON_PIN); // switch to output ON_PORT = (1<<ON_PIN); // switch power on #ifndef PULLUP_DISABLE RST_PORT |= (1<<RST_PIN); // enable internal Pullup for Start-Pin #endif uint8_t tmp; //ADC-Init ADCSRA = (1<<ADEN) | AUTO_CLOCK_DIV; //prescaler=8 or 64 (if 8Mhz clock) #ifdef __AVR_ATmega8__ // #define WDRF_HOME MCU_STATUS_REG #define WDRF_HOME MCUCSR #else #define WDRF_HOME MCUSR #if FLASHEND > 0x3fff // probably was a bootloader active, disable the UART UCSR0B = 0; // disable UART, if started with bootloader #endif #endif wait500ms(); #if (PROCESSOR_TYP == 644) || (PROCESSOR_TYP == 1280) #define BAUD_RATE 9600 // UBRR0H = (F_CPU / 16 / BAUD_RATE - 1) >> 8; // UBRR0L = (F_CPU / 16 / BAUD_RATE - 1) & 0xff; // UCSR0B = (1<<TXEN0); // UCSR0C = (1<<USBS0) | (3<<UCSZ00); // 2 stop bits, 8-bit // while (!(UCSR0A & (1<<UDRE0))) { }; // wait for send data port ready #ifdef SWUART_INVERT SERIAL_PORT &= ~(1<<SERIAL_BIT); #else SERIAL_PORT |= (1<<SERIAL_BIT); #endif SERIAL_DDR |= (1<<SERIAL_BIT); #endif tmp = (WDRF_HOME & ((1<<WDRF))); // save Watch Dog Flag WDRF_HOME &= ~(1<<WDRF); //reset Watch Dog flag wdt_disable(); // disable Watch Dog #ifndef INHIBIT_SLEEP_MODE // switch off unused Parts #if PROCESSOR_TYP == 644 #ifdef PRUSART1 PRR0 = (1<<PRTWI) | (1<<PRSPI) | (1<<PRUSART1); #else PRR0 = (1<<PRTWI) | (1<<PRSPI) ; #endif // PRR1 = (1<<PRTIM3) ; #elif PROCESSOR_TYP == 1280 PRR0 = (1<<PRTWI) | (1<<PRSPI) | (1<<PRUSART1); PRR1 = (1<<PRTIM5) | (1<<PRTIM4) | (1<<PRTIM3) | (1<<PRUSART3) | (1<<PRUSART2) | (1<<PRUSART3); #else PRR = (1<<PRTWI) | (1<<PRSPI) | (1<<PRUSART0); #endif // disable digital inputs of Analog pins, but TP1-3 digital inputs must be left enabled for VGS measurement DIDR0 = ((1<<ADC5D) | (1<<ADC4D) | (1<<ADC3D) | (1<<ADC2D) | (1<<ADC1D) | (1<<ADC0D)) & ~((1<<TP3) | (1<<TP2) | (1<<TP1)); TCCR2A = (0<<WGM21) | (0<<WGM20); // Counter 2 normal mode TCCR2B = CNTR2_PRESCALER; //prescaler set in autoconf #endif /* INHIBIT_SLEEP_MODE */ sei(); // enable interrupts lcd_init(); //initialize LCD // ADC_PORT = TXD_VAL; // ADC_DDR = TXD_MSK; if(tmp) { // check if Watchdog-Event // this happens, if the Watchdog is not reset for 2s // can happen, if any loop in the Program doen't finish. lcd_line1(); lcd_MEM_string(TestTimedOut); //Output Timeout wait_about3s(); // time to read the Timeout message switch_tester_off(); return 0; } #ifdef PULLUP_DISABLE #ifdef __AVR_ATmega8__ SFIOR = (1<<PUD); // disable Pull-Up Resistors mega8 #else MCUCR = (1<<PUD); // disable Pull-Up Resistors mega168 family #endif #endif //#if POWER_OFF+0 > 1 // tester display time selection #ifndef USE_EEPROM EE_check_init(); // init EEprom, if unset #endif #ifdef WITH_ROTARY_SWITCH // rotary_switch_present = eeprom_read_byte(&EE_RotarySwitch); rotary.ind = ROT_MSK+1; //initilize state history with next call of check_rotary() #endif #ifdef WITH_HARDWARE_SERIAL // ii = 60; ii = 30; #else #if 1 for (ii=0; ii<60; ii++) { if (RST_PIN_REG & (1 << RST_PIN)) break; // button is released wait_about10ms(); } #else ii = 0; if (!(RST_PIN_REG & (1<<RST_PIN))) { // key is still pressed ii = wait_for_key_ms(700); } #endif display_time = OFF_WAIT_TIME; // LONG_WAIT_TIME for single mode, else SHORT_WAIT_TIME if (ii > 30) { display_time = LONG_WAIT_TIME; // ... set long time display anyway } #endif // WITH_HARDWARE_SERIAL #if POWER_OFF+0 > 1 empty_count = 0; mess_count = 0; #endif ADCconfig.RefFlag = 0; Calibrate_UR(); // get Ref Voltages and Pin resistance #ifdef WDT_enabled wdt_enable(WDTO_2S); //Watchdog on #endif #ifdef WITH_MENU if (ii >= 60) { while(function_menu()); // selection of function } #endif //***************************************************************** //Entry: if start key is pressed before shut down loop_start: #if ((LCD_ST_TYPE == 7565) || (LCD_ST_TYPE == 1306)) lcd_command(CMD_DISPLAY_ON); lcd_command(CMD_SET_ALLPTS_NORMAL); // 0xa4 #endif lcd_clear(); // clear the LCD ADC_DDR = TXD_MSK; // activate Software-UART init_parts(); // reset parts info to nothing found Calibrate_UR(); // get Ref Voltages and Pin resistance lcd_line1(); // Cursor to 1. row, column 1 #ifdef BAT_CHECK // Battery check is selected Battery_check(); #else lcd_MEM_string(VERSION_str); // if no Battery check, Version .. in row 1 #endif /* BAT_CHECK */ // begin tests #if FLASHEND > 0x1fff if (WithReference) { /* 2.5V precision reference is checked OK */ #if POWER_OFF+0 > 1 if ((mess_count == 0) && (empty_count == 0)) #endif { /* display VCC= only first time */ lcd_line2(); lcd_MEM_string(VCC_str); // VCC= Display_mV(ADCconfig.U_AVCC,3); // Display 3 Digits of this mV units lcd_refresh(); // write the pixels to display, ST7920 only wait_about1s(); // time to read the VCC= message } } #endif #ifdef WITH_VEXT unsigned int Vext; // show the external voltage while (!(RST_PIN_REG & (1<<RST_PIN))) { lcd_clear_line2(); lcd_MEM_string(Vext_str); // Vext= ADC_DDR = 0; //deactivate Software-UART Vext = W5msReadADC(TPext); // read external voltage // ADC_DDR = TXD_MSK; //activate Software-UART uart_newline(); // MAURO replaced uart_putc(' ') by uart_newline(), 'Z' #if EXT_NUMERATOR <= (0xffff/U_VCC) Display_mV(Vext*EXT_NUMERATOR/EXT_DENOMINATOR,3); // Display 3 Digits of this mV units #else DisplayValue((unsigned long)Vext*EXT_NUMERATOR/EXT_DENOMINATOR,-3,'V',3); // Display 3 Digits of this mV units #endif lcd_refresh(); // write the pixels to display, ST7920 only wait_about300ms(); // delay to read the Vext= message } #endif /* WITH_VEXT */ #ifndef DebugOut lcd_line2(); //LCD position row 2, column 1 #endif EntladePins(); // discharge all capacitors! if(PartFound == PART_CELL) { lcd_clear(); lcd_MEM_string(Cell_str); // display "Cell!" #if FLASHEND > 0x3fff lcd_line2(); // use LCD line 2 Display_mV(cell_mv[0],3); lcd_space(); Display_mV(cell_mv[1],3); lcd_space(); Display_mV(cell_mv[2],3); #endif #ifdef WITH_SELFTEST lcd_refresh(); // write the pixels to display, ST7920 only wait_about2s(); AutoCheck(0x11); // full Selftest with "Short probes" message #endif goto tt_end; } #ifdef WITH_SELFTEST #ifdef AUTO_CAL lcd_cursor_off(); UnCalibrated = (eeprom_read_byte(&c_zero_tab[3]) - eeprom_read_byte(&c_zero_tab[0])); if (UnCalibrated != 0) { // if calibrated, both c_zero_tab values are identical! c_zero_tab[3] is not used otherwise lcd_cursor_on(); } #endif #ifdef WITH_MENU AutoCheck(0x00); //check, if selftest should be done, only calibration #else AutoCheck(0x01); //check, if selftest should be done, full selftest without MENU #endif #endif #if FLASHEND > 0x1fff lcd_clear_line2(); //LCD position row2, column 1 #else lcd_line2(); //LCD position row2, column 1 #endif lcd_MEM_string(TestRunning); //String: testing... lcd_refresh(); // write the pixels to display, ST7920 only #ifdef WITH_UART uart_putc(0x03); // ETX, start of new measurement uart_newline(); // MAURO Added #endif // // check all 6 combinations for the 3 pins // High Low Tri CheckPins(TP1, TP2, TP3); CheckPins(TP2, TP1, TP3); CheckPins(TP1, TP3, TP2); CheckPins(TP3, TP1, TP2); CheckPins(TP2, TP3, TP1); CheckPins(TP3, TP2, TP1); // Capacity measurement is only possible correctly with two Pins connected. // A third connected pin will increase the capacity value! // if(((PartFound == PART_NONE) || (PartFound == PART_RESISTOR) || (PartFound == PART_DIODE)) ) { if(PartFound == PART_NONE) { // If no part is found yet, check separate if is is a capacitor #ifdef DebugOut lcd_data('C'); #endif EntladePins(); // discharge capacities //measurement of capacities in all 3 combinations ReadCapacity(TP3, TP1); #ifdef DebugOut lcd_data('K'); #endif #if DebugOut != 10 ReadCapacity(TP3, TP2); #ifdef DebugOut lcd_data('K'); #endif ReadCapacity(TP2, TP1); #ifdef DebugOut lcd_data('K'); #endif #endif } #ifdef WITH_UJT // check for UJT if (PartFound==PART_DIODE && NumOfDiodes==2 // UJT is detected as 2 diodes E-B1 and E-B2... // && ResistorsFound==1 // ...and a resistor B1-B2 && diodes.Anode[0]==diodes.Anode[1] // check diodes have common anode // && (unsigned char)(ResistorList[0]+diodes.Anode[0])==2 // and resistor is between cathodes ) // note: there also exist CUJTs (complementary UJTs); they seem to be (even) rarer than UJTs, and are not supported for now { CheckUJT(); } #endif /* defined WITH_UJT */ #ifdef WITH_XTAL if (PartFound==PART_NONE || ((PartFound==PART_CAPACITOR) && (cap.cpre_max == -12))) { // still not recognized anything? then check for ceramic resonator or crystal // these tests are time-consuming, so we do them last, and only on TP1/TP3 sampling_test_xtal(); } #endif //All checks are done, output result to display #ifdef DebugOut // only clear two lines of LCD lcd_clear_line1(); #else lcd_clear(); // clear total display #endif _trans = &ntrans; // default transistor structure to show if (PartFound == PART_THYRISTOR) { #ifdef WITH_GRAPHICS lcd_big_icon(THYRISTOR|LCD_UPPER_LEFT); lcd_draw_trans_pins(-8, 16); lcd_set_cursor(0,TEXT_RIGHT_TO_ICON); // position behind the icon, Line 1 lcd_MEM_string(Thyristor); //"Thyristor" #else lcd_MEM_string(Thyristor); //"Thyristor" PinLayout(Cathode_char,'G','A'); // CGA= or 123=... #endif goto TyUfAusgabe; } if (PartFound == PART_TRIAC) { #ifdef WITH_GRAPHICS lcd_big_icon(TRIAC|LCD_UPPER_LEFT); lcd_draw_trans_pins(-8, 16); lcd_set_cursor(0,TEXT_RIGHT_TO_ICON); // position behind the icon, Line 1 lcd_MEM_string(Triac); //"Triac" #else lcd_MEM_string(Triac); //"Triac" PinLayout('1','G','2'); // CGA= or 123=... #endif goto TyUfAusgabe; } #ifdef WITH_PUT if (PartFound == PART_PUT) { static const unsigned char PUT_str[] MEM_TEXT = "PUT"; lcd_MEM_string(PUT_str); _trans=&ptrans; PinLayout('A','G',Cathode_char); goto TyUfAusgabe; } #endif #ifdef WITH_UJT if (PartFound == PART_UJT) { static const unsigned char UJT_str[] MEM_TEXT = "UJT"; lcd_MEM_string(UJT_str); PinLayout('1','E','2'); #ifdef SamplingADC static const unsigned char eta_str[] MEM_TEXT = " eta="; lcd_next_line(0); ResistorChecked[ntrans.e - TP_MIN + ntrans.c - TP_MIN - 1] = 0; // forget last resistance measurement GetResistance(ntrans.c, ntrans.e); // resistor value is in ResistorVal[resnum] DisplayValue(ResistorVal[ntrans.e - TP_MIN + ntrans.c - TP_MIN - 1],-1,LCD_CHAR_OMEGA,2); lcd_MEM_string(eta_str); //"eta=" DisplayValue(ntrans.gthvoltage,0,'%',3); #else /* ! SamplingADC */ static const unsigned char R12_str[] MEM_TEXT = "R12="; lcd_next_line(0); lcd_MEM_string(R12_str); //"R12=" DisplayValue(ResistorVal[ntrans.e - TP_MIN + ntrans.c - TP_MIN - 1],-1,LCD_CHAR_OMEGA,2); lcd_data(','); DisplayValue(((RR680PL * (unsigned long)(ADCconfig.U_AVCC - ntrans.uBE)) / ntrans.uBE)-RRpinPL,-1,LCD_CHAR_OMEGA,3); #endif /* SamplingADC */ goto tt_end; } #endif /* WITH_UJT */ if (PartFound == PART_CAPACITOR) { #if FLASHEND > 0x3fff if ((cap.ca + cap.cb) == (TP1 + TP3)) { show_Cap13(); // repeated capacity measurement goto shut_off; // key was pressed or timeout } show_cap(0); // show capacity in normal way and measure additional parameters #else show_cap_simple(); // show capacity in normal way and measure additional parameters #endif goto tt_end; } /* end PartFound == PART_CAPACITOR */ #ifdef WITH_XTAL if (PartFound == PART_CERAMICRESONATOR) { // static const unsigned char cerres_str[] MEM_TEXT = "Cer.resonator "; lcd_MEM_string(cerres_str); if (sampling_measure_xtal()) goto loop_start; goto tt_end; } if (PartFound == PART_XTAL) { // static const unsigned char xtal_str[] MEM_TEXT = "Crystal "; lcd_MEM_string(xtal_str); if (sampling_measure_xtal()) goto loop_start; goto tt_end; } #endif // ======================================== if(PartFound == PART_DIODE) { // ======================================== if(NumOfDiodes == 1) { //single Diode // lcd_MEM_string(Diode); //"Diode: " #if FLASHEND > 0x1fff // enough memory (>8k) to sort the pins and additional Ir= DiodeSymbol_withPins(0); GetIr(diodes.Cathode[0],diodes.Anode[0]); // measure and output Ir=x.xuA #else // too less memory to sort the pins DiodeSymbol_withPins(0); #endif UfAusgabe(0x70); // mark for additional resistor and output Uf= in line 2 #ifndef SamplingADC /* load current of capacity is (5V-1.1V)/(470000 Ohm) = 8298nA */ ReadCapacity(diodes.Cathode[0],diodes.Anode[0]); // Capacity opposite flow direction if (cap.cpre < -3) { /* capacity is measured */ #if (LCD_LINES > 2) lcd_line3(); // output Capacity in line 3 #endif lcd_MEM_string(Cap_str); //"C=" #if LCD_LINE_LENGTH > 16 DisplayValue(cap.cval,cap.cpre,'F',3); #else DisplayValue(cap.cval,cap.cpre,'F',2); #endif } #else // SamplingADC showdiodecap: cap.cval=sampling_cap(diodes.Cathode[0],diodes.Anode[0],0); // at low voltage lcd_next_line_wait(0); // next line, wait 5s and clear line 2 DisplayValue(cap.cval,sampling_cap_pre,'F',2); #ifdef PULLUP_DISABLE lcd_data('-'); cap.cval=sampling_cap(diodes.Cathode[0],diodes.Anode[0],1); // at high voltage if (cap.cval < 0) cap.cval = 0; // don't show negativ value DisplayValue(cap.cval,sampling_cap_pre,'F',2); #if LCD_LINE_LENGTH > 16 lcd_MEM_string(AT05volt); // " @0-5V" #else lcd_MEM_string(AT05volt+1); // "@0-5V" #endif uart_newline(); // MAURO Diode ('A') #else #warning Capacity measurement from high to low not possible for diodes without PULLUP_DISABLE option! #endif /* PULLUP_DISABLE */ #endif goto end3; } else if(NumOfDiodes == 2) { // double diode lcd_data('2'); lcd_MEM_string(Dioden); //"diodes " if(diodes.Anode[0] == diodes.Anode[1]) { //Common Anode DiodeSymbol_CpinApin(0); // 1-|<-2 DiodeSymbol_ACpin(1); // ->|-3 UfAusgabe(0x01); #ifdef SamplingADC goto showdiodecap; // double diodes are often varicap; measure capacitance of one of them #else goto end3; #endif } if(diodes.Cathode[0] == diodes.Cathode[1]) { //Common Cathode DiodeSymbol_ApinCpin(0); // 1->|-2 DiodeSymbol_CApin(1); // -|<-3 UfAusgabe(0x01); #ifdef SamplingADC goto showdiodecap; // double diodes are often varicap; measure capacitance of one of them #else goto end3; #endif // else if ((diodes.Cathode[0] == diodes.Anode[1]) && (diodes.Cathode[1] == diodes.Anode[0])) } if (diodes.Cathode[0] == diodes.Anode[1]) { // normaly two serial diodes are detected as three diodes, but if the threshold is high // for both diodes, the third diode is not detected. // can also be Antiparallel diode_sequence = 0x01; // 0 1 SerienDiodenAusgabe(); goto end3; } if (diodes.Cathode[1] == diodes.Anode[0]) { diode_sequence = 0x10; // 1 0 SerienDiodenAusgabe(); goto end3; } } else if(NumOfDiodes == 3) { //Serial of 2 Diodes; was detected as 3 Diodes diode_sequence = 0x33; // 3 3 /* Check for any constellation of 2 serial diodes: Only once the pin No of anyone Cathode is identical of another anode. two diodes in series is additionally detected as third big diode. */ if (diodes.Cathode[0] == diodes.Anode[1]) { diode_sequence = 0x01; // 0 1 } if (diodes.Anode[0] == diodes.Cathode[1]) { diode_sequence = 0x10; // 1 0 } if (diodes.Cathode[0] == diodes.Anode[2]) { diode_sequence = 0x02; // 0 2 } if (diodes.Anode[0] == diodes.Cathode[2]) { diode_sequence = 0x20; // 2 0 } if (diodes.Cathode[1] == diodes.Anode[2]) { diode_sequence = 0x12; // 1 2 } if (diodes.Anode[1] == diodes.Cathode[2]) { diode_sequence = 0x21; // 2 1 } // if((ptrans.b<3) && (ptrans.c<3)) if(diode_sequence < 0x22) { lcd_data('3'); lcd_MEM_string(Dioden); //"Diodes " SerienDiodenAusgabe(); goto end3; } } // end (NumOfDiodes == 3) lcd_MEM_string(Bauteil); //"Bauteil" lcd_MEM_string(Unknown); //" unbek." lcd_line2(); //2. row lcd_data(NumOfDiodes + '0'); lcd_data('*'); lcd_MEM_string(AnKat_str); //"->|-" lcd_MEM_string(Detected); //" detected" goto not_known; // end (PartFound == PART_DIODE) // ======================================== } else if (PartFound == PART_TRANSISTOR) { // ======================================== #ifdef SEARCH_PARASITIC if ((ptrans.count != 0) && (ntrans.count !=0)) { // Special Handling of NPNp and PNPn Transistor. // If a protection diode is built on the same structur as the NPN-Transistor, // a parasitic PNP-Transistor will be detected. ReadCapacity(ntrans.e, ntrans.b); // read capacity of NPN base-emitter n_cval = cap.cval; // save the found capacity value n_cpre = cap.cpre; // and dimension ReadCapacity(ptrans.b, ptrans.e); // read capacity of PNP base-emitter // check if one hfe is very low. If yes, simulate a very low BE capacity if ((ntrans.hfe < 500) && (ptrans.hfe >= 500)) n_cpre = -16; // set NPN BE capacity to low value if ((ptrans.hfe < 500) && (ntrans.hfe >= 500)) cap.cpre = -16; // set PNP BE capacity to low value if (((n_cpre == cap.cpre) && (cap.cval > n_cval)) || (cap.cpre > n_cpre)) { // the capacity value or dimension of the PNP B-E is greater than the NPN B-E PartMode = PART_MODE_PNP; } else { PartMode = PART_MODE_NPN; } } /* end ((ptrans.count != 0) && (ntrans.count !=0)) */ #endif // not possible for mega8, change Pin sequence instead. if ((ptrans.count != 0) && (ntrans.count != 0) && (!(RST_PIN_REG & (1 << RST_PIN)))) { // if the Start key is still pressed, use the other Transistor #if 0 if (PartMode == PART_MODE_NPN) { PartMode = PART_MODE_PNP; // switch to parasitic transistor } else { PartMode = PART_MODE_NPN; // switch to parasitic transistor } #else PartMode ^= (PART_MODE_PNP - PART_MODE_NPN); #endif } #ifdef WITH_GRAPHICS lcd_set_cursor(0,TEXT_RIGHT_TO_ICON); // position behind the icon, Line 1 lcd_big_icon(BJT_NPN|LCD_UPPER_LEFT); // show the NPN Icon at lower left corner if(PartMode == PART_MODE_NPN) { // _trans = &ntrans; is allready selected a default lcd_MEM_string(NPN_str); //"NPN " if (ptrans.count != 0) { lcd_data('p'); // mark for parasitic PNp } } else { _trans = &ptrans; // change transistor structure lcd_update_icon(bmp_pnp); // update for PNP lcd_MEM_string(PNP_str); //"PNP " if (ntrans.count != 0) { lcd_data('n'); // mark for parasitic NPn } } #else /* only character display */ if(PartMode == PART_MODE_NPN) { // _trans = &ntrans; is allready selected a default lcd_MEM_string(NPN_str); //"NPN " if (ptrans.count != 0) { lcd_data('p'); // mark for parasitic PNp } } else { _trans = &ptrans; // change transistor structure lcd_MEM_string(PNP_str); //"PNP " if (ntrans.count != 0) { lcd_data('n'); // mark for parasitic NPn } } lcd_space(); #endif // show the protection diode of the BJT vak_diode_nr = search_vak_diode(); if (vak_diode_nr < 5) { // no side of the diode is connected to the base, this must be the protection diode #ifdef WITH_GRAPHICS options = 0; if (_trans->c != diodes.Anode[vak_diode_nr]) options |= OPT_VREVERSE; lcd_update_icon_opt(bmp_vakdiode,options); // show the protection diode right to the Icon #else /* only character display, show the diode in correct direction */ char an_cat; // diode is anode-cathode type an_cat = 0; #ifdef EBC_STYLE #if EBC_STYLE == 321 // Layout with 321= style an_cat = (((PartMode == PART_MODE_NPN) && (ntrans.c < ntrans.e)) || ((PartMode != PART_MODE_NPN) && (ptrans.c > ptrans.e))); #else // Layout with EBC= style an_cat = (PartMode == PART_MODE_NPN); #endif #else // Layout with 123= style an_cat = (((PartMode == PART_MODE_NPN) && (ntrans.c > ntrans.e)) || ((PartMode != PART_MODE_NPN) && (ptrans.c < ptrans.e))); #endif if (an_cat) { lcd_MEM_string(AnKat_str); //"->|-" } else { lcd_MEM_string(KatAn_str); //"-|<-" } #endif /* !WITH_GRAPHICS */ } /* endif vak_diode_nr < 6 */ #ifdef WITH_GRAPHICS lcd_draw_trans_pins(-7, 16); // show the pin numbers lcd_next_line(TEXT_RIGHT_TO_ICON); // position behind the icon, Line 2 lcd_MEM_string(hfe_str); //"B=" (hFE) DisplayValue(_trans->hfe,-2,0,3); lcd_next_line(TEXT_RIGHT_TO_ICON+1-LOW_H_SPACE); // position behind the icon+1, Line 3 lcd_data('I'); if (_trans->current >= 10000) { lcd_data('e'); // emitter current has 10mA offset _trans->current -= 10000; } else { lcd_data('c'); } lcd_equal(); // lcd_data('='); DisplayValue16(_trans->current,-6,'A',2); // display Ic or Ie current lcd_next_line(TEXT_RIGHT_TO_ICON); // position behind the icon, Line 4 lcd_MEM_string(Ube_str); //"Ube=" Display_mV(_trans->uBE,3-LOW_H_SPACE); last_line_used = 1; #ifdef SHOW_ICE if (_trans->ice0 > 0) { lcd_next_line_wait(TEXT_RIGHT_TO_ICON-1-LOW_H_SPACE); // position behind the icon, Line 4 & wait and clear last line lcd_MEM2_string(ICE0_str); // "ICE0=" DisplayValue16(_trans->ice0,-6,'A',2); // display ICEO } if (_trans->ices > 0) { lcd_next_line_wait(TEXT_RIGHT_TO_ICON-1-LOW_H_SPACE); // position behind the icon, Line 4 & wait and clear last line lcd_MEM2_string(ICEs_str); // "ICEs=" DisplayValue16(_trans->ices,-6,'A',2); // display ICEs } #endif #else /* character display */ PinLayout('E','B','C'); // EBC= or 123=... lcd_line2(); //2. row lcd_MEM_string(hfe_str); //"B=" (hFE) DisplayValue(_trans->hfe,-2,0,3); #if FLASHEND > 0x1fff lcd_space(); lcd_data('I'); if (_trans->current >= 10000) { lcd_data('e'); // emitter current has 10mA offset _trans->current -= 10000; } else { lcd_data('c'); } lcd_equal(); // lcd_data('='); DisplayValue16(_trans->current,-6,'A',2); // display Ic or Ie current #endif #if defined(SHOW_ICE) lcd_next_line_wait(0); // next line, wait 5s and clear line 2 lcd_MEM_string(Ube_str); //"Ube=" Display_mV(_trans->uBE,3); if (_trans->ice0 > 0) { lcd_next_line_wait(0); // next line, wait 5s and clear line 2 lcd_MEM2_string(ICE0_str); // "ICE0=" DisplayValue16(_trans->ice0,-6,'A',3); } if (_trans->ices > 0) { lcd_next_line_wait(0); // next line, wait 5s and clear line 2 lcd_MEM2_string(ICEs_str); // "ICEs=" DisplayValue16(_trans->ices,-6,'A',3); } #endif #endif /* WITH_GRAPHICS */ #ifdef SHOW_VAKDIODE if (vak_diode_nr < 5) { lcd_next_line_wait(0); // next line, wait 5s and clear line 2/4 DiodeSymbol_withPins(vak_diode_nr); lcd_MEM_string(Uf_str); //"Uf=" mVAusgabe(vak_diode_nr); uart_newline(); // MAURO not verified ('D') } /* end if (vak_diode_nr < 5) */ #endif #ifdef WITH_GRAPHICS PinLayoutLine('E','B','C'); // Pin 1=E ... uart_newline(); // MAURO OK BJT ('E') #endif goto tt_end; // end (PartFound == PART_TRANSISTOR) // ======================================== } else if (PartFound == PART_FET) { /* JFET or MOSFET */ // ======================================== #ifdef WITH_GRAPHICS unsigned char fetidx = 0; lcd_set_cursor(0,TEXT_RIGHT_TO_ICON); // position behind the icon, Line 1 #endif if((PartMode&P_CHANNEL) == P_CHANNEL) { lcd_data('P'); //P-channel _trans = &ptrans; #ifdef WITH_GRAPHICS fetidx = 2; #endif } else { lcd_data('N'); //N-channel // _trans = &ntrans; is allready selected as default } lcd_data('-'); // minus is used for JFET, D-MOS, E-MOS ... uint8_t part_code; part_code = PartMode&0x0f; #ifdef WITH_GRAPHICS if (part_code == PART_MODE_JFET) { lcd_MEM_string(jfet_str); //"JFET" lcd_big_icon(N_JFET|LCD_UPPER_LEFT); if (fetidx != 0) { lcd_update_icon(bmp_p_jfet); // update the n_jfet bitmap to p_jfet } } else { // no JFET if ((PartMode&D_MODE) == D_MODE) { lcd_data('D'); // N-D or P-D fetidx += 1; } else { lcd_data('E'); // N-E or P-E } if (part_code == (PART_MODE_IGBT)) { lcd_MEM_string(igbt_str); //"-IGBT" lcd_big_icon(N_E_IGBT|LCD_UPPER_LEFT); if (fetidx == 1) lcd_update_icon(bmp_n_d_igbt); if (fetidx == 2) lcd_update_icon(bmp_p_e_igbt); if (fetidx == 3) lcd_update_icon(bmp_p_d_igbt); } else { lcd_MEM_string(mosfet_str); //"-MOS " lcd_big_icon(N_E_MOS|LCD_UPPER_LEFT); if (fetidx == 1) lcd_update_icon(bmp_n_d_mos); if (fetidx == 2) lcd_update_icon(bmp_p_e_mos); if (fetidx == 3) lcd_update_icon(bmp_p_d_mos); } } /* end PART_MODE_JFET */ #else /* normal character display */ if (part_code == PART_MODE_JFET) { lcd_MEM_string(jfet_str); //"-JFET" } else { // no JFET if ((PartMode&D_MODE) == D_MODE) { lcd_data('D'); // N-D or P-D } else { lcd_data('E'); // N-E or P-E } if (part_code == (PART_MODE_IGBT)) { lcd_MEM_string(igbt_str); //"-IGBT" } else { lcd_MEM_string(mosfet_str); //"-MOS " } } /* end PART_MODE_JFET */ if (part_code == PART_MODE_IGBT) { PinLayout('E','G','C'); // SGD= or 123=... } else if (part_code == PART_MODE_JFET) { PinLayout('?','G','?'); // ?G?= or 123=... } else { PinLayout('S','G','D'); // SGD= or 123=... } #endif /* WITH_GRAPHICS */ vak_diode_nr = search_vak_diode(); if(vak_diode_nr < 5) { //MOSFET with protection diode; only with enhancement-FETs #ifndef WITH_GRAPHICS #if FLASHEND <= 0x1fff char an_cat; // diode is anode-cathode type an_cat = 0; #ifdef EBC_STYLE #if EBC_STYLE == 321 // layout with 321= style an_cat = (((PartMode&P_CHANNEL) && (ptrans.c > ptrans.e)) || ((!(PartMode&P_CHANNEL)) && (ntrans.c < ntrans.e))); #else // Layout with SGD= style an_cat = (PartMode&P_CHANNEL); /* N or P MOS */ #endif #else /* EBC_STYLE not defined */ // layout with 123= style an_cat = (((PartMode & P_CHANNEL) && (ptrans.c < ptrans.e)) || ((!(PartMode & P_CHANNEL)) && (ntrans.c > ntrans.e))); #endif /* end ifdef EBC_STYLE */ // show diode symbol in right direction (short form for less flash memory) if (an_cat) { lcd_data(LCD_CHAR_DIODE1); //show Diode symbol >| } else { lcd_data(LCD_CHAR_DIODE2); //show Diode symbol |< } #endif #endif /* not WITH_GRAPHICS */ #ifdef WITH_GRAPHICS options = 0; if (_trans->c != diodes.Anode[vak_diode_nr]) options |= OPT_VREVERSE; lcd_update_icon_opt(bmp_vakdiode,options); // update Icon with protection diode #endif } /* end if NumOfDiodes == 1 */ #ifdef WITH_GRAPHICS lcd_draw_trans_pins(-7, 16); // update of pin numbers must be done after diode update lcd_next_line(TEXT_RIGHT_TO_ICON); // position text behind the icon, Line 2 #if LCD_LINES > 6 lcd_next_line(TEXT_RIGHT_TO_ICON); // double line #endif if((PartMode&D_MODE) != D_MODE) { //enhancement-MOSFET lcd_MEM_string(vt_str+1); // "Vt=" Display_mV(_trans->gthvoltage,2); //Gate-threshold voltage //Gate capacity ReadCapacity(_trans->b,_trans->e); //measure capacity lcd_next_line(TEXT_RIGHT_TO_ICON); // position text behind the icon, Line 3 lcd_show_Cg(); // show Cg=xxxpF #ifdef SHOW_R_DS lcd_show_rds(TEXT_RIGHT_TO_ICON-1); // show RDS at column behind the icon -1 #endif } else { /* depletion mode */ if ((PartMode&0x0f) != PART_MODE_JFET) { /* kein JFET */ ReadCapacity(_trans->b,_trans->e); //measure capacity lcd_show_Cg(); // show Cg=xxxpF #ifdef FET_Idss } else { // it is a JFET // display the I_DSS, if measured if (_trans->uBE!=0) { static const unsigned char str_Idss[] MEM_TEXT = "Idss="; lcd_MEM_string(str_Idss); DisplayValue16(_trans->uBE,-6,'A',2); } #endif } // set cursor below the icon #define LINE_BELOW_ICON ((ICON_HEIGHT/8)/((FONT_HEIGHT+7)/8)) #if LCD_LINES > 6 lcd_set_cursor((LINE_BELOW_ICON + 1) * PAGES_PER_LINE,0); #else lcd_set_cursor(LINE_BELOW_ICON * PAGES_PER_LINE,0); #endif lcd_data('I'); #if (LCD_LINE_LENGTH > 17) lcd_data('d'); #endif lcd_equal(); // lcd_data('='); DisplayValue16(_trans->current,-6,'A',2); lcd_MEM_string(Vgs_str); // "@Vg=" Display_mV(_trans->gthvoltage,2); //Gate-threshold voltage #ifdef SHOW_ICE // Display also the cutoff gate voltage, idea from Pieter-Tjerk if (_trans->ice0<4800) { // can't trust cutoff voltage if close to 5V supply voltage, since then the transistor may not have been cut off at all lcd_next_line_wait(0); lcd_data('I'); #if (LCD_LINE_LENGTH > 17) lcd_data('d'); #endif lcd_equal(); // lcd_data('='); DisplayValue16(0,-5,'A',2); lcd_MEM_string(Vgs_str); // "@Vg=" Display_mV(_trans->ice0,2); // cutoff Gate voltage #endif } #ifdef SHOW_R_DS lcd_show_rds(0); // show Drain-Source resistance RDS at column 0 #endif } /* end of enhancement or depletion mode WITH_GRAPHICS */ #else /* character display */ if((PartMode&D_MODE) != D_MODE) { //enhancement-MOSFET //Gate capacity lcd_line2(); // line 2 ReadCapacity(_trans->b,_trans->e); //measure capacity lcd_show_Cg(); // show Cg=xxxpF lcd_MEM_string(vt_str); // " Vt=" Display_mV(_trans->gthvoltage,2); //Gate-threshold voltage #ifdef SHOW_R_DS lcd_show_rds(0); // show Drain-Source resistance RDS at column 0 #endif } else { // depletion #if FLASHEND > 0x1fff if ((PartMode&0x0f) != PART_MODE_JFET) { /* kein JFET */ lcd_next_line(0); // line 2 ReadCapacity(_trans->b,_trans->e); //measure capacity lcd_show_Cg(); // show Cg=xxxpF #ifdef FET_Idss } else { // it is a JFET // display the I_DSS, if measured if (_trans->uBE!=0) { lcd_next_line(0); static const unsigned char str_Idss[] MEM_TEXT = "Idss="; lcd_MEM_string(str_Idss); DisplayValue16(_trans->uBE,-6,'A',2); } #endif } lcd_next_line_wait(0); // line 2 or 3, if possible & wait and clear last line #endif lcd_data('I'); // show I=xmA@Vg=y.yV at line 2 or 3 #if (LCD_LINE_LENGTH > 17) lcd_data('d'); #endif lcd_equal(); // lcd_data('='); DisplayValue16(_trans->current,-6,'A',2); lcd_MEM_string(Vgs_str); // "@Vg=" Display_mV(_trans->gthvoltage,2); //Gate-threshold voltage #ifdef SHOW_ICE // Display also the cutoff gate voltage, idea from Pieter-Tjerk if (_trans->ice0<4800) { // can't trust cutoff voltage if close to 5V supply voltage, since then the transistor may not have been cut off at all lcd_next_line_wait(0); lcd_data('I'); #if (LCD_LINE_LENGTH > 17) lcd_data('d'); #endif lcd_equal(); // lcd_data('='); DisplayValue16(0,-5,'A',2); lcd_MEM_string(Vgs_str); // "@Vg=" Display_mV(_trans->ice0,2); // cutoff Gate voltage } #endif #ifdef SHOW_R_DS lcd_show_rds(0); // show Drain-Source resistance RDS at column 0 #endif } /* end of enhancement or depletion mode */ #endif /* WITH_GRAPHICS or without */ #if DebugOut == 5 lcd_line4(); lcd_data('>'); lcd_data('|'); lcd_space(); DisplayValue16(NumOfDiodes,0,' ',3); #endif #if FLASHEND > 0x1fff if (part_code != PART_MODE_JFET) { for (ii=0;ii<NumOfDiodes;ii++) { // there is enough space for long form of presenting protection diode #if LCD_LINES > 6 if (ii == 0) lcd_next_line(0); // line 5 , if possible #endif lcd_next_line_wait(0); // line 4, if possible & wait 5s and clear last line DiodeSymbol_withPins(ii); lcd_MEM_string(Uf_str); //"Uf=" mVAusgabe(ii); // uart_newline(); // MAURO OK N-E-MOS/IGBT ('F') } /* end for ii (NumOfDiodes) */ } /* PART_MODE != JFET */ #endif #ifdef WITH_GRAPHICS if (part_code == PART_MODE_IGBT) { PinLayoutLine('E','G','C'); // Pin 1=... } else if (part_code == PART_MODE_JFET) { PinLayoutLine('?','G','?'); // Pin 1=... } else { PinLayoutLine('S','G','D'); // Pin 1=... } uart_newline(); // MAURO OK IGBT ('G') #endif goto tt_end; } /* end (PartFound == PART_FET) */ // if(PartFound == PART_RESISTOR) resistor_out: if (ResistorsFound != 0) { if (ResistorsFound == 1) { // single resistor rpins.pw = Rnum2pins(ResistorList[0]); // get pin numbers for resistor 1 #if FLASHEND <= 0x1fff lcd_testpin(rpins.pb[0]); //Pin-number 1 lcd_MEM_string(Resistor_str); // -[=]- lcd_testpin(rpins.pb[1]); //Pin-number 2 lcd_line2(); //2. row RvalOut(ResistorList[0]); #else #if FLASHEND > 0x3fff if ((ResistorList[0] == 1) && (NumOfDiodes == 0)) { // is the TP1:TP3 resistor and no additional diode show_Resis13(); // call of the special resistor measurement goto shut_off; // key is pressed or timeout } #endif show_resis(rpins.pb[0],rpins.pb[1],0); #endif } else { // multiple resistors found, R-Max suchen ii = ResistorList[0]; // first resistor in the list with number 0,1,2 if (ResistorVal[ResistorList[1]] > ResistorVal[ii]) ii = ResistorList[1]; // second resistor in the list with number 0,1,2 if (ResistorsFound == 2) { ii = (3 - ResistorList[0] - ResistorList[1]); } else { if (ResistorVal[ResistorList[2]] > ResistorVal[ii]) { ii = ResistorList[2]; } } // ResistorVal[0] TP1:TP2, [1] TP1:TP3, [2] TP2:TP3 #if (TP2!=TP1+1 || TP3!=TP2+1) x = TP1; y = TP3; z = TP2; if (ii == 1) { /* TP1:TP3 is maximum */ x = TP1; y = TP2; z = TP3; } if (ii == 2) { /* TP2:TP3 is maximum */ x = TP2; y = TP1; z = TP3; } #else // the following does the same as the above, but more cryptically (and in fewer instructions) x = TP1+(ii>>1); y = TP3-ii; z = TP2+(ii>0); #endif lcd_testpin(x); //Pin-number 1 lcd_MEM_string(Resistor_str); // -[=]- lcd_testpin(y); //Pin-number 2 lcd_MEM_string(Resistor_str); // -[=]- lcd_testpin(z); //Pin-number 3 lcd_next_line(0); // output resistor values in right order // if (ii == 0) { /* resistor 0 has maximum */ // RvalOut(1); // RvalOut(2); // } // if (ii == 1) { /* resistor 1 has maximum */ // RvalOut(0); // RvalOut(2); // } // if (ii == 2) { /* resistor 2 has maximum */ // RvalOut(0); // RvalOut(1); // } // again a shorter but cryptical equivalent: RvalOut(ii==0); RvalOut(2-(ii>>1)); } // end ResistorsFound==1 goto tt_end; } // end (PartFound == PART_RESISTOR) lcd_MEM_string(TestFailed1); //"Kein,unbek. oder" lcd_line2(); //2. row #if defined(LANG_ITALIAN) || defined(LANG_FRANCAIS) //italiano or francais lcd_MEM_string(Bauteil); //"campione" lcd_space(); lcd_MEM_string(TestFailed2); //"guasto " #else lcd_MEM_string(TestFailed2); //"defektes " lcd_MEM_string(Bauteil); //"Bauteil" #endif not_known: // uart_newline(); // MAURO added #ifdef WITH_GRAPHICS lcd_big_icon(QUESTION); // show big question mark #endif #if POWER_OFF+0 > 1 empty_count++; mess_count = 0; #endif max_time = SHORT_WAIT_TIME; // use allways the short wait time goto end2; //gakAusgabe: // PinLayout(Cathode_char,'G','A'); // CGA= or 123=... TyUfAusgabe: #ifdef WITH_THYRISTOR_GATE_V #ifdef WITH_GRAPHICS lcd_set_cursor(1*PAGES_PER_LINE,TEXT_RIGHT_TO_ICON); // position behind the icon,line 2 #else lcd_line2(); //2. row #endif lcd_MEM_string(Uf_str); // "Uf=" #ifdef WITH_PUT Display_mV(_trans->uBE,2); // needed instead of ntrans for PUT, but costs 4 bytes more flash... #else Display_mV(ntrans.uBE,2); #endif // uart_newline(); // MAURO ('I') #endif //- - - - - - - - - - - - - - - - - - - - - - - - - - - - tt_end: #if POWER_OFF+0 > 1 empty_count = 0; // reset counter, if part is found mess_count++; // count measurements #endif max_time = display_time; // full specified wait time end2: ADC_DDR = (1<<TPRELAY) | TXD_MSK; // switch pin with reference to GND, release relay lcd_refresh(); // write the pixels to display, ST7920 only while (!(RST_PIN_REG & (1 << RST_PIN))) ; //wait ,until button is released #ifdef WITH_ROTARY_SWITCH wait_again: #endif ii = wait_for_key_ms(max_time); #if POWER_OFF+0 > 1 #ifdef WITH_ROTARY_SWITCH if ((ii > 0) || (rotary.incre > 0)) #else if (ii > 0) #endif { empty_count = 0; // reset counter, if any switch activity mess_count = 0; } #endif #ifdef WITH_MENU #ifdef WITH_ROTARY_SWITCH if ((ii >=50) || (rotary.incre > 2)) #else if (ii >= 50) #endif { // menu selected by long key press or rotary switch while(function_menu());// start the function menu goto loop_start; } #endif if (ii != 0) goto loop_start; // key is pressed again, repeat measurement #ifdef WITH_ROTARY_SWITCH if (rotary.incre > 0) goto wait_again; #endif #ifdef POWER_OFF #if POWER_OFF > 127 #define POWER2_OFF 255 #else #define POWER2_OFF POWER_OFF*2 #endif #if POWER_OFF+0 > 1 if ((empty_count < POWER_OFF) && (mess_count < POWER2_OFF)) { goto loop_start; // repeat measurement POWER_OFF times } #endif // only one Measurement requested, shut off #if FLASHEND > 0x3fff shut_off: // look, if the tester is uncalibrated (C-source will be included directly) lcd_cursor_off(); /* HelpCalibration Begin */ #if defined(AUTO_CAL) && (FLASHEND > 0x3fff) // Check is direct included in the main source of the TransistorTester // a function with a call from main will use additional 38 bytes of flash // define additional variables , ii is already defined in main #define TIME_TO_READ 10000 if (UnCalibrated) { #ifndef SHORT_UNCAL_MSG unsigned int jj; char zeich; uint8_t space_pos; uint8_t line_nr; uint8_t sub_line; // Output the help text for calibration. // The text is formatted for two 16 character display lines. jj = 0; zeich = ' '; // initial value for while loop line_nr = LCD_LINES; // begin with the first LCD line, but don't wait while (zeich != (char)0) { // zero is end of text space_pos = LCD_LINE_LENGTH; // if no space is found for (ii=0;ii<(LCD_LINE_LENGTH+1);ii++) { // look for the last space character zeich = pgm_read_byte(&HelpCalibration_str[ii+jj]); if (zeich == ' ') space_pos = ii; // save the position } if (line_nr == 0) { // it is the first LCD line, wait for showing the last message if ((wait_for_key_ms(TIME_TO_READ)) != 0) break; // key pressed } sub_line = line_nr % LCD_LINES; if (sub_line == 0) lcd_clear(); // clear display, line_nr is 0 or 4 lcd_set_cursor(sub_line*PAGES_PER_LINE ,0); uart_newline(); wdt_reset(); line_nr = (line_nr + 1) % LCD_LINES; for (ii=0;ii<space_pos;ii++) { zeich = pgm_read_byte(&HelpCalibration_str[ii+jj]); if (zeich == (char)0) break; // end of text found if (zeich == LCD_CHAR_INSEP) { lcd_space(); // replace with space } else { lcd_data(zeich); // display the character without offset } } if (zeich == (char)0) break; // end of text found jj += space_pos; // start position of line 2 if((pgm_read_byte(&HelpCalibration_str[jj])) == ' ') jj++; // no space at begin of line } /* end while */ #else lcd_clear(); lcd_pgm_string(HelpCalibration_str); // only short message! #ifdef WITH_UART //Mauro // uart_newline(); //Mauro #endif //Mauro #endif wait_for_key_ms(TIME_TO_READ); // key pressed } #endif /* AUTO_CAL && (FLASHEND > 0x3fff) */ /* HelpCalibration End */ #endif // MCUSR = 0; switch_tester_off(); #else /* no POWER_OFF */ shut_off: // look, if the tester is uncalibrated (C-source will be included directly) lcd_cursor_off(); /* HelpCalibration Begin */ #if defined(AUTO_CAL) && (FLASHEND > 0x3fff) // Check is direct included in the main source of the TransistorTester // a function with a call from main will use additional 38 bytes of flash // define additional variables , ii is already defined in main #define TIME_TO_READ 10000 if (UnCalibrated) { #ifndef SHORT_UNCAL_MSG unsigned int jj; char zeich; uint8_t space_pos; uint8_t line_nr; uint8_t sub_line; // Output the help text for calibration. // The text is formatted for two 16 character display lines. jj = 0; zeich = ' '; // initial value for while loop line_nr = LCD_LINES; // begin with the first LCD line, but don't wait while (zeich != (char)0) { // zero is end of text space_pos = LCD_LINE_LENGTH; // if no space is found for (ii=0;ii<(LCD_LINE_LENGTH+1);ii++) { // look for the last space character zeich = pgm_read_byte(&HelpCalibration_str[ii+jj]); if (zeich == ' ') space_pos = ii; // save the position } if (line_nr == 0) { // it is the first LCD line, wait for showing the last message if ((wait_for_key_ms(TIME_TO_READ)) != 0) break; // key pressed } sub_line = line_nr % LCD_LINES; if (sub_line == 0) lcd_clear(); // clear display, line_nr is 0 or 4 lcd_set_cursor(sub_line*PAGES_PER_LINE ,0); uart_newline(); wdt_reset(); line_nr = (line_nr + 1) % LCD_LINES; for (ii=0;ii<space_pos;ii++) { zeich = pgm_read_byte(&HelpCalibration_str[ii+jj]); if (zeich == (char)0) break; // end of text found if (zeich == LCD_CHAR_INSEP) { lcd_space(); // replace with space } else { lcd_data(zeich); // display the character without offset } } if (zeich == (char)0) break; // end of text found jj += space_pos; // start position of line 2 if((pgm_read_byte(&HelpCalibration_str[jj])) == ' ') jj++; // no space at begin of line } /* end while */ #else lcd_clear(); lcd_pgm_string(HelpCalibration_str); // only short message! #ifdef WITH_UART //Mauro // uart_newline(); //Mauro #endif //Mauro #endif wait_for_key_ms(TIME_TO_READ); // key pressed } #endif /* AUTO_CAL && (FLASHEND > 0x3fff) */ /* HelpCalibration End */ #endif goto loop_start; // POWER_OFF not selected, repeat measurement // return 0; end3: // uart_newline(); // MAURO ('H') // the diode is already shown on the LCD if (ResistorsFound == 0) goto tt_end; ADC_DDR = (1<<TPRELAY) | TXD_MSK; // switch pin with reference to GND, release relay // there is one resistor or more detected #if (LCD_LINES > 3) ADC_DDR = TXD_MSK; // switch pin with reference to input, activate relay #ifdef WAIT_LINE2_CLEAR lcd_next_line_wait(0); #else lcd_line3(); #endif #else wait_for_key_ms(display_time); ADC_DDR = TXD_MSK; // switch pin with reference to input, activate relay lcd_clear(); //#if FLASHEND > 0x1fff lcd_data('0'+NumOfDiodes); lcd_MEM_string(Dioden); //"Diodes " //#endif #endif goto resistor_out; } // ****** end setup() ***** end main // function search_vak_diode try to find a diode, which has no side connected to the transistor base // returns 20, if no diode found uint8_t search_vak_diode() { uint8_t ii; for (ii=0; ii<NumOfDiodes; ii++) { if ((diodes.Anode[ii] == _trans->b) || (diodes.Cathode[ii] == _trans->b)) continue; // no side of the diode is connected to the base, this must be the protection diode if (diodes.Voltage[ii] > 1000) break; // Voltage is too high for protection diode return ii; } return 20; } /* init_parts initialize all parts to nothing found */ void init_parts(void) { PartFound = PART_NONE; // no part found NumOfDiodes = 0; // Number of diodes = 0 ptrans.count = 0; // Number of found P type transistors ntrans.count = 0; // Number of found N type transistors PartMode = PART_MODE_NONE; WithReference = 0; // no precision reference voltage ResistorsFound = 0; // no resistors found ResistorChecked[0] = 0; ResistorChecked[1] = 0; ResistorChecked[2] = 0; cap.ca = TP1; cap.cb = TP3; #if FLASHEND > 0x1fff inductor_lpre = 0; // mark as zero cap.v_loss = 0; // set Vloss to zero #endif cap.cval_max = 0; // set max to zero cap.cpre_max = -15; // set max to fF unit } void switch_tester_off(void) { #ifdef WITH_UART uart_putc('O'); // MAURO uart_putc('F'); // MAURO uart_putc('F'); // MAURO // uart_newline(); // MAURO #endif #if ((LCD_ST_TYPE == 7565) || (LCD_ST_TYPE == 1306)) lcd_powersave(); // set graphical display to power save mode #endif ON_PORT &= ~(1<<ON_PIN); //switch off power wait2s(); wait_for_key_ms(0); //never ending loop } #ifdef WITH_SELFTEST /* Begin AutoCheck.c */ // Selftest of the device and calibration #ifdef WITH_SELFTEST void AutoCheck(uint8_t test_mode) { /* (test_mode & 0x0f) == 0 , only calibration without T1-T7 */ /* (test_mode & 0x0f) == 1 , calibration and additional T1-T7 */ /* (test_mode & 0xf0) == 0 , check for shorted probes, if unshorted, return */ /* (test_mode & 0xf0) == 0x10 , ask for shorted probes */ uint8_t ww; // counter for repeating the tests int adcmv[7]; #ifdef EXTENDED_TESTS uint16_t u680; // 3 * (Voltage at 680 Ohm) uint8_t taste; // ist key pressed? 0 = no #else #ifndef NO_TEST_T1_T7 #warning "Selftest without extended tests T1 to T7!" #endif #endif #if defined(EXTENDED_TESTS) || defined(WITH_MENU) uint8_t tt; // number of running test #endif #ifdef FREQUENCY_50HZ uint8_t ff50; // loop counter for 2s #endif // define the maximum count of repetitions MAX_REP #define MAX_REP 4 #ifdef AUTO_CAL uint8_t cap_found; // counter for found capacitor #ifdef AUTOSCALE_ADC int8_t udiff; // difference between ADC Voltage with VCC or Bandgap reference int8_t udiff2; #endif #endif PartFound = PART_NONE; // no part found before if ((test_mode & 0xf0) == 0) { // probed should be shorted already to begin selftest if (AllProbesShorted() != 3) return; lcd_clear(); lcd_MEM_string(SELFTEST); // "Selftest mode.." lcd_line2(); lcd_data('?'); // wait for key pressed for confirmation if (wait_for_key_ms(2000) > 10) goto begin_selftest; // key is pressed again #ifdef WITH_MENU } else { // report to user, that probes should be shorted ww = 0; for (tt=0;tt<150;tt++) { /* wait about 30 seconds for shorted probes */ lcd_clear(); lcd_MEM2_string(SHORT_PROBES_str); // message "Short probes!" to LCD if (AllProbesShorted() == 3) { ww++; // all probes now shorted } else { ww = 0; // connection not stable, retry } if (ww > 3) break; // connection seems to be stable lcd_refresh(); // write the pixels to display, ST7920 only wait_about200ms(); // wait 200ms and try again } /* end for (tt...) */ if (tt < 150) goto begin_selftest; // is shorted before time limit goto no_zero_resistance; // skip measuring of the zero resistance #endif } // no key pressed for 2s lcd_clear(); lcd_MEM_string(VERSION_str); //"Version ..." return; begin_selftest: lcd_line2(); Calibrate_UR(); // get Reference voltage, Pin resistance lcd_MEM2_string(R0_str); // "R0=" eeprom_write_byte((uint8_t *)(&EE_ESR_ZEROtab[2]), (uint8_t)0); // clear zero offset eeprom_write_byte((uint8_t *)(&EE_ESR_ZEROtab[3]), (uint8_t)0); // clear zero offset eeprom_write_byte((uint8_t *)(&EE_ESR_ZEROtab[1]), (uint8_t)0); // clear zero offset adcmv[0] = GetESR(TP3, TP1); adcmv[1] = GetESR(TP3, TP2); adcmv[2] = GetESR(TP2, TP1); DisplayValue16(adcmv[0],-2,' ',3); DisplayValue16(adcmv[1],-2,' ',3); DisplayValue16(adcmv[2],-2,LCD_CHAR_OMEGA,3); if (adcmv[0] >= 90) { adcmv[0] = ESR_ZERO; // set back to default value } eeprom_write_byte((uint8_t *)(&EE_ESR_ZEROtab[2]), (uint8_t)adcmv[0]); // fix zero offset if (adcmv[1] >= 90) { adcmv[1] = ESR_ZERO; // set back to default value } eeprom_write_byte((uint8_t *)(&EE_ESR_ZEROtab[3]), (uint8_t)adcmv[1]); // fix zero offset if (adcmv[2] >= 90) { adcmv[2] = ESR_ZERO; // set back to default value } eeprom_write_byte((uint8_t *)(&EE_ESR_ZEROtab[1]), (uint8_t)adcmv[2]); // fix zero offset last_line_used = 2; wait_for_key_5s_line2(); // wait up to 5 seconds and clear line 2 #ifdef WITH_MENU no_zero_resistance: #endif #ifdef EXTENDED_TESTS #define TEST_COUNT 8 if((test_mode & 0x0f) == 1) { /* full test requested */ for(tt=1;tt<TEST_COUNT;tt++) { // loop for all Tests for(ww=0;ww<MAX_REP;ww++) { // repeat the test MAX_REP times lcd_clear_line2(); // clear total line 2 lcd_clear_line1(); // clear total line 1 lcd_data('T'); //output the Testmode "T" u2lcd(tt); //lcd_string(utoa(tt, outval, 10)); //output Test number lcd_space(); //############################################ if (tt == 1) { // output of reference voltage and factors for capacity measurement lcd_MEM2_string(URef_str); //"URef=" Display_mV(ref_mv,4); lcd_line2(); //Cursor to column 1, row 2 lcd_MEM2_string(RHfakt_str); //"RHf=" u2lcd(RHmultip); //lcd_string(utoa(RHmultip, outval, 10)); ADCconfig.Samples = R_ANZ_MESS; // set number of ADC reads near to maximum } //############################################ if (tt == 2) { // how equal are the RL resistors? u680 = ((long)ADCconfig.U_AVCC * (PIN_RM + R_L_VAL) / (PIN_RM + R_L_VAL + R_L_VAL + PIN_RP)); R_PORT = 1<<PIN_RL1; //RL1 to VCC R_DDR = (1<<PIN_RL1) | (1<<PIN_RL2); //RL2 to - adcmv[0] = W20msReadADC(TP1); adcmv[0] -= u680; R_DDR = (1<<PIN_RL1) | (1<<PIN_RL3); //RL3 to - adcmv[1] = W20msReadADC(TP1); adcmv[1] -= u680; R_PORT = 1<<PIN_RL2; //RL2 to VCC R_DDR = (1<<PIN_RL2) | (1<<PIN_RL3); //RL3 to - adcmv[2] = W20msReadADC(TP2); adcmv[2] -= u680; lcd_MEM_string(RLRL_str); // "RLRL" } //############################################ if (tt == 3) { // how equal are the RH resistors R_PORT = 1<<PIN_RH1; //RH1 to VCC R_DDR = (1<<PIN_RH1) | (1<<PIN_RH2); //RH2 to - adcmv[0] = W20msReadADC(TP1); adcmv[3] = ADCconfig.U_AVCC / 2; adcmv[0] -= adcmv[3]; R_DDR = (1<<PIN_RH1) | (1<<PIN_RH3); //RH3 to - adcmv[1] = W20msReadADC(TP1); adcmv[1] -= adcmv[3]; R_PORT = 1<<PIN_RH2; //RH2 to VCC R_DDR = (1<<PIN_RH2) | (1<<PIN_RH3); //RH3 to - adcmv[2] = W20msReadADC(TP2); adcmv[2] -= adcmv[3]; lcd_MEM_string(RHRH_str); // "RHRH" } //############################################ if (tt == 4) { // Text release probes lcd_MEM_string(RELPROBE); // "Release Probes" if (AllProbesShorted() != 0) ww = MAX_REP-2; } //############################################ if (tt == 5) { // can we switch the ADC pins to GND across R_H resistor? R_PORT = 0; R_DDR = 1<<PIN_RH1; //Pin 1 over R_H to GND adcmv[0] = W20msReadADC(TP1); R_DDR = 1<<PIN_RH2; //Pin 2 over R_H to GND adcmv[1] = W20msReadADC(TP2); R_DDR = 1<<PIN_RH3; //Pin 3 over R_H to GND adcmv[2] = W20msReadADC(TP3); lcd_MEM_string(RH1L_str); // "RH_Lo=" } //############################################ if (tt == 6) { // can we switch the ADC pins to VCC across the R_H resistor? R_DDR = 1<<PIN_RH1; //Pin 1 over R_H to VCC R_PORT = 1<<PIN_RH1; adcmv[0] = W20msReadADC(TP1) - ADCconfig.U_AVCC; R_DDR = 1<<PIN_RH2; //Pin 2 over R_H to VCC R_PORT = 1<<PIN_RH2; adcmv[1] = W20msReadADC(TP2) - ADCconfig.U_AVCC; R_DDR = 1<<PIN_RH3; //Pin 3 over R_H to VCC R_PORT = 1<<PIN_RH3; adcmv[2] = W20msReadADC(TP3) - ADCconfig.U_AVCC; lcd_MEM_string(RH1H_str); // "RH_Hi=" } if (tt == 7) { // is the voltage of all R_H / R_L dividers correct? u680 = ((long)ADCconfig.U_AVCC * (PIN_RM + R_L_VAL) / (PIN_RM + R_L_VAL + (unsigned long)R_H_VAL*100)); R_PORT = 1<<PIN_RH1; //RH1 to VCC R_DDR = (1<<PIN_RH1) | (1<<PIN_RL1); //RH1 to +, RL1 to - adcmv[0] = W20msReadADC(TP1); adcmv[0] -= u680; R_PORT = 1<<PIN_RH2; //RH2 to VCC R_DDR = (1<<PIN_RH2) | (1<<PIN_RL2); //RH2 to +, RL2 to - adcmv[1] = W20msReadADC(TP2); adcmv[1] -= u680; R_PORT = 1<<PIN_RH3; //RH3 to VCC R_DDR = (1<<PIN_RH3) | (1<<PIN_RL3); //RH3 to +, RL3 to - adcmv[2] = W20msReadADC(TP3); adcmv[2] -= u680; lcd_MEM_string(RHRL_str); // "RH/RL" } //############################################ if (tt > 1) { // output 3 voltages lcd_line2(); //Cursor to column 1, row 2 i2lcd(adcmv[0]); // lcd_string(itoa(adcmv[0], outval, 10)); //output voltage 1 lcd_space(); i2lcd(adcmv[1]); // lcd_string(itoa(adcmv[1], outval, 10)); //output voltage 2 lcd_space(); i2lcd(adcmv[2]); // lcd_string(itoa(adcmv[2], outval, 10)); //output voltage 3 } ADC_DDR = TXD_MSK; // all-Pins to Input ADC_PORT = TXD_VAL; // all ADC-Ports to GND R_DDR = 0; // all R-Ports to Input R_PORT = 0; taste = wait_for_key_ms(1000); // wait up to 1 second or key is pressed if ((tt != 4) && (taste > 10)) { // don't finish repetition for T4 with pressed key break; // if key is pressed, don't repeat } } //end for ww wait_for_key_ms(1000); // wait up to 1 second or key is pressed } //end for tt #if PROCESSOR_TYP == 1280 lcd_clear(); lcd_testpin(TP1); lcd_data('L'); lcd_equal(); // lcd_data('='); ADC_PORT = TXD_VAL; ADC_DDR = (1<<TP1) | TXD_MSK; R_PORT = (1<<PIN_RL1); R_DDR = (1<<PIN_RL1); adcmv[0] = W5msReadADC(TP1); ADCSRB = (1<<MUX5); // switch to upper 8 MUX inputs adcmv[1] = ReadADC(PIN_RL1); ADCSRB = 0; // switch back to lower 8 MUX inputs ResistorVal[0] = (adcmv[0] * (unsigned long)R_L_VAL) / (adcmv[1] - adcmv[0]); DisplayValue(ResistorVal[0],-1,LCD_CHAR_OMEGA,3); lcd_space(); lcd_data('H'); lcd_equal(); // lcd_data('='); ResistorVal[1] = (vcc_diff(adcmv[1]) * (unsigned long)R_L_VAL) / (adcmv[1] - adcmv[0]); DisplayValue(ResistorVal[1],-1,LCD_CHAR_OMEGA,3); lcd_line2(); lcd_testpin(TP1); lcd_space(); lcd_data('H'); lcd_equal(); // lcd_data('='); ADC_PORT = (1<<TP1) | TXD_VAL; R_PORT = 0; adcmv[0] = W5msReadADC(TP1); ADCSRB = (1<<MUX5); // switch to upper 8 MUX inputs adcmv[1] = ReadADC(PIN_RL1); ADCSRB = 0; // switch back to lower 8 MUX inputs ResistorVal[1] = (vcc_diff(adcmv[0]) * (unsigned long)R_L_VAL) / (adcmv[0] - adcmv[1]); DisplayValue(ResistorVal[1],-1,LCD_CHAR_OMEGA,3); lcd_space(); lcd_data('L'); lcd_equal(); // lcd_data('='); ResistorVal[0] = (adcmv[1] * (unsigned long)R_L_VAL) / (adcmv[0] - adcmv[1]); DisplayValue(ResistorVal[0],-1,LCD_CHAR_OMEGA,3); wait_about1s(); // only for mega1280 last_line_used = 2; wait_for_key_5s_line2(); // wait up to 5 seconds and clear line 2 // lcd_clear(); lcd_testpin(TP2); lcd_data('L'); lcd_equal(); // lcd_data('='); ADC_PORT = TXD_VAL; ADC_DDR = (1<<TP2) | TXD_MSK; R_PORT = (1<<PIN_RL2); R_DDR = (1<<PIN_RL2); adcmv[0] = W5msReadADC(TP2); ADCSRB = (1<<MUX5); // switch to upper 8 MUX inputs adcmv[1] = ReadADC(PIN_RL2); ADCSRB = 0; // switch back to lower 8 MUX inputs ResistorVal[0] = (adcmv[0] * (unsigned long)R_L_VAL) / (adcmv[1] - adcmv[0]); DisplayValue(ResistorVal[0],-1,LCD_CHAR_OMEGA,3); lcd_space(); lcd_data('H'); lcd_equal(); // lcd_data('='); ResistorVal[1] = (vcc_diff(adcmv[1]) * (unsigned long)R_L_VAL) / (adcmv[1] - adcmv[0]); DisplayValue(ResistorVal[1],-1,LCD_CHAR_OMEGA,3); lcd_line2(); lcd_testpin(TP2); lcd_data('H'); lcd_equal(); // lcd_data('='); ADC_PORT = (1<<TP2) | TXD_VAL; R_PORT = 0; adcmv[0] = W5msReadADC(TP2); ADCSRB< |