Components Tester using Arduino Nano
Hello friends, This is very useful gadget for your electronics components. You can check many type of electronics components, such as Resistor, Capacitor, Transistor, Mosfet, Diode, LED, Triac etc. Follow all the step and male your own components tester.
Parts List:
- Arduino Nano : https://amzn.to/3o5p5tu
- 16×2 I2C LCD Panel : https://amzn.to/37lmBBo
- Female Header Pin : https://amzn.to/3jcXKlw
- TP-4056 Charging Module : https://amzn.to/35d2HFU
- MT-3608 Boost Converter : https://amzn.to/3k9v8uJ
- SPST Switch : https://amzn.to/3lW8Tci
Diagram:
Code:
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 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 |
/* \\\|/// \\ - - // ( @ @ ) /--------------------oOOo-(_)-oOOo---------------------\ | | | | | Transistor Tester for Arduino (version 1.08a) | | | | based on code: Karl-Heinz Kubbeler (version 1.08k) | | | | | | Oooo | \--------------------oooO----( )---------------------/ ( ) ) / \ ( (_/ \_) */ #include <avr/io.h> #include <util/delay.h> #include <avr/sleep.h> #include <stdlib.h> #include <string.h> #include <avr/eeprom.h> #include <avr/pgmspace.h> #include <avr/wdt.h> #include <avr/interrupt.h> #include <math.h> #include <stdint.h> #include <avr/power.h> #include <Wire.h> //#include <LiquidCrystal.h> //LiquidCrystal lcd(7, 6, 5, 4, 3, 2); // RS,E,D4,D5,D6,D7 #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); // ******** config options for your Semiconductor tester // Every changing of this Makefile will result in new compiling the whole // programs, if you call make or make upload. #define MCU atmega328p #define F_CPU 16000000UL // Select your language: // Available languages are: LANG_ENGLISH, LANG_GERMAN, LANG_POLISH, LANG_CZECH, LANG_SLOVAK, LANG_SLOVENE, // LANG_DUTCH, LANG_BRASIL, LANG_RUSSIAN, LANG_UKRAINIAN #define LANG_ENGLISH // The LCD_CYRILLIC option is necessary, if you have a display with cyrillic characterset. // This lcd-display don't have a character for Ohm and for u (micro). // Russian language requires a LCD controller with russian characterset and option LCD_CYRILLIC! #define LCD_CYRILLIC // The LCD_DOGM option must be set for support of the DOG-M type of LCD modules with ST7036 controller. // For this LCD type the contrast must be set with software command. //#define LCD_DOGM // Option STRIP_GRID_BOARD selects different board-layout, do not set for standard board! // The connection of LCD is totally different for both versions. //#define STRIP_GRID_BOARD // The WITH_SELFTEST option enables selftest function (only for mega168 or mega328). //#define WITH_SELFTEST // AUTO_CAL will enable the autocalibration of zero offset of capacity measurement and // also the port output resistance values will be find out in SELFTEST section. // With a external capacitor a additionally correction of reference voltage is figured out for // low capacity measurement and also for the AUTOSCALE_ADC measurement. // The AUTO_CAL option is only selectable for mega168 and mega328. //#define AUTO_CAL // FREQUENCY_50HZ enables a 50 Hz frequency generator for up to one minute at the end of selftests. //#define FREQUENCY_50HZ // The WITH_AUTO_REF option enables reading of internal REF-voltage to get factors for the Capacity measuring. #define WITH_AUTO_REF // REF_C_KORR corrects the reference Voltage for capacity measurement (<40uF) and has mV units. // Greater values gives lower capacity results. #define REF_C_KORR 12 // REF_L_KORR corrects the reference Voltage for inductance measurement and has mV units. #define REF_L_KORR 40 // C_H_KORR defines a correction of 0.1% units for big capacitor measurement. // Positive values will reduce measurement results. #define C_H_KORR 0 // The WITH_UART option enables the software UART (TTL level output at Pin PC3, 26). // If the option is deselected, PC3 can be used as external voltage input with a // 10:1 resistor divider. //#define WITH_UART // The CAP_EMPTY_LEVEL defines the empty voltage level for capacitors in mV. // Choose a higher value, if your Tester reports "Cell!" by unloading capacitors. #define CAP_EMPTY_LEVEL 4 // The AUTOSCALE_ADC option enables the autoscale ADC (ADC use VCC and Bandgap Ref). #define AUTOSCALE_ADC #define REF_R_KORR 3 // The ESR_ZERO value define the zero value of ESR measurement (units = 0.01 Ohm). //#define ESR_ZERO 29 #define ESR_ZERO 20 // NO_AREF_CAP tells your Software, that you have no Capacitor installed at pin AREF (21). // This enables a shorter wait-time for AUTOSCALE_ADC function. // A capacitor with 1nF can be used with the option NO_AREF_CAP set. #define NO_AREF_CAP // The OP_MHZ option tells the software the Operating Frequency of your ATmega. // OP_MHZ 16 // Restart from sleep mode will be delayed for 16384 clock tics with crystal mode. // Operation with the internal RC-Generator or external clock will delay the restart by only 6 clock tics. // You must specify this with "#define RESTART_DELAY_TICS=6", if you don't use the crystal mode. //#define RESTART_DELAY_TICS 6 // The USE_EEPROM option specify where you wish to locate fix text and tables. // If USE_EEPROM is unset, program memory (flash) is taken for fix text and tables. //#define USE_EEPROM // Setting EBC_STYPE will select the old style to present the order of Transistor connection (EBC=...). // Omitting the option will select the 123=... style. Every point is replaced by a character identifying // type of connected transistor pin (B=Base, E=Emitter, C=Collector, G=Gate, S=Source, D=Drain). // If you select EBC_STYLE=321 , the style will be 321=... , the inverted order to the 123=... style. //#define EBC_STYLE //#define EBC_STYLE 321 // Setting of NO_NANO avoids the use of n as prefix for Farad (nF), the mikro prefix is used insted (uF). //#define NO_NANO // The PULLUP_DISABLE option disable the pull-up Resistors of IO-Ports. // To use this option a external pull-up Resistor (10k to 30k) // from Pin 13 to VCC must be installed! #define PULLUP_DISABLE // The ANZ_MESS option specifies, how often an ADC value is read and accumulated. // Possible values of ANZ_MESS are 5 to 200. #define ANZ_MESS 25 // The POWER_OFF option enables the power off function, otherwise loop measurements infinitely // until power is disconnected with a ON/OFF switch (#define POWER_OFF). // If you have the tester without the power off transistors, you can deselect POWER_OFF . // If you have NOT selected the POWER_OFF option with the transistors installed, // you can stop measuring by holding the key several seconds after a result is // displayed. After releasing the key, the tester will be shut off by timeout. // Otherwise you can also specify, after how many measurements without found part // the tester will shut down (#define POWER_OFF=5). // The tester will also shut down with found part, // but successfull measurements are allowed double of the specified number. // You can specify up to 255 empty measurements (#define POWER_OFF=255). //#define POWER_OFF 5 //#define POWER_OFF // Option BAT_CHECK enables the Battery Voltage Check, otherwise the SW Version is displayed instead of Bat. // BAT_CHECK should be set for battery powered tester version. //#define BAT_CHECK // The BAT_OUT option enables Battery Voltage Output on LCD (if BAT_CHECK is selected). // If your 9V supply has a diode installed, use the BAT_OUT=600 form to specify the // threshold voltage of your diode to adjust the output value. // This threshold level is added to LCD-output and does not affect the voltage checking levels. //#define BAT_OUT 150 // To adjust the warning-level and poor-level of battery check to the capability of a // low drop voltage regulator, you can specify the Option BAT_POOR=5400 . // The unit for this option value is 1mV , 5400 means a poor level of 5.4V. // The warning level is 0.8V higher than the specified poor level (>5.3V). // The warning level is 0.4V higher than the specified poor level (>2.9V, <=5.3V). // The warning level is 0.2V higher than the specified poor level (>1.3V, <=2.9V). // The warning level is 0.1V higher than the specified poor level (<=1.3V). // Setting the poor level to low values is not recommended for rechargeable Batteries, // because this increase the danger for deep discharge!! #define BAT_POOR 6400 // The sleep mode of the ATmega168 or ATmega328 is normally used by the software to save current. // You can inhibit this with the option INHIBIT_SLEEP_MODE . //#define INHIBIT_SLEEP_MODE // ******** end of selectable options /* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */ // ######## Configuration #ifndef ADC_PORT //#define DebugOut 3 // if set, output of voltages of resistor measurements in row 2,3,4 //#define DebugOut 4 // if set, output of voltages of Diode measurement in row 3+4 //#define DebugOut 5 // if set, output of Transistor checks in row 2+3 //#define DebugOut 10 // if set, output of capacity measurements (ReadCapacity) in row 3+4 /* Port, that is directly connected to the probes. This Port must have an ADC-Input (ATmega8: PORTC). The lower pins of this Port must be used for measurements. Please don't change the definitions of TP1, TP2 and TP3! The TPREF pin can be connected with a 2.5V precision voltage reference The TPext can be used with a 10:1 resistor divider as external voltage probe up to 50V */ #define ADC_PORT PORTC #define ADC_DDR DDRC #define ADC_PIN PINC #define TP1 0 #define TP2 1 #define TP3 2 #define TPext 3 // Port pin for 2.5V precision reference used for VCC check (optional) #define TPREF 4 // Port pin for Battery voltage measuring #define TPBAT 5 /* exact values of used resistors (Ohm). The standard value for R_L is 680 Ohm, for R_H 470kOhm. To calibrate your tester the resistor-values can be adjusted: */ #define R_L_VAL 6800 // standard value 680 Ohm, multiplied by 10 for 0.1 Ohm resolution //#define R_L_VAL 6690 // this will be define a 669 Ohm #define R_H_VAL 47000 // standard value 470000 Ohm, multiplied by 10, divided by 100 //#define R_H_VAL 47900 // this will be define a 479000 Ohm, divided by 100 #define R_DDR DDRB #define R_PORT PORTB /* Port for the Test resistors The Resistors must be connected to the lower 6 Pins of the Port in following sequence: RLx = 680R-resistor for Test-Pin x RHx = 470k-resistor for Test-Pin x RL1 an Pin 0 RH1 an Pin 1 RL2 an Pin 2 RH2 an Pin 3 RL3 an Pin 4 RH3 an Pin 5 */ #define ON_DDR DDRD #define ON_PORT PORTD #define ON_PIN_REG PIND #define ON_PIN 18 // Pin, must be switched to high to switch power on #ifdef STRIP_GRID_BOARD // Strip Grid board version #define RST_PIN 0 // Pin, is switched to low, if push button is pressed #else // normal layout version #define RST_PIN 17 // Pin, is switched to low, if push button is pressed #endif // Port(s) / Pins for LCD #ifdef STRIP_GRID_BOARD // special Layout for strip grid board #define HW_LCD_EN_PORT PORTD #define HW_LCD_EN_PIN 5 #define HW_LCD_RS_PORT PORTD #define HW_LCD_RS_PIN 7 #define HW_LCD_B4_PORT PORTD #define HW_LCD_B4_PIN 4 #define HW_LCD_B5_PORT PORTD #define HW_LCD_B5_PIN 3 #define HW_LCD_B6_PORT PORTD #define HW_LCD_B6_PIN 2 #define HW_LCD_B7_PORT PORTD #define HW_LCD_B7_PIN 1 #else // normal Layout #define HW_LCD_EN_PORT PORTD #define HW_LCD_EN_PIN 6 #define HW_LCD_RS_PORT PORTD #define HW_LCD_RS_PIN 7 #define HW_LCD_B4_PORT PORTD #define HW_LCD_B4_PIN 5 #define HW_LCD_B5_PORT PORTD #define HW_LCD_B5_PIN 4 #define HW_LCD_B6_PORT PORTD #define HW_LCD_B6_PIN 3 #define HW_LCD_B7_PORT PORTD #define HW_LCD_B7_PIN 2 #endif // U_VCC defines the VCC Voltage of the ATmega in mV units #define U_VCC 5000 // integer factors are used to change the ADC-value to mV resolution in ReadADC ! // With the option NO_CAP_HOLD_TIME you specify, that capacitor loaded with 680 Ohm resistor will not // be tested to hold the voltage same time as load time. // Otherwise (without this option) the voltage drop during load time is compensated to avoid displaying // too much capacity for capacitors with internal parallel resistance. // #define NO_CAP_HOLD_TIME // U_SCALE can be set to 4 for better resolution of ReadADC function for resistor measurement #define U_SCALE 4 // R_ANZ_MESS can be set to a higher number of measurements (up to 200) for resistor measurement #define R_ANZ_MESS 190 // Watchdog //#define WDT_enabled /* If you remove the "#define WDT_enabled" , the Watchdog will not be activated. This is only for Test or debugging usefull. For normal operation please activate the Watchdog ! */ // ######## End of configuration #if R_ANZ_MESS < ANZ_MESS #undef R_ANZ_MESS #define R_ANZ_MESS ANZ_MESS #endif #if U_SCALE < 0 // limit U_SCALE #undef U_SCALE #define U_SCALE 1 #endif #if U_SCALE > 4 // limit U_SCALE #undef U_SCALE #define U_SCALE 4 #endif #ifndef REF_L_KORR #define REF_L_KORR 50 #endif // the following definitions specify where to load external data from: EEprom or flash #ifdef USE_EEPROM #define MEM_TEXT EEMEM #if E2END > 0X1FF #define MEM2_TEXT EEMEM #define MEM2_read_byte(a) eeprom_read_byte(a) #define MEM2_read_word(a) eeprom_read_word(a) #define lcd_fix2_string(a) lcd_fix_string(a) #else #define MEM2_TEXT PROGMEM #define MEM2_read_byte(a) pgm_read_byte(a) #define MEM2_read_word(a) pgm_read_word(a) #define lcd_fix2_string(a) lcd_pgm_string(a) #define use_lcd_pgm #endif #define MEM_read_word(a) eeprom_read_word(a) #define MEM_read_byte(a) eeprom_read_byte(a) #else #define MEM_TEXT PROGMEM #define MEM2_TEXT PROGMEM #define MEM_read_word(a) pgm_read_word(a) #define MEM_read_byte(a) pgm_read_byte(a) #define MEM2_read_byte(a) pgm_read_byte(a) #define MEM2_read_word(a) pgm_read_word(a) #define lcd_fix2_string(a) lcd_pgm_string(a) #define use_lcd_pgm #endif // RH_OFFSET : systematic offset of resistor measurement with RH (470k) // resolution is 0.1 Ohm, 3500 defines a offset of 350 Ohm #define RH_OFFSET 3500 // TP2_CAP_OFFSET is a additionally offset for TP2 capacity measurements in pF units #define TP2_CAP_OFFSET 2 // CABLE_CAP defines the capacity (pF) of 12cm cable with clip at the terminal pins #define CABLE_CAP 3 // select the right Processor Typ /* #if defined(__AVR_ATmega48__) #define PROCESSOR_TYP 168 #elif defined(__AVR_ATmega48P__) #define PROCESSOR_TYP 168 #elif defined(__AVR_ATmega88__) #define PROCESSOR_TYP 168 #elif defined(__AVR_ATmega88P__) #define PROCESSOR_TYP 168 #elif defined(__AVR_ATmega168__) #define PROCESSOR_TYP 168 #elif defined(__AVR_ATmega168P__) #define PROCESSOR_TYP 168 #elif defined(__AVR_ATmega328__) #define PROCESSOR_TYP 328 #elif defined(__AVR_ATmega328P__) #define PROCESSOR_TYP 328 #elif defined(__AVR_ATmega640__) #define PROCESSOR_TYP 1280 #elif defined(__AVR_ATmega1280__) #define PROCESSOR_TYP 1280 #elif defined(__AVR_ATmega2560__) #define PROCESSOR_TYP 1280 #else #define PROCESSOR_TYP 8 #endif */ #define PROCESSOR_TYP 328 // automatic selection of right call type #if FLASHEND > 0X1FFF #define ACALL call #else #define ACALL rcall #endif // automatic selection of option and parameters for different AVRs //------------------=========---------- #if PROCESSOR_TYP == 168 //------------------=========---------- #define MCU_STATUS_REG MCUCR #define ADC_COMP_CONTROL ADCSRB #define TI1_INT_FLAGS TIFR1 #define DEFAULT_BAND_GAP 1070 #define DEFAULT_RH_FAKT 884 // mega328 1070 mV // LONG_HFE activates computation of current amplification factor with long variables #define LONG_HFE // COMMON_COLLECTOR activates measurement of current amplification factor in common collector circuit (Emitter follower) #define COMMON_COLLECTOR #define MEGA168A 17 #define MEGA168PA 18 // Pin resistor values of ATmega168 //#define PIN_RM 196 //#define PIN_RP 225 #define PIN_RM 190 #define PIN_RP 220 // CC0 defines the capacity of empty terminal pins 1 & 3 without cable #define CC0 36 // Slew rate correction val += COMP_SLEW1 / (val + COMP_SLEW2) #define COMP_SLEW1 4000 #define COMP_SLEW2 220 #define C_NULL CC0+CABLE_CAP+(COMP_SLEW1 / (CC0 + CABLE_CAP + COMP_SLEW2)) #define MUX_INT_REF 0x0e // channel number of internal 1.1 V //------------------=========---------- #elif PROCESSOR_TYP == 328 //------------------=========---------- #define MCU_STATUS_REG MCUCR #define ADC_COMP_CONTROL ADCSRB #define TI1_INT_FLAGS TIFR1 #define DEFAULT_BAND_GAP 1070 #define DEFAULT_RH_FAKT 884 // mega328 1070 mV // LONG_HFE activates computation of current amplification factor with long variables #define LONG_HFE // COMMON_COLLECTOR activates measurement of current amplification factor in common collector circuit (Emitter follower) #define COMMON_COLLECTOR #define PIN_RM 200 #define PIN_RP 220 // CC0 defines the capacity of empty terminal pins 1 & 3 without cable #define CC0 36 // Slew rate correction val += COMP_SLEW1 / (val + COMP_SLEW2) #define COMP_SLEW1 4000 #define COMP_SLEW2 180 #define C_NULL CC0+CABLE_CAP+(COMP_SLEW1 / (CC0 + CABLE_CAP + COMP_SLEW2)) #define MUX_INT_REF 0x0e // channel number of internal 1.1 V //------------------=========---------- #elif PROCESSOR_TYP == 1280 //------------------=========---------- #define MCU_STATUS_REG MCUCR #define ADC_COMP_CONTROL ADCSRB #define TI1_INT_FLAGS TIFR1 #define DEFAULT_BAND_GAP 1070 #define DEFAULT_RH_FAKT 884 // mega328 1070 mV // LONG_HFE activates computation of current amplification factor with long variables #define LONG_HFE // COMMON_COLLECTOR activates measurement of current amplification factor in common collector circuit (Emitter follower) #define COMMON_COLLECTOR #define PIN_RM 200 #define PIN_RP 220 // CC0 defines the capacity of empty terminal pins 1 & 3 without cable #define CC0 36 // Slew rate correction val += COMP_SLEW1 / (val + COMP_SLEW2) #define COMP_SLEW1 4000 #define COMP_SLEW2 180 #define C_NULL CC0+CABLE_CAP+(COMP_SLEW1 / (CC0 + CABLE_CAP + COMP_SLEW2)) #define MUX_INT_REF 0x1e /* channel number of internal 1.1 V */ //------------------=========---------- #else // ATmega8 //------------------=========---------- #define MCU_STATUS_REG MCUCSR #define ADC_COMP_CONTROL SFIOR #define TI1_INT_FLAGS TIFR #define DEFAULT_BAND_GAP 1298 //mega8 1298 mV #define DEFAULT_RH_FAKT 740 // mega8 1250 mV // LONG_HFE activates computation of current amplification factor with long variables #define LONG_HFE // COMMON_COLLECTOR activates measurement of current amplification factor in common collector circuit (Emitter follower) #define COMMON_COLLECTOR #define PIN_RM 196 #define PIN_RP 240 // CC0 defines the capacity of empty terminal pins 1 & 3 without cable #define CC0 27 // Slew rate correction val += COMP_SLEW1 / (val + COMP_SLEW2) #define COMP_SLEW1 0 #define COMP_SLEW2 33 #define C_NULL CC0+CABLE_CAP+(COMP_SLEW1 / (CC0 + CABLE_CAP + COMP_SLEW2)) #define MUX_INT_REF 0x0e /* channel number of internal 1.1 V */ #ifndef INHIBIT_SLEEP_MODE #define INHIBIT_SLEEP_MODE /* do not use the sleep mode of ATmega */ #endif #endif #if PROCESSOR_TYP == 8 // 2.54V reference voltage + correction (fix for ATmega8) #ifdef AUTO_CAL #define ADC_internal_reference (2560 + (int8_t)eeprom_read_byte((uint8_t *)&RefDiff)) #else #define ADC_internal_reference (2560 + REF_R_KORR) #endif #else // all other processors use a 1.1V reference #ifdef AUTO_CAL #define ADC_internal_reference (ref_mv + (int8_t)eeprom_read_byte((uint8_t *)&RefDiff)) #else #define ADC_internal_reference (ref_mv + REF_R_KORR) #endif #endif #ifndef REF_R_KORR #define REF_R_KORR 0 #endif #ifndef REF_C_KORR #define REF_C_KORR 0 #endif #define LONG_WAIT_TIME 28000 #define SHORT_WAIT_TIME 5000 #ifdef POWER_OFF // if POWER OFF function is selected, wait 14s // if POWER_OFF with parameter > 2, wait only 5s before repeating #if (POWER_OFF+0) > 2 #define OFF_WAIT_TIME SHORT_WAIT_TIME #else #define OFF_WAIT_TIME LONG_WAIT_TIME #endif #else // if POWER OFF function is not selected, wait 14s before repeat measurement #define OFF_WAIT_TIME LONG_WAIT_TIME #endif //********************************************************** // defines for the selection of a correctly ADC-Clock // will match for 1MHz, 2MHz, 4MHz, 8MHz and 16MHz // ADC-Clock can be 125000 or 250000 // 250 kHz is out of the full accuracy specification! // clock divider is 4, when CPU_Clock==1MHz and ADC_Clock==250kHz // clock divider is 128, when CPU_Clock==16MHz and ADC_Clock==125kHz #define F_ADC 125000 //#define F_ADC 250000 #if F_CPU/F_ADC == 2 #define AUTO_CLOCK_DIV (1<<ADPS0) #endif #if F_CPU/F_ADC == 4 #define AUTO_CLOCK_DIV (1<<ADPS1) #endif #if F_CPU/F_ADC == 8 #define AUTO_CLOCK_DIV (1<<ADPS1) | (1<<ADPS0) #endif #if F_CPU/F_ADC == 16 #define AUTO_CLOCK_DIV (1<<ADPS2) #endif #if F_CPU/F_ADC == 32 #define AUTO_CLOCK_DIV (1<<ADPS2) | (1<<ADPS0) #endif #if F_CPU/F_ADC == 64 #define AUTO_CLOCK_DIV (1<<ADPS2) | (1<<ADPS1) #endif #if F_CPU/F_ADC == 128 #define AUTO_CLOCK_DIV (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0) #endif //********************************************************** #define F_ADC_F 500000 #if F_CPU/F_ADC_F == 2 #define FAST_CLOCK_DIV (1<<ADPS0) #endif #if F_CPU/F_ADC_F == 4 #define FAST_CLOCK_DIV (1<<ADPS1) #endif #if F_CPU/F_ADC_F == 8 #define FAST_CLOCK_DIV (1<<ADPS1) | (1<<ADPS0) #endif #if F_CPU/F_ADC_F == 16 #define FAST_CLOCK_DIV (1<<ADPS2) #endif #if F_CPU/F_ADC_F == 32 #define FAST_CLOCK_DIV (1<<ADPS2) | (1<<ADPS0) #endif #if F_CPU/F_ADC_F == 64 #define FAST_CLOCK_DIV (1<<ADPS2) | (1<<ADPS1) #endif #if F_CPU/F_ADC_F == 128 #define FAST_CLOCK_DIV (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0) #endif #ifndef PIN_RP #define PIN_RP 220 // estimated internal resistance PORT to VCC // will only be used, if not set before in config.h #endif #ifndef PIN_RM #define PIN_RM 190 // estimated internal resistance PORT to GND // will only be used, if not set before in config.h #endif //********************************************************** // defines for the WITH_UART option /* With define SWUART_INVERT you can specify, if the software-UART operates normal or invers. in the normal mode the UART sends with usual logik level (Low = 0; High = 1). You can use this mode for direct connection to a uC, or a level converter like MAX232. With invers mode the UART sends with invers logik (Low = 1, High = 0). This is the level of a standard RS232 port of a PC. In most cases the output of the software UART can so be connected to the RxD of a PC. The specification say, that level -3V to 3V is unspecified, but in most cases it works. Is a simple but unclean solution. Is SWUART_INVERT defined, the UART works is inverse mode */ //#define SWUART_INVERT #define TxD 3 // TxD-Pin of Software-UART; must be at Port C ! #ifdef WITH_UART #define TXD_MSK (1<<TxD) #else #define TXD_MSK 0xF8 #endif #ifdef SWUART_INVERT #define TXD_VAL 0 #else #define TXD_VAL TXD_MSK #endif #ifdef INHIBIT_SLEEP_MODE // save memory, do not use the sleep mode #define wait_about5ms() wait5ms() #define wait_about10ms() wait10ms() #define wait_about20ms() wait20ms() #define wait_about30ms() wait30ms() #define wait_about50ms() wait50ms() #define wait_about100ms() wait100ms() #define wait_about200ms() wait200ms() #define wait_about300ms() wait300ms() #define wait_about400ms() wait400ms() #define wait_about500ms() wait500ms() #define wait_about1s() wait1s() #define wait_about2s() wait2s() #define wait_about3s() wait3s() #define wait_about4s() wait4s() #else // use sleep mode to save current for user interface #define wait_about5ms() sleep_5ms(1) #define wait_about10ms() sleep_5ms(2) #define wait_about20ms() sleep_5ms(4) #define wait_about30ms() sleep_5ms(6) #define wait_about50ms() sleep_5ms(10) #define wait_about100ms() sleep_5ms(20) #define wait_about200ms() sleep_5ms(40) #define wait_about300ms() sleep_5ms(60) #define wait_about400ms() sleep_5ms(80) #define wait_about500ms() sleep_5ms(100) #define wait_about1s() sleep_5ms(200) #define wait_about2s() sleep_5ms(400) #define wait_about3s() sleep_5ms(600) #define wait_about4s() sleep_5ms(800) #endif #undef AUTO_RH #ifdef WITH_AUTO_REF #define AUTO_RH #else #ifdef AUTO_CAL #define AUTO_RH #endif #endif #undef CHECK_CALL #ifdef WITH_SELFTEST // AutoCheck Function is needed #define CHECK_CALL #endif #ifdef AUTO_CAL // AutoCheck Function is needed #define CHECK_CALL #define RR680PL resis680pl #define RR680MI resis680mi #define RRpinPL pin_rpl #define RRpinMI pin_rmi #else #define RR680PL (R_L_VAL + PIN_RP) #define RR680MI (R_L_VAL + PIN_RM) #define RRpinPL (PIN_RP) #define RRpinMI (PIN_RM) #endif #ifndef ESR_ZERO // define a default zero value for ESR measurement (0.01 Ohm units) #define ESR_ZERO 20 #endif #ifndef RESTART_DELAY_TICS // define the processor restart delay for crystal oscillator 16K // only set, if no preset (Makefile) exists. #define RESTART_DELAY_TICS 16384 // for ceramic oscillator 258 or 1024 Clock tics can be selected with fuses // for external oscillator or RC-oscillator is only a delay of 6 clock tics. #endif // with EBC_STYLE you can select the Pin-description in EBC= style instead of 123=??? style //#define EBC_STYLE #if EBC_STYLE == 123 // unset the option for the 123 selection, since this style is default. #undef EBC_STYLE #endif // self build characters #define LCD_CHAR_DIODE1 1 // Diode-Icon; will be generated as custom character #define LCD_CHAR_DIODE2 2 // Diode-Icon; will be generated as custom character #define LCD_CHAR_CAP 3 // Capacitor-Icon; will be generated as custom character // numbers of RESIS1 and RESIS2 are swapped for OLED display, which shows a corrupt RESIS1 character otherwise ??? #define LCD_CHAR_RESIS1 7 // Resistor left part will be generated as custom character #define LCD_CHAR_RESIS2 6 // Resistor right part will be generated as custom character #ifdef LCD_CYRILLIC #define LCD_CHAR_OMEGA 4 // Omega-character #define LCD_CHAR_U 5 // micro-character #else #define LCD_CHAR_OMEGA 244 // Omega-character #define LCD_CHAR_U 228 // micro-character #endif #ifdef LCD_DOGM #undef LCD_CHAR_OMEGA #define LCD_CHAR_OMEGA 0x1e // Omega-character for DOGM module #undef LCD_CHAR_U #define LCD_CHAR_U 5 // micro-character for DOGM module loadable #endif #define LCD_CHAR_DEGREE 0xdf // Character for degree #endif // #ifndef ADC_PORT // the hFE (B) can be determined with common collector and common emitter circuit // with more than 16K both methodes are possible #ifdef COMMON_COLLECTOR #if FLASHEND > 0x3fff #define COMMON_EMITTER #endif #else #define COMMON_EMITTER #endif /* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */ #define MAIN_C #if defined (MAIN_C) #define COMMON /* The voltage at a capacitor grows with Uc = VCC * (1 - e**(-t/T)) The voltage 1.3V is reached at t = -ln(3.7/5)*T = 0.3011*T . Time constant is T = R * C ; also C = T / R for the resistor 470 kOhm is C = t / (0.3011 * 470000) H_Fakt = 707/100 for a result in pF units. */ // Big Capacities (>50uF) are measured with up to 500 load-pulses with the 680 Ohm resistor. // Each of this load-puls has an length of 10ms. After every load-pulse the voltage of the // capacitor is measured. If the voltage is more than 300mV, the capacity is computed by // interpolating the corresponding values of the table RLtab and multiply that with the number // of load pulses (*10). // Widerstand 680 Ohm 300 325 350 375 400 425 450 475 500 525 550 575 600 625 650 675 700 725 750 775 800 825 850 875 900 925 950 975 1000 1025 1050 1075 1100 1125 1150 1175 1200 1225 1250 1275 1300 1325 1350 1375 1400 mV const uint16_t RLtab[] MEM_TEXT = {22447,20665,19138,17815,16657,15635,14727,13914,13182,12520,11918,11369,10865,10401, 9973, 9577, 9209, 8866, 8546, 8247, 7966, 7702, 7454, 7220, 6999, 6789, 6591, 6403, 6224, 6054, 5892, 5738, 5590, 5449, 5314, 5185, 5061, 4942, 4828, 4718, 4613, 4511, 4413, 4319, 4228}; #if FLASHEND > 0x1fff // {0, 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 }; const uint16_t LogTab[] PROGMEM = {0, 20, 41, 62, 83, 105, 128, 151, 174, 198, 223, 248, 274, 301, 329, 357, 386, 416, 446, 478, 511, 545, 580, 616, 654, 693, 734, 777, 821, 868, 916, 968, 1022, 1079, 1139, 1204, 1273, 1347, 1427, 1514, 1609, 1715, 1833, 1966, 2120, 2303, 2526 }; #endif #ifdef AUTO_RH // resistor 470000 Ohm 1000 1050 1100 1150 1200 1250 1300 1350 1400 mV const uint16_t RHtab[] PROGMEM = { 954, 903, 856, 814, 775, 740, 707, 676, 648}; #endif // with integer factors the ADC-value will be changed to mV resolution in ReadADC ! // all if statements are corrected to the mV resolution. // Strings in PROGMEM or in EEprom #if defined(LANG_GERMAN) // deutsch const unsigned char TestRunning[] MEM_TEXT = "Testen..."; const unsigned char BatWeak[] MEM_TEXT = "gering"; const unsigned char BatEmpty[] MEM_TEXT = "leer!"; const unsigned char TestFailed2[] MEM_TEXT = "defektes "; const unsigned char Component[] MEM_TEXT = "Bauteil"; // const unsigned char Diode[] MEM_TEXT = "Diode: "; const unsigned char Triac[] MEM_TEXT = "Triac"; const unsigned char Thyristor[] MEM_TEXT = "Thyristor"; const unsigned char Unknown[] MEM_TEXT = " unbek."; const unsigned char TestFailed1[] MEM_TEXT = "Kein,unbek. oder"; const unsigned char OrBroken[] MEM_TEXT = "oder defekt "; const unsigned char TestTimedOut[] MEM_TEXT = "Timeout!"; #define Cathode_char 'K' #ifdef WITH_SELFTEST const unsigned char SELFTEST[] MEM_TEXT = "Selbsttest .."; const unsigned char RELPROBE[] MEM_TEXT = "isolate Probe!"; const unsigned char ATE[] MEM_TEXT = "Test Ende"; #endif #endif #if defined(LANG_ENGLISH) // english const unsigned char TestRunning[] MEM_TEXT = "testing..."; const unsigned char BatWeak[] MEM_TEXT = "weak"; const unsigned char BatEmpty[] MEM_TEXT = "empty!"; const unsigned char TestFailed2[] MEM_TEXT = "damaged "; const unsigned char Component[] MEM_TEXT = "part"; //const unsigned char Diode[] MEM_TEXT = "Diode: "; const unsigned char Triac[] MEM_TEXT = "Triac"; const unsigned char Thyristor[] MEM_TEXT = "Thyristor"; const unsigned char Unknown[] MEM_TEXT = " unknown"; const unsigned char TestFailed1[] MEM_TEXT = "No, unknown, or"; const unsigned char OrBroken[] MEM_TEXT = "or damaged "; const unsigned char TestTimedOut[] MEM_TEXT = "Timeout!"; #define Cathode_char 'C' #ifdef WITH_SELFTEST const unsigned char SELFTEST[] MEM_TEXT = "Selftest mode.."; const unsigned char RELPROBE[] MEM_TEXT = "isolate Probe!"; const unsigned char ATE[] MEM_TEXT = "Test End"; #endif #endif // Strings, which are not dependent of any language const unsigned char Bat_str[] MEM_TEXT = "Bat. "; const unsigned char OK_str[] MEM_TEXT = "OK"; const unsigned char mosfet_str[] MEM_TEXT = "-MOS"; const unsigned char jfet_str[] MEM_TEXT = "JFET"; const unsigned char GateCap_str[] MEM_TEXT = "C="; const unsigned char hfe_str[] MEM_TEXT ="B="; const unsigned char NPN_str[] MEM_TEXT = "NPN "; const unsigned char PNP_str[] MEM_TEXT = "PNP "; #ifndef EBC_STYLE const unsigned char N123_str[] MEM_TEXT = " 123="; //const unsigned char N123_str[] MEM_TEXT = " Pin="; #else #if EBC_STYLE == 321 const unsigned char N321_str[] MEM_TEXT = " 321="; #endif #endif const unsigned char Uf_str[] MEM_TEXT = "Uf="; const unsigned char vt_str[] MEM_TEXT = " Vt="; const unsigned char Vgs_str[] MEM_TEXT = "@Vgs="; const unsigned char CapZeich[] MEM_TEXT = {'-',LCD_CHAR_CAP,'-',0}; const unsigned char Cell_str[] MEM_TEXT = "Cell!"; const unsigned char VCC_str[] MEM_TEXT = "VCC="; #if FLASHEND > 0x1fff const unsigned char ESR_str[] MEM_TEXT = " ESR="; const unsigned char VLOSS_str[] MEM_TEXT = " Vloss="; const unsigned char Lis_str[] MEM_TEXT = "L="; const unsigned char Ir_str[] MEM_TEXT = " Ir="; #ifndef WITH_UART //#define WITH_VEXT #endif #else #ifndef BAT_CHECK #ifndef WITH_UART //#define WITH_VEXT #endif #endif #endif #ifdef WITH_VEXT const unsigned char Vext_str[] MEM_TEXT = "Vext="; #define LCD_CLEAR #endif const unsigned char VERSION_str[] MEM2_TEXT = "Ttester 1.08.001"; const unsigned char AnKat[] MEM_TEXT = {'-', LCD_CHAR_DIODE1, '-',0}; const unsigned char KatAn[] MEM_TEXT = {'-', LCD_CHAR_DIODE2, '-',0}; const unsigned char Diodes[] MEM_TEXT = {'*',LCD_CHAR_DIODE1, ' ', ' ',0}; const unsigned char Resistor_str[] MEM_TEXT = {'-', LCD_CHAR_RESIS1, LCD_CHAR_RESIS2,'-',0}; #ifdef WITH_SELFTEST const unsigned char URefT[] MEM2_TEXT = "Ref="; const unsigned char RHfakt[] MEM2_TEXT = "RHf="; const unsigned char RH1L[] MEM_TEXT = "RH-"; const unsigned char RH1H[] MEM_TEXT = "RH+"; const unsigned char RLRL[] MEM_TEXT = "+RL- 12 13 23"; const unsigned char RHRH[] MEM_TEXT = "+RH- 12 13 23"; const unsigned char RHRL[] MEM_TEXT = "RH/RL"; const unsigned char R0_str[] MEM2_TEXT = "R0="; #define LCD_CLEAR #endif #ifdef CHECK_CALL const unsigned char RIHI[] MEM_TEXT = "Ri_Hi="; const unsigned char RILO[] MEM_TEXT = "Ri_Lo="; const unsigned char C0_str[] MEM_TEXT = "C0 "; const unsigned char T50HZ[] MEM_TEXT = " 50Hz"; #endif #ifdef AUTO_CAL const unsigned char MinCap_str[] MEM2_TEXT = " >100nF"; const unsigned char REF_C_str[] MEM2_TEXT = "REF_C="; const unsigned char REF_R_str[] MEM2_TEXT = "REF_R="; #endif #ifdef DebugOut #define LCD_CLEAR #endif const unsigned char DiodeIcon1[] MEM_TEXT = { 0x11, 0x19, 0x1d, 0x1f, 0x1d, 0x19, 0x11, 0x00 }; // Diode-Icon Anode left const unsigned char DiodeIcon2[] MEM_TEXT = { 0x11, 0x13, 0x17, 0x1f, 0x17, 0x13, 0x11, 0x00 }; // Diode-Icon Anode right const unsigned char CapIcon[] MEM_TEXT = { 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x00 }; // Capacitor Icon const unsigned char ResIcon1[] MEM_TEXT = { 0x00, 0x0f, 0x08, 0x18, 0x08, 0x0f, 0x00, 0x00 }; // Resistor Icon1 left const unsigned char ResIcon2[] MEM_TEXT = { 0x00, 0x1e, 0x02, 0x03, 0x02, 0x1e, 0x00, 0x00 }; // Resistor Icon2 right const unsigned char OmegaIcon[] MEM_TEXT = { 0x00, 0x00, 0x0e, 0x11, 0x11, 0x0a, 0x1b, 0x00 }; // Omega Icon const unsigned char MicroIcon[] MEM_TEXT = { 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0e, 0x09, 0x10 }; // Micro Icon const unsigned char PinRLtab[] PROGMEM = { (1<<(TP1*2)), (1<<(TP2*2)), (1<<(TP3*2))}; // Table of commands to switch the R-L resistors Pin 0,1,2 const unsigned char PinADCtab[] PROGMEM = { (1<<TP1), (1<<TP2), (1<<TP3)}; // Table of commands to switch the ADC-Pins 0,1,2 /* // generate Omega- and u-character as Custom-character, if these characters has a number of loadable type #if LCD_CHAR_OMEGA < 8 const unsigned char CyrillicOmegaIcon[] MEM_TEXT = {0,0,14,17,17,10,27,0}; // Omega #endif #if LCD_CHAR_U < 8 const unsigned char CyrillicMuIcon[] MEM_TEXT = {0,17,17,17,19,29,16,16}; // micro #endif */ #ifdef AUTO_CAL //const uint16_t R680pl EEMEM = R_L_VAL+PIN_RP; // total resistor to VCC //const uint16_t R680mi EEMEM = R_L_VAL+PIN_RM; // total resistor to GND const int8_t RefDiff EEMEM = REF_R_KORR; // correction of internal Reference Voltage #endif const uint8_t PrefixTab[] MEM_TEXT = { 'p','n',LCD_CHAR_U,'m',0,'k','M'}; // p,n,u,m,-,k,M #ifdef AUTO_CAL //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 // LoPin:HiPin 2:1 3:1 1:2 : 3:2 1:3 2:3 const uint8_t c_zero_tab[] EEMEM = { C_NULL,C_NULL,C_NULL+TP2_CAP_OFFSET,C_NULL,C_NULL+TP2_CAP_OFFSET,C_NULL,C_NULL }; // table of zero offsets #endif const uint8_t EE_ESR_ZEROtab[] PROGMEM = {ESR_ZERO, ESR_ZERO, ESR_ZERO, ESR_ZERO}; // zero offset of ESR measurement // End of EEPROM-Strings // Multiplier for capacity measurement with R_H (470KOhm) unsigned int RHmultip = DEFAULT_RH_FAKT; #else // no MAIN_C #define COMMON extern #ifdef WITH_SELFTEST extern const unsigned char SELFTEST[] MEM_TEXT; extern const unsigned char RELPROBE[] MEM_TEXT; extern const unsigned char ATE[] MEM_TEXT; #endif #ifdef AUTO_CAL //extern uint16_t R680pl; //extern uint16_t R680mi; extern int8_t RefDiff; extern uint16_t ref_offset; extern uint8_t c_zero_tab[]; #endif extern const uint8_t EE_ESR_ZEROtab[] EEMEM; // zero offset of ESR measurement extern const uint16_t RLtab[]; #if FLASHEND > 0x1fff extern uint16_t LogTab[]; extern const unsigned char ESR_str[]; #endif #ifdef AUTO_RH extern const uint16_t RHtab[]; #endif extern const unsigned char PinRLtab[]; extern const unsigned char PinADCtab[]; extern unsigned int RHmultip; #endif // MAIN_C struct Diode_t { uint8_t Anode; uint8_t Cathode; unsigned int Voltage; }; COMMON struct Diode_t diodes[6]; COMMON uint8_t NumOfDiodes; COMMON struct { unsigned long hfe[2]; // current amplification factor unsigned int uBE[2]; // B-E-voltage of the Transistor uint8_t b,c,e; // pins of the Transistor }trans; COMMON unsigned int gthvoltage; // Gate-threshold voltage COMMON uint8_t PartReady; // part detection is finished COMMON uint8_t PartMode; COMMON uint8_t tmpval, tmpval2; COMMON unsigned int ref_mv; // Reference-voltage in mV units COMMON struct resis_t{ unsigned long rx; // value of resistor RX #if FLASHEND > 0x1fff unsigned long lx; // inductance 10uH or 100uH int8_t lpre; // prefix for inductance #endif uint8_t ra,rb; // Pins of RX uint8_t rt; // Tristate-Pin (inactive) } resis[3]; COMMON uint8_t ResistorsFound; // Number of found resistors COMMON uint8_t ii; // multipurpose counter COMMON struct cap_t { 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=u, -3=m int8_t cpre_max; // Prefix of the biggest capacitor } cap; #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; // the found part COMMON char outval[12]; // String for ASCII-outpu 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 #endif #if POWER_OFF+0 > 1 COMMON unsigned int display_time; // display time of measurement in ms units #endif /* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */ // definitions of parts #define PART_NONE 0 #define PART_DIODE 1 #define PART_TRANSISTOR 2 #define PART_FET 3 #define PART_TRIAC 4 #define PART_THYRISTOR 5 #define PART_RESISTOR 6 #define PART_CAPACITOR 7 #define PART_CELL 8 // special definition for different parts // FETs #define PART_MODE_N_E_MOS 2 #define PART_MODE_P_E_MOS 3 #define PART_MODE_N_D_MOS 4 #define PART_MODE_P_D_MOS 5 #define PART_MODE_N_JFET 6 #define PART_MODE_P_JFET 7 // Bipolar #define PART_MODE_NPN 1 #define PART_MODE_PNP 2 /* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */ // wait functions #define wait5s() delay(5000) #define wait4s() delay(4000) #define wait3s() delay(3000) #define wait2s() delay(2000) #define wait1s() delay(1000) #define wait500ms() delay(500) #define wait400ms() delay(400) #define wait300ms() delay(300) #define wait200ms() delay(200) #define wait100ms() delay(100) #define wait50ms() delay(50) #define wait40ms() delay(40) #define wait30ms() delay(30) #define wait20ms() delay(20) #define wait10ms() delay(10) #define wait5ms() delay(5) #define wait4ms() delay(4) #define wait3ms() delay(3) #define wait2ms() delay(2) #define wait1ms() delay(1) #define wait500us() delayMicroseconds(500) #define wait400us() delayMicroseconds(400) #define wait300us() delayMicroseconds(300) #define wait200us() delayMicroseconds(200) #define wait100us() delayMicroseconds(100) #define wait50us() delayMicroseconds(50) #define wait40us() delayMicroseconds(40) #define wait30us() delayMicroseconds(30) #define wait20us() delayMicroseconds(20) #define wait10us() delayMicroseconds(10) #define wait5us() delayMicroseconds(5) #define wait4us() delayMicroseconds(4) #define wait3us() delayMicroseconds(3) #define wait2us() delayMicroseconds(2) #define wait1us() delayMicroseconds(1) /* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */ // Interfacing of a HD44780 compatible LCD with 4-Bit-Interface mode // LCD-commands #define CMD_ClearDisplay 0x01 #define CMD_ReturnHome 0x02 #define CMD_SetEntryMode 0x04 #define CMD_SetDisplayAndCursor 0x08 #define CMD_SetIFOptions 0x20 #define CMD_SetCGRAMAddress 0x40 // for Custom character #define CMD_SetDDRAMAddress 0x80 // set Cursor #define CMD1_SetBias 0x10 // set Bias (instruction table 1, DOGM) #define CMD1_PowerControl 0x50 // Power Control, set Contrast C5:C4 (instruction table 1, DOGM) #define CMD1_FollowerControl 0x60 // Follower Control, amplified ratio (instruction table 1, DOGM) #define CMD1_SetContrast 0x70 // set Contrast C3:C0 (instruction table 1, DOGM) // Makros for LCD #define lcd_line1() lcd_set_cursor(0,0) // move to beginning of 1 row #define lcd_line2() lcd_set_cursor(1,0) // move to beginning of 2 row #define lcd_line3() lcd_set_cursor(2,0) // move to beginning of 3 row #define lcd_line4() lcd_set_cursor(3,0) // move to beginning of 4 row #define lcd_init() lcd.begin(20,4) #define lcd_command(value) lcd.command(value) #define lcd_home() lcd.home() #define uart_newline() Serial.println() /* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */ #ifndef INHIBIT_SLEEP_MODE // prepare sleep mode EMPTY_INTERRUPT(TIMER2_COMPA_vect); EMPTY_INTERRUPT(ADC_vect); #endif uint8_t tmp = 0; //unsigned int PRR; byte TestKey; byte TestKeyPin = 17; // A3 // begin of transistortester program void setup() { Serial.begin(9600); pinMode(TestKeyPin, INPUT); lcd.init(); //lcd.begin(16,2); lcd.backlight(); //lcd_init(); // initialize LCD lcd_pgm_custom_char(LCD_CHAR_DIODE1, DiodeIcon1); // Custom-Character Diode symbol >| lcd_pgm_custom_char(LCD_CHAR_DIODE2, DiodeIcon2); // Custom-Character Diode symbol |< lcd_pgm_custom_char(LCD_CHAR_CAP, CapIcon); // Custom-Character Capacitor symbol || lcd_pgm_custom_char(LCD_CHAR_RESIS1, ResIcon1); // Custom-Character Resistor symbol [ lcd_pgm_custom_char(LCD_CHAR_RESIS2, ResIcon2); // Custom-Character Resistor symbol ] lcd_pgm_custom_char(LCD_CHAR_OMEGA, OmegaIcon); // load Omega as Custom-Character lcd_pgm_custom_char(LCD_CHAR_U, MicroIcon); // load Micro as Custom-Character lcd_home(); lcd_string("Componant Tester"); lcd_set_cursor(1, 0); lcd_string("Press Enter..."); //ON_DDR = 0; //ON_PORT = 0; /* // switch on ON_DDR = (1<<ON_PIN); // switch to output #ifdef PULLUP_DISABLE ON_PORT = (1<<ON_PIN); // switch power on #else ON_PORT = (1<<ON_PIN)|(1<<RST_PIN); // switch power on , enable internal Pullup for Start-Pin #endif */ // 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 #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 PRR = (1<<PRTWI) | (1<<PRTIM0) | (1<<PRSPI) | (1<<PRUSART0); DIDR0 = (1<<ADC5D) | (1<<ADC4D) | (1<<ADC3D); TCCR2A = (0<<WGM21) | (0<<WGM20); // Counter 2 normal mode #if F_CPU <= 1000000UL TCCR2B = (1<<CS22) | (0<<CS21) | (1<<CS20); // prescaler 128, 128us @ 1MHz #define T2_PERIOD 128 #endif #if F_CPU == 2000000UL TCCR2B = (1<<CS22) | (1<<CS21) | (0<<CS20); // prescaler 256, 128us @ 2MHz #define T2_PERIOD 128 #endif #if F_CPU == 4000000UL TCCR2B = (1<<CS22) | (1<<CS21) | (0<<CS20); // prescaler 256, 64us @ 2MHz #define T2_PERIOD 64 #endif #if F_CPU >= 8000000UL TCCR2B = (1<<CS22) | (1<<CS21) | (1<<CS20); // prescaler 1024, 128us @ 8MHz, 64us @ 16MHz #define T2_PERIOD (1024 / (F_CPU / 1000000UL)); // set to 128 or 64 us #endif sei(); // enable interrupts #endif */ #define T2_PERIOD (1024 / (F_CPU / 1000000UL)); // set to 128 or 64 us //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_fix_string(TestTimedOut); // Output Timeout wait_about3s(); // wait for 3 s //ON_PORT = 0; // shut off! //ON_DDR = (1<<ON_PIN); // switch to GND //return; } #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 //DIDR0 = 0x3f; // disable all Input register of ADC /* #if POWER_OFF+0 > 1 // tester display time selection display_time = OFF_WAIT_TIME; // LONG_WAIT_TIME for single mode, else SHORT_WAIT_TIME if (!(ON_PIN_REG & (1<<RST_PIN))) { // if power button is pressed ... wait_about300ms(); // wait to catch a long key press if (!(ON_PIN_REG & (1<<RST_PIN))) { // check if power button is still pressed display_time = LONG_WAIT_TIME; // ... set long time display anyway } } #else #define display_time OFF_WAIT_TIME #endif */ #define display_time OFF_WAIT_TIME empty_count = 0; mess_count = 0; } void loop() { // Entry: if start key is pressed before shut down start: TestKey = 1; while(TestKey) { TestKey = digitalRead(TestKeyPin); delay(100); } while(!TestKey) { TestKey = digitalRead(TestKeyPin); delay(100); } lcd_clear(); delay(100); PartFound = PART_NONE; // no part found NumOfDiodes = 0; // Number of diodes = 0 PartReady = 0; PartMode = 0; WithReference = 0; // no precision reference voltage ADC_DDR = TXD_MSK; // activate Software-UART ResistorsFound = 0; // no resistors found cap.ca = 0; cap.cb = 0; #ifdef WITH_UART uart_newline(); // start of new measurement #endif ADCconfig.RefFlag = 0; Calibrate_UR(); // get Ref Voltages and Pin resistance lcd_line1(); // 1 row ADCconfig.U_Bandgap = ADC_internal_reference; // set internal reference voltage for ADC #ifdef BAT_CHECK // Battery check is selected ReadADC(TPBAT); // Dummy-Readout trans.uBE[0] = W5msReadADC(TPBAT); // with 5V reference lcd_fix_string(Bat_str); // output: "Bat. " #ifdef BAT_OUT // display Battery voltage // The divisor to get the voltage in 0.01V units is ((10*33)/133) witch is about 2.4812 // A good result can be get with multiply by 4 and divide by 10 (about 0.75%). //cap.cval = (trans.uBE[0]*4)/10+((BAT_OUT+5)/10); // usually output only 2 digits //DisplayValue(cap.cval,-2,'V',2); // Display 2 Digits of this 10mV units cap.cval = (trans.uBE[0]*4)+BAT_OUT; // usually output only 2 digits DisplayValue(cap.cval,-3,'V',2); // Display 2 Digits of this 10mV units lcd_space(); #endif #if (BAT_POOR > 12000) #warning "Battery POOR level is set very high!" #endif #if (BAT_POOR < 2500) #warning "Battery POOR level is set very low!" #endif #if (BAT_POOR > 5300) // use .8 V difference to Warn-Level #define WARN_LEVEL (((unsigned long)(BAT_POOR+800)*(unsigned long)33)/133) #elif (BAT_POOR > 3249) // less than 5.4 V only .4V difference to Warn-Level #define WARN_LEVEL (((unsigned long)(BAT_POOR+400)*(unsigned long)33)/133) #elif (BAT_POOR > 1299) // less than 2.9 V only .2V difference to Warn-Level #define WARN_LEVEL (((unsigned long)(BAT_POOR+200)*(unsigned long)33)/133) #else // less than 1.3 V only .1V difference to Warn-Level #define WARN_LEVEL (((unsigned long)(BAT_POOR+100)*(unsigned long)33)/133) #endif #define POOR_LEVEL (((unsigned long)(BAT_POOR)*(unsigned long)33)/133) // check the battery voltage if (trans.uBE[0] < WARN_LEVEL) { // Vcc < 7,3V; show Warning if(trans.uBE[0] < POOR_LEVEL) { // Vcc <6,3V; no proper operation is possible lcd_fix_string(BatEmpty); // Battery empty! wait_about2s(); PORTD = 0; // switch power off return; } lcd_fix_string(BatWeak); // Battery weak } else { // Battery-voltage OK lcd_fix_string(OK_str); // "OK" } #else lcd_fix2_string(VERSION_str); // if no Battery check, Version .. in row 1 #endif #ifdef WDT_enabled //wdt_enable(WDTO_2S); // Watchdog on #endif //wait_about1s(); // add more time for reading batterie voltage // begin tests #ifdef AUTO_RH RefVoltage(); // compute RHmultip = f(reference voltage) #endif #if FLASHEND > 0x1fff if (WithReference) { // 2.5V precision reference is checked OK if ((mess_count == 0) && (empty_count == 0)) { // display VCC= only first time lcd_line2(); lcd_fix_string(VCC_str); // VCC= DisplayValue(ADCconfig.U_AVCC,-3,'V',3); // Display 3 Digits of this mV units //lcd_space(); //DisplayValue(RRpinMI,-1,LCD_CHAR_OMEGA,4); wait_about1s(); } } #endif #ifdef WITH_VEXT // show the external voltage while (!(ON_PIN_REG & (1<<RST_PIN))) { lcd_line2(); lcd_clear_line(); lcd_line2(); lcd_fix_string(Vext_str); // Vext= ADC_DDR = 0; // deactivate Software-UART trans.uBE[1] = W5msReadADC(TPext); // read external voltage ADC_DDR = TXD_MSK; // activate Software-UART #ifdef WITH_UART uart_newline(); // start of new measurement #endif DisplayValue(trans.uBE[1]*10,-3,'V',3); // Display 3 Digits of this mV units wait_about300ms(); } #endif lcd_line2(); // LCD position row 2, column 1 lcd_fix_string(TestRunning); // String: testing... #ifndef DebugOut lcd_line2(); // LCD position row 2, column 1 #endif EntladePins(); // discharge all capacitors! if(PartFound == PART_CELL) { lcd_clear(); lcd_fix_string(Cell_str); // display "Cell!" goto end2; } #ifdef CHECK_CALL AutoCheck(); // check, if selftest should be done #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); // separate check if is is a capacitor if(((PartFound == PART_NONE) || (PartFound == PART_RESISTOR) || (PartFound == PART_DIODE)) ) { EntladePins(); // discharge capacities // measurement of capacities in all 3 combinations cap.cval_max = 0; // set max to zero cap.cpre_max = -12; // set max to pF unit ReadCapacity(TP3, TP1); ReadCapacity(TP3, TP2); ReadCapacity(TP2, TP1); #if FLASHEND > 0x1fff ReadInductance(); // measure inductance #endif } // All checks are done, output result to display lcd_clear(); if(PartFound == PART_DIODE) { if(NumOfDiodes == 1) { // single Diode //lcd_fix_string(Diode); // "Diode: " #if FLASHEND > 0x1fff // enough memory to sort the pins #if EBC_STYLE == 321 // the higher test pin number is left side if (diodes[0].Anode > diodes[0].Cathode) { lcd_testpin(diodes[0].Anode); lcd_fix_string(AnKat); // "->|-" lcd_testpin(diodes[0].Cathode); } else { lcd_testpin(diodes[0].Cathode); lcd_fix_string(KatAn); // "-|<-" lcd_testpin(diodes[0].Anode); } #else // the higher test pin number is right side if (diodes[0].Anode < diodes[0].Cathode) { lcd_testpin(diodes[0].Anode); lcd_fix_string(AnKat); // "->|-" lcd_testpin(diodes[0].Cathode); } else { lcd_testpin(diodes[0].Cathode); lcd_fix_string(KatAn); // "-|<-" lcd_testpin(diodes[0].Anode); } #endif #else // too less memory to sort the pins lcd_testpin(diodes[0].Anode); lcd_fix_string(AnKat); // "->|-" lcd_testpin(diodes[0].Cathode); #endif #if FLASHEND > 0x1fff GetIr(diodes[0].Cathode,diodes[0].Anode); #endif UfOutput(0x70); // load current of capacity is (5V-1.1V)/(470000 Ohm) = 8298nA lcd_fix_string(GateCap_str); // "C=" ReadCapacity(diodes[0].Cathode,diodes[0].Anode); // Capacity opposite flow direction DisplayValue(cap.cval,cap.cpre,'F',3); goto end; } else if(NumOfDiodes == 2) { // double diode lcd_data('2'); lcd_fix_string(Diodes); // "diodes " if(diodes[0].Anode == diodes[1].Anode) { //Common Anode lcd_testpin(diodes[0].Cathode); lcd_fix_string(KatAn); // "-|<-" lcd_testpin(diodes[0].Anode); lcd_fix_string(AnKat); // "->|-" lcd_testpin(diodes[1].Cathode); UfOutput(0x01); goto end; } else if(diodes[0].Cathode == diodes[1].Cathode) { //Common Cathode lcd_testpin(diodes[0].Anode); lcd_fix_string(AnKat); // "->|-" lcd_testpin(diodes[0].Cathode); lcd_fix_string(KatAn); // "-|<-" lcd_testpin(diodes[1].Anode); UfOutput(0x01); goto end; } else if ((diodes[0].Cathode == diodes[1].Anode) && (diodes[1].Cathode == diodes[0].Anode)) { // Antiparallel lcd_testpin(diodes[0].Anode); lcd_fix_string(AnKat); // "->|-" lcd_testpin(diodes[0].Cathode); lcd_fix_string(AnKat); // "->|-" lcd_testpin(diodes[1].Cathode); UfOutput(0x01); goto end; } } else if(NumOfDiodes == 3) { // Serial of 2 Diodes; was detected as 3 Diodes trans.b = 3; trans.c = 3; // Check for any constallation 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[0].Cathode == diodes[1].Anode) { trans.b = 0; trans.c = 1; } if(diodes[0].Anode == diodes[1].Cathode) { trans.b = 1; trans.c = 0; } if(diodes[0].Cathode == diodes[2].Anode) { trans.b = 0; trans.c = 2; } if(diodes[0].Anode == diodes[2].Cathode) { trans.b = 2; trans.c = 0; } if(diodes[1].Cathode == diodes[2].Anode) { trans.b = 1; trans.c = 2; } if(diodes[1].Anode == diodes[2].Cathode) { trans.b = 2; trans.c = 1; } #if DebugOut == 4 lcd_line3(); lcd_testpin(diodes[0].Anode); lcd_data(':'); lcd_testpin(diodes[0].Cathode); lcd_space(); lcd_string(utoa(diodes[0].Voltage, outval, 10)); lcd_space(); lcd_testpin(diodes[1].Anode); lcd_data(':'); lcd_testpin(diodes[1].Cathode); lcd_space(); lcd_string(utoa(diodes[1].Voltage, outval, 10)); lcd_line4(); lcd_testpin(diodes[2].Anode); lcd_data(':'); lcd_testpin(diodes[2].Cathode); lcd_space(); lcd_string(utoa(diodes[2].Voltage, outval, 10)); lcd_line1(); #endif if((trans.b < 3) && (trans.c < 3)) { lcd_data('3'); lcd_fix_string(Diodes); // "Diodes " lcd_testpin(diodes[trans.b].Anode); lcd_fix_string(AnKat); // "->|-" lcd_testpin(diodes[trans.b].Cathode); lcd_fix_string(AnKat); // "->|-" lcd_testpin(diodes[trans.c].Cathode); UfOutput( (trans.b<<4)|trans.c); goto end; } } // end (PartFound == PART_DIODE) } else if (PartFound == PART_TRANSISTOR) { if(PartReady != 0) { if((trans.hfe[0]>trans.hfe[1])) { // if the amplification factor was higher at first testr: swap C and E ! tmp = trans.c; trans.c = trans.e; trans.e = tmp; } else { trans.hfe[0] = trans.hfe[1]; trans.uBE[0] = trans.uBE[1]; } } if(PartMode == PART_MODE_NPN) { lcd_fix_string(NPN_str); // "NPN " } else { lcd_fix_string(PNP_str); // "PNP " } if( NumOfDiodes > 2) { // Transistor with protection diode #ifdef EBC_STYLE #if EBC_STYLE == 321 // Layout with 321= style if (((PartMode == PART_MODE_NPN) && (trans.c < trans.e)) || ((PartMode != PART_MODE_NPN) && (trans.c > trans.e))) #else // Layout with EBC= style if(PartMode == PART_MODE_NPN) #endif #else // Layout with 123= style if (((PartMode == PART_MODE_NPN) && (trans.c > trans.e)) || ((PartMode != PART_MODE_NPN) && (trans.c < trans.e))) #endif { lcd_fix_string(AnKat); // "->|-" } else { lcd_fix_string(KatAn); // "-|<-" } } PinLayout('E','B','C'); // EBC= or 123=... lcd_line2(); // 2 row lcd_fix_string(hfe_str); // "B=" (hFE) DisplayValue(trans.hfe[0],0,0,3); lcd_space(); lcd_fix_string(Uf_str); // "Uf=" DisplayValue(trans.uBE[0],-3,'V',3); goto end; // end (PartFound == PART_TRANSISTOR) } else if (PartFound == PART_FET) { // JFET or MOSFET if(PartMode&1) { lcd_data('P'); // P-channel } else { lcd_data('N'); // N-channel } lcd_data('-'); tmp = PartMode/2; if (tmp == (PART_MODE_N_D_MOS/2)) { lcd_data('D'); // N-D } if (tmp == (PART_MODE_N_E_MOS/2)) { lcd_data('E'); // N-E } if (tmp == (PART_MODE_N_JFET/2)) { lcd_fix_string(jfet_str); // "JFET" } else { lcd_fix_string(mosfet_str); // "-MOS " } PinLayout('S','G','D'); // SGD= or 123=... if((NumOfDiodes > 0) && (PartMode < PART_MODE_N_D_MOS)) { // MOSFET with protection diode; only with enhancement-FETs #ifdef EBC_STYLE #if EBC_STYLE == 321 // layout with 321= style if (((PartMode&1) && (trans.c > trans.e)) || ((!(PartMode&1)) && (trans.c < trans.e))) #else // Layout with SGD= style if (PartMode&1) // N or P MOS #endif #else // layout with 123= style if (((PartMode&1) && (trans.c < trans.e)) || ((!(PartMode&1)) && (trans.c > trans.e))) #endif { lcd_data(LCD_CHAR_DIODE1); // show Diode symbol >| } else { lcd_data(LCD_CHAR_DIODE2); // show Diode symbol |< } } lcd_line2(); // 2 row if(PartMode < PART_MODE_N_D_MOS) { // enhancement-MOSFET // Gate capacity lcd_fix_string(GateCap_str); // "C=" ReadCapacity(trans.b,trans.e); // measure capacity DisplayValue(cap.cval,cap.cpre,'F',3); lcd_fix_string(vt_str); // "Vt=" } else { lcd_data('I'); lcd_data('='); DisplayValue(trans.uBE[1],-5,'A',2); lcd_fix_string(Vgs_str); // " Vgs=" } // Gate-threshold voltage DisplayValue(gthvoltage,-3,'V',2); goto end; // end (PartFound == PART_FET) } else if (PartFound == PART_THYRISTOR) { lcd_fix_string(Thyristor); // "Thyristor" goto gakOutput; } else if (PartFound == PART_TRIAC) { lcd_fix_string(Triac); // "Triac" goto gakOutput; } else if(PartFound == PART_RESISTOR) { if (ResistorsFound == 1) { // single resistor lcd_testpin(resis[0].rb); // Pin-number 1 lcd_fix_string(Resistor_str); lcd_testpin(resis[0].ra); // Pin-number 2 } else { // R-Max suchen ii = 0; if (resis[1].rx > resis[0].rx) ii = 1; if (ResistorsFound == 2) { ii = 2; } else { if (resis[2].rx > resis[ii].rx) ii = 2; } char x = '1'; char y = '3'; char z = '2'; if (ii == 1) { //x = '1'; y = '2'; z = '3'; } if (ii == 2) { x = '2'; y = '1'; z = '3'; } lcd_data(x); lcd_fix_string(Resistor_str); // "-[=]-" lcd_data(y); lcd_fix_string(Resistor_str); // "-[=]-" lcd_data(z); } lcd_line2(); // 2 row if (ResistorsFound == 1) { RvalOut(0); #if FLASHEND > 0x1fff if (resis[0].lx != 0) { // resistor have also Inductance lcd_fix_string(Lis_str); // "L=" DisplayValue(resis[0].lx,resis[0].lpre,'H',3); // output inductance } #endif } else { // output resistor values in right order if (ii == 0) { RvalOut(1); RvalOut(2); } if (ii == 1) { RvalOut(0); RvalOut(2); } if (ii == 2) { RvalOut(0); RvalOut(1); } } goto end; // end (PartFound == PART_RESISTOR) // capacity measurement is wanted } else if(PartFound == PART_CAPACITOR) { //lcd_fix_string(Capacitor); lcd_testpin(cap.ca); // Pin number 1 lcd_fix_string(CapZeich); // capacitor sign lcd_testpin(cap.cb); // Pin number 2 #if FLASHEND > 0x1fff GetVloss(); // get Voltage loss of capacitor if (cap.v_loss != 0) { lcd_fix_string(VLOSS_str); // " Vloss=" DisplayValue(cap.v_loss,-1,'%',2); } #endif lcd_line2(); // 2 row DisplayValue(cap.cval_max,cap.cpre_max,'F',4); #if FLASHEND > 0x1fff cap.esr = GetESR(cap.cb, cap.ca); // get ESR of capacitor if (cap.esr < 65530) { lcd_fix_string(ESR_str); DisplayValue(cap.esr,-2,LCD_CHAR_OMEGA,2); } #endif goto end; } if(NumOfDiodes == 0) { // no diodes are found lcd_fix_string(TestFailed1); // "No, unknown, or" lcd_line2(); // 2 row lcd_fix_string(TestFailed2); // "damaged " lcd_fix_string(Component); // "part" } else { lcd_fix_string(Component); // "part" lcd_fix_string(Unknown); // " unknown" lcd_line2(); // 2 row lcd_fix_string(OrBroken); // "or damaged " lcd_data(NumOfDiodes + '0'); lcd_fix_string(AnKat); // "->|-" } empty_count++; mess_count = 0; goto end2; gakOutput: lcd_line2(); // 2 row PinLayout(Cathode_char,'G','A'); // CGA= or 123=... //- - - - - - - - - - - - - - - - - - - - - - - - - - - - end: empty_count = 0; // reset counter, if part is found mess_count++; // count measurements end2: //ADC_DDR = (1<<TPREF) | TXD_MSK; // switch pin with reference to GND, release relay ADC_DDR = TXD_MSK; // switch pin with reference to GND, release relay goto start; while(!(ON_PIN_REG & (1<<RST_PIN))); // wait ,until button is released wait_about200ms(); // wait 14 seconds or 5 seconds (if repeat function) for(gthvoltage = 0;gthvoltage<display_time;gthvoltage+=10) { if(!(ON_PIN_REG & (1<<RST_PIN))) { // If the key is pressed again... // goto start of measurement goto start; } wdt_reset(); wait_about10ms(); } #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 start; // repeat measurement POWER_OFF times } #endif // only one Measurement requested, shut off //MCUSR = 0; ON_PORT &= ~(1<<ON_PIN); // switch off power // never ending loop while(1) { if(!(ON_PIN_REG & (1<<RST_PIN))) { // The statement is only reached if no auto off equipment is installed goto start; } wdt_reset(); wait_about10ms(); } #else goto start; // POWER_OFF not selected, repeat measurement #endif return; } // end main //****************************************************************** // output of flux voltage for 1-2 diodes in row 2 // bcdnum = Numbers of both Diodes: // higher 4 Bit number of first Diode // lower 4 Bit number of second Diode (Structure diodes[nn]) // if number >= 3 no output is done void UfOutput(uint8_t bcdnum) { lcd_line2(); // 2 row lcd_fix_string(Uf_str); // "Uf=" mVOutput(bcdnum >> 4); mVOutput(bcdnum & 0x0f); } void mVOutput(uint8_t nn) { if (nn < 3) { // Output in mV units DisplayValue(diodes[nn].Voltage,-3,'V',3); lcd_space(); } } void RvalOut(uint8_t ii) { // output of resistor value #if FLASHEND > 0x1fff uint16_t rr; if ((resis[ii].rx < 100) && (resis[0].lx == 0)) { rr = GetESR(resis[ii].ra,resis[ii].rb); DisplayValue(rr,-2,LCD_CHAR_OMEGA,3); } else { DisplayValue(resis[ii].rx,-1,LCD_CHAR_OMEGA,4); } #else DisplayValue(resis[ii].rx,-1,LCD_CHAR_OMEGA,4); #endif lcd_space(); } //****************************************************************** void ChargePin10ms(uint8_t PinToCharge, uint8_t ChargeDirection) { // Load the specified pin to the specified direction with 680 Ohm for 10ms. // Will be used by discharge of MOSFET Gates or to load big capacities. // Parameters: // PinToCharge: specifies the pin as mask for R-Port // ChargeDirection: 0 = switch to GND (N-Kanal-FET), 1= switch to VCC(P-Kanal-FET) if(ChargeDirection&1) { R_PORT |= PinToCharge; // R_PORT to 1 (VCC) } else { R_PORT &= ~PinToCharge; // or 0 (GND) } R_DDR |= PinToCharge; // switch Pin to output, across R to GND or VCC wait_about10ms(); // wait about 10ms // switch back Input, no current R_DDR &= ~PinToCharge; // switch back to input R_PORT &= ~PinToCharge; // no Pull up } // first discharge any charge of capacitors void EntladePins() { uint8_t adc_gnd; // Mask of ADC-outputs, which can be directly connected to GND unsigned int adcmv[3]; // voltages of 3 Pins in mV unsigned int clr_cnt; // Clear Counter uint8_t lop_cnt; // loop counter // max. time of discharge in ms (10000/20) == 10s #define MAX_ENTLADE_ZEIT (10000/20) for(lop_cnt=0;lop_cnt<10;lop_cnt++) { adc_gnd = TXD_MSK; // put all ADC to Input ADC_DDR = adc_gnd; ADC_PORT = TXD_VAL; // ADC-outputs auf 0 R_PORT = 0; // R-outputs auf 0 R_DDR = (2<<(TP3*2)) | (2<<(TP2*2)) | (2<<(TP1*2)); // R_H for all Pins to GND adcmv[0] = W5msReadADC(TP1); // which voltage has Pin 1? adcmv[1] = ReadADC(TP2); // which voltage has Pin 2? adcmv[2] = ReadADC(TP3); // which voltage has Pin 3? if ((PartFound == PART_CELL) || (adcmv[0] < CAP_EMPTY_LEVEL) & (adcmv[1] < CAP_EMPTY_LEVEL) & (adcmv[2] < CAP_EMPTY_LEVEL)) { ADC_DDR = TXD_MSK; // switch all ADC-Pins to input R_DDR = 0; // switch all R_L Ports (and R_H) to input return; // all is discharged } // all Pins with voltage lower than 1V can be connected directly to GND (ADC-Port) if (adcmv[0] < 1000) { adc_gnd |= (1<<TP1); // Pin 1 directly to GND } if (adcmv[1] < 1000) { adc_gnd |= (1<<TP2); // Pin 2 directly to GND } if (adcmv[2] < 1000) { adc_gnd |= (1<<TP3); // Pin 3 directly to GND } ADC_DDR = adc_gnd; // switch all selected ADC-Ports at the same time // additionally switch the leaving Ports with R_L to GND. // since there is no disadvantage for the already directly switched pins, we can // simply switch all R_L resistors to GND R_DDR = (1<<(TP3*2)) | (1<<(TP2*2)) | (1<<(TP1*2)); // Pins across R_L resistors to GND for(clr_cnt=0;clr_cnt<MAX_ENTLADE_ZEIT;clr_cnt++) { wdt_reset(); adcmv[0] = W20msReadADC(TP1); // which voltage has Pin 1? adcmv[1] = ReadADC(TP2); // which voltage has Pin 2? adcmv[2] = ReadADC(TP3); // which voltage has Pin 3? if (adcmv[0] < 1300) { ADC_DDR |= (1<<TP1); // below 1.3V , switch directly with ADC-Port to GND } if (adcmv[1] < 1300) { ADC_DDR |= (1<<TP2); // below 1.3V, switch directly with ADC-Port to GND } if (adcmv[2] < 1300) { ADC_DDR |= (1<<TP3); // below 1.3V, switch directly with ADC-Port to GND } if ((adcmv[0] < (CAP_EMPTY_LEVEL+2)) && (adcmv[1] < (CAP_EMPTY_LEVEL+2)) && (adcmv[2] < (CAP_EMPTY_LEVEL+2))) { break; } } if (clr_cnt == MAX_ENTLADE_ZEIT) { PartFound = PART_CELL; // mark as Battery // there is charge on capacitor, warn later! } for(adcmv[0]=0;adcmv[0]<clr_cnt;adcmv[0]++) { // for safety, discharge 5% of discharge time wait1ms(); } } // end for lop_cnt } #ifdef AUTO_RH void RefVoltage(void) { // RefVoltage interpolates table RHtab corresponding to voltage ref_mv . // RHtab contain the factors to get capacity from load time with 470k for // different Band gab reference voltages. // for remember: // resistor 470000 Ohm 1000 1050 1100 1150 1200 1250 1300 1350 1400 mV // uint16_t RHTAB[] MEM_TEXT = { 954, 903, 856, 814, 775, 740, 707, 676, 648}; #define Ref_Tab_Abstand 50 // displacement of table is 50mV #define Ref_Tab_Beginn 1000 // begin of table is 1000mV unsigned int referenz; unsigned int y1, y2; uint8_t tabind; uint8_t tabres; #ifdef AUTO_CAL referenz = ref_mv + (int16_t)eeprom_read_word((uint16_t *)(&ref_offset)); #else referenz = ref_mv + REF_C_KORR; #endif if (referenz >= Ref_Tab_Beginn) { referenz -= Ref_Tab_Beginn; } else { referenz = 0; // limit to begin of table } tabind = referenz / Ref_Tab_Abstand; tabres = referenz % Ref_Tab_Abstand; tabres = Ref_Tab_Abstand-tabres; if (tabind > 7) { tabind = 7; // limit to end of table } // interpolate the table of factors y1 = pgm_read_word(&RHtab[tabind]); y2 = pgm_read_word(&RHtab[tabind+1]); // RHmultip is the interpolated factor to compute capacity from load time with 470k RHmultip = ((y1 - y2) * tabres + (Ref_Tab_Abstand/2)) / Ref_Tab_Abstand + y2; } #endif #ifdef LCD_CLEAR void lcd_clear_line(void) { // writes 20 spaces to LCD-Display, Cursor must be positioned to first column unsigned char ll; for (ll=0;ll<20;ll++) { lcd_space(); } } #endif /* ************************************************************************ * display of values and units * ************************************************************************ */ /* * display value and unit * - max. 4 digits excluding "." and unit * * requires: * - value * - exponent of factor related to base unit (value * 10^x) * e.g: p = 10^-12 -> -12 * - unit character (0 = none) * digits = 2, 3 or 4 */ void DisplayValue(unsigned long Value, int8_t Exponent, unsigned char Unit, unsigned char digits) { char OutBuffer[15]; unsigned int Limit; unsigned char Prefix; // prefix character uint8_t Offset; // exponent of offset to next 10^3 step uint8_t Index; // index ID uint8_t Length; // string length Limit = 100; // scale value down to 2 digits if (digits == 3) Limit = 1000; // scale value down to 3 digits if (digits == 4) Limit = 10000; // scale value down to 4 digits while (Value >= Limit) { Value += 5; // for automatic rounding Value = Value / 10; // scale down by 10^1 Exponent++; // increase exponent by 1 } // determine prefix Length = Exponent + 12; if ((int8_t)Length < 0) Length = 0; // Limit to minimum prefix if (Length > 18) Length = 18; // Limit to maximum prefix Index = Length / 3; Offset = Length % 3; if (Offset > 0) { Index++; // adjust index for exponent offset, take next prefix Offset = 3 - Offset; // reverse value (1 or 2) } #ifdef NO_NANO if (Index == 1) { // use no nano Index++; // use mikro instead of nano Offset += 3; // can be 3,4 or 5 } #endif Prefix = MEM_read_byte((uint8_t *)(&PrefixTab[Index])); // look up prefix in table // display value // convert value into string utoa((unsigned int)Value, OutBuffer, 10); Length = strlen(OutBuffer); // position of dot Exponent = Length - Offset; // calculate position if (Exponent <= 0) // we have to prepend "0." { // 0: factor 10 / -1: factor 100 //lcd_data('0'); lcd_data('.'); #ifdef NO_NANO while (Exponent < 0) { lcd_data('0'); // extra 0 for factor 10 Exponent++; } #else if (Exponent < 0) lcd_data('0'); // extra 0 for factor 100 #endif } if (Offset == 0) Exponent = -1; // disable dot if not needed // adjust position to array or disable dot if set to 0 //Exponent--; // display value and add dot if requested Index = 0; while (Index < Length) // loop through string { lcd_data(OutBuffer[Index]); // display char Index++; // next one if (Index == Exponent) { lcd_data('.'); // display dot } } // display prefix and unit if (Prefix != 0) lcd_data(Prefix); if (Unit) lcd_data(Unit); } #ifndef INHIBIT_SLEEP_MODE // set the processor to sleep state // wake up will be done with compare match interrupt of counter 2 void sleep_5ms(uint16_t pause){ // pause is the delay in 5ms units uint8_t t2_offset; #define RESTART_DELAY_US (RESTART_DELAY_TICS/(F_CPU/1000000UL)) // for 8 MHz crystal the Restart delay is 16384/8 = 2048us while (pause > 0) { #if 3000 > RESTART_DELAY_US if (pause > 1) { // Startup time is too long with 1MHz Clock!!!! t2_offset = (10000 - RESTART_DELAY_US) / T2_PERIOD; // set to 10ms above the actual counter pause -= 2; } else { t2_offset = (5000 - RESTART_DELAY_US) / T2_PERIOD; // set to 5ms above the actual counter pause = 0; } OCR2A = TCNT2 + t2_offset; // set the compare value TIMSK2 = (0<<OCIE2B) | (1<<OCIE2A) | (0<<TOIE2); // enable output compare match A interrupt set_sleep_mode(SLEEP_MODE_PWR_SAVE); //set_sleep_mode(SLEEP_MODE_IDLE); sleep_mode(); // wake up after output compare match interrupt #else // restart delay ist too long, use normal delay of 5ms wait5ms(); #endif wdt_reset(); } TIMSK2 = (0<<OCIE2B) | (0<<OCIE2A) | (0<<TOIE2); // disable output compare match A interrupt } #endif // show the Pin Layout of the device void PinLayout(char pin1, char pin2, char pin3) { // pin1-3 is EBC or SGD or CGA #ifndef EBC_STYLE // Layout with 123= style lcd_fix_string(N123_str); // " 123=" for (ii=0;ii<3;ii++) { if (ii == trans.e) lcd_data(pin1); // Output Character in right order if (ii == trans.b) lcd_data(pin2); if (ii == trans.c) lcd_data(pin3); } #else #if EBC_STYLE == 321 // Layout with 321= style lcd_fix_string(N321_str); // " 321=" ii = 3; while (ii != 0) { ii--; if (ii == trans.e) lcd_data(pin1); // Output Character in right order if (ii == trans.b) lcd_data(pin2); if (ii == trans.c) lcd_data(pin3); } #else // Layout with EBC= style lcd_space(); lcd_data(pin1); lcd_data(pin2); lcd_data(pin3); lcd_data('='); lcd_testpin(trans.e); lcd_testpin(trans.b); lcd_testpin(trans.c); #endif #endif } /* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */ void AutoCheck(void) { #ifdef WITH_SELFTEST uint8_t tt; // number of running test uint8_t ww; // counter for repeating the tests int adcmv[7]; uint16_t u680; // 3 * (Voltage at 680 Ohm) // 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 ADC_PORT = TXD_VAL; ADC_DDR = TXD_MSK; #define RequireShortedProbes if (AllProbesShorted() != 3) return; lcd_clear(); lcd_fix_string(SELFTEST); // "Selftest mode.." lcd_line2(); lcd_fix2_string(R0_str); // "R0=" eeprom_write_byte((uint8_t *)(&EE_ESR_ZEROtab[2]), (int8_t)0); // clear zero offset eeprom_write_byte((uint8_t *)(&EE_ESR_ZEROtab[3]), (int8_t)0); // clear zero offset eeprom_write_byte((uint8_t *)(&EE_ESR_ZEROtab[1]), (int8_t)0); // clear zero offset adcmv[0] = GetESR(TP3, TP1); adcmv[1] = GetESR(TP3, TP2); adcmv[2] = GetESR(TP2, TP1); DisplayValue(adcmv[0],-2,' ',3); DisplayValue(adcmv[1],-2,' ',3); DisplayValue(adcmv[2],-2,LCD_CHAR_OMEGA,3); if (adcmv[0] < 60) { eeprom_write_byte((uint8_t *)(&EE_ESR_ZEROtab[2]), (int8_t)adcmv[0]); // fix zero offset } if (adcmv[1] < 60) { eeprom_write_byte((uint8_t *)(&EE_ESR_ZEROtab[3]), (int8_t)adcmv[1]); // fix zero offset } if (adcmv[2] < 60) { eeprom_write_byte((uint8_t *)(&EE_ESR_ZEROtab[1]), (int8_t)adcmv[2]); // fix zero offset } for(tt=0; tt<12; tt++) { wait_about500ms(); if(!(ON_PIN_REG & (1<<RST_PIN))) { // if key is pressed, don't repeat break; } } // end for tt #define TEST_COUNT 8 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_line2(); // Cursor to column 1, row 2 lcd_clear_line(); // clear total line lcd_line1(); // Cursor to column 1, row 1 lcd_clear_line(); // clear total line lcd_line1(); // Cursor to column 1, row 1 lcd_data('T'); // output the Testmode "T" lcd_string(utoa(tt, outval, 10)); // output Test number lcd_space(); if (tt == 1) { // output of reference voltage and factors for capacity measurement Calibrate_UR(); // get Reference voltage, Pin resistance lcd_fix2_string(URefT); // "URef=" DisplayValue(ref_mv,-3,'V',4); lcd_line2(); // Cursor to column 1, row 2 lcd_fix2_string(RHfakt); // "RHf=" lcd_string(utoa(RHmultip, outval, 10)); ADCconfig.Samples = 190; // 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<<(TP1*2); // RL1 to VCC R_DDR = (1<<(TP1*2)) | (1<<(TP2*2)); // RL2 to - adcmv[0] = W20msReadADC(TP1); adcmv[0] -= u680; R_DDR = (1<<(TP1*2)) | (1<<(TP3*2)); // RL3 to - adcmv[1] = W20msReadADC(TP1); adcmv[1] -= u680; R_PORT = 1<<(TP2*2); // RL2 to VCC R_DDR = (1<<(TP2*2)) | (1<<(TP3*2)); // RL3 to - adcmv[2] = W20msReadADC(TP2); adcmv[2] -= u680; lcd_fix_string(RLRL); // "RLRL" } if (tt == 3) { // how equal are the RH resistors R_PORT = 2<<(TP1*2); // RH1 to VCC R_DDR = (2<<(TP1*2)) | (2<<(TP2*2)); // RH2 to - adcmv[0] = W20msReadADC(TP1); adcmv[3] = ADCconfig.U_AVCC / 2; adcmv[0] -= adcmv[3]; R_DDR = (2<<(TP1*2)) | (2<<(TP3*2)); // RH3 to - adcmv[1] = W20msReadADC(TP1); adcmv[1] -= adcmv[3]; R_PORT = 2<<(TP2*2); // RH2 to VCC R_DDR = (2<<(TP2*2)) | (2<<(TP3*2)); // RH3 to - adcmv[2] = W20msReadADC(TP2); adcmv[2] -= adcmv[3]; lcd_fix_string(RHRH); // "RHRH" } if (tt == 4) { // Text release probes lcd_fix_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 = 2<<(TP1*2); // Pin 1 over R_H to GND adcmv[0] = W20msReadADC(TP1); R_DDR = 2<<(TP2*2); // Pin 2 over R_H to GND adcmv[1] = W20msReadADC(TP2); R_DDR = 2<<(TP3*2); // Pin 3 over R_H to GND adcmv[2] = W20msReadADC(TP3); lcd_fix_string(RH1L); // "RH_Lo=" } if (tt == 6) { // can we switch the ADC pins to VCC across the R_H resistor? R_DDR = 2<<(TP1*2); // Pin 1 over R_H to VCC R_PORT = 2<<(TP1*2); adcmv[0] = W20msReadADC(TP1) - ADCconfig.U_AVCC; R_DDR = 2<<(TP2*2); // Pin 2 over R_H to VCC R_PORT = 2<<(TP2*2); adcmv[1] = W20msReadADC(TP2) - ADCconfig.U_AVCC; R_DDR = 2<<(TP3*2); // Pin 3 over R_H to VCC R_PORT = 2<<(TP3*2); adcmv[2] = W20msReadADC(TP3) - ADCconfig.U_AVCC; lcd_fix_string(RH1H); // "RH_Hi=" } if (tt == 7) { // can we switch the ADC pins to VCC across the R_H resistor? u680 = ((long)ADCconfig.U_AVCC * (PIN_RM + R_L_VAL) / (PIN_RM + R_L_VAL + R_H_VAL*100)); R_PORT = 2<<(TP1*2); // RH1 to VCC R_DDR = (2<<(TP1*2)) | (1<<(TP1*2)); // RH1 to +, RL1 to - adcmv[0] = W20msReadADC(TP1); adcmv[0] -= u680; R_PORT = 2<<(TP2*2); // RH2 to VCC R_DDR = (2<<(TP2*2)) | (1<<(TP2*2)); // RH2 to +, RL2 to - adcmv[1] = W20msReadADC(TP2); adcmv[1] -= u680; R_PORT = 2<<(TP3*2); // RH3 to VCC R_DDR = (2<<(TP3*2)) | (1<<(TP3*2)); // RH3 to +, RL3 to - adcmv[2] = W20msReadADC(TP3); adcmv[2] -= u680; lcd_fix_string(RHRL); // "RH/RL" } if (tt > 1) { // output 3 voltages lcd_line2(); // Cursor to column 1, row 2 lcd_string(itoa(adcmv[0], outval, 10)); // output voltage 1 lcd_space(); lcd_string(itoa(adcmv[1], outval, 10)); // output voltage 2 lcd_space(); 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; if(!(ON_PIN_REG & (1<<RST_PIN))) { // if key is pressed, don't repeat break; } wait_about500ms(); if(!(ON_PIN_REG & (1<<RST_PIN))) { // if key is pressed, don't repeat break; } wait_about500ms(); } // end for ww wait_about1s(); } // end for tt lcd_clear(); lcd_fix_string(RIHI); // "RiHi=" DisplayValue(RRpinPL,-1,LCD_CHAR_OMEGA,3); lcd_line2(); lcd_fix_string(RILO); // "RiLo=" DisplayValue(RRpinMI,-1,LCD_CHAR_OMEGA,3); wait_about2s(); //measure Zero offset for Capacity measurement adcmv[3] = 0; PartFound = PART_NONE; ReadCapacity(TP3, TP1); adcmv[5] = (unsigned int) cap.cval_uncorrected.dw; // save capacity value of empty Pin 1:3 ReadCapacity(TP3, TP2); adcmv[6] = (unsigned int) cap.cval_uncorrected.dw; // save capacity value of empty Pin 2:3 ReadCapacity(TP2, TP1); adcmv[2] = (unsigned int) cap.cval_uncorrected.dw; // save capacity value of empty Pin 1:2 ReadCapacity(TP1, TP3); adcmv[1] = (unsigned int) cap.cval_uncorrected.dw; // save capacity value of empty Pin 3:1 ReadCapacity(TP2, TP3); adcmv[4] = (unsigned int) cap.cval_uncorrected.dw; // save capacity value of empty Pin 3:2 ReadCapacity(TP1, TP2); adcmv[0] = (unsigned int) cap.cval_uncorrected.dw; // save capacity value of empty Pin 2:1 lcd_clear(); lcd_fix_string(C0_str); // output "C0 " DisplayValue(adcmv[5],0,' ',3); // output cap0 1:3 DisplayValue(adcmv[6],0,' ',3); // output cap0 2:3 DisplayValue(adcmv[2],-12,'F',3); // output cap0 1:2 #ifdef AUTO_CAL for (ww=0;ww<7;ww++) { if (adcmv[ww] > 70) goto no_c0save; } for (ww=0;ww<7;ww++) { // write all zero offsets to the EEprom (void) eeprom_write_byte((uint8_t *)(&c_zero_tab[ww]),adcmv[ww]+(COMP_SLEW1 / (CC0 + CABLE_CAP + COMP_SLEW2))); } lcd_line2(); lcd_fix_string(OK_str); // output "OK" no_c0save: #endif wait_about2s(); #ifdef AUTO_CAL // Message C > 100nF cap_found = 0; for (ww=0; ww<64; ww++) { lcd_clear(); lcd_data('1'); lcd_fix_string(CapZeich); // "-||-" lcd_data('3'); lcd_fix2_string(MinCap_str); // " >100nF!" PartFound = PART_NONE; // measure offset Voltage of analog Comparator for Capacity measurement ReadCapacity(TP3, TP1); // look for capacitor > 100nF while (cap.cpre < -9) { cap.cpre++; cap.cval /= 10; } if ((cap.cpre == -9) && (cap.cval > 95) && (cap.cval < 22000)) { cap_found++; } else { cap_found = 0; // wait for stable connection } if (cap_found > 1) { // value of capacitor is correct (void) eeprom_write_word((uint16_t *)(&ref_offset), load_diff); // hold zero offset + slew rate dependend offset lcd_clear(); lcd_fix2_string(REF_C_str); // "REF_C=" lcd_string(itoa(load_diff, outval, 10)); // output REF_C_KORR #if 0 // Test for switching level of the digital input of port TP3 for (ii=0;ii<8;ii++) { ADC_PORT = TXD_VAL; // ADC-Port 1 to GND ADC_DDR = 1<<TP1 | TXD_MSK; // ADC-Pin 1 to output 0V R_PORT = 2<<(TP3*2); // Pin 3 over R_H to VCC R_DDR = 2<<(TP3*2); // Pin 3 over R_H to VCC while (1) { wdt_reset(); if ((ADC_PIN&(1<<TP3)) == (1<<TP3)) break; } R_DDR = 0; // Pin 3 without current R_PORT = 0; adcmv[0] = ReadADC(TP3); lcd_line3(); DisplayValue(adcmv[0],-3,'V',4); R_DDR = 2<<(TP3*2); // Pin 3 over R_H to GND while (1) { wdt_reset(); if ((ADC_PIN&(1<<TP3)) != (1<<TP3)) break; } R_DDR = 0; // Pin 3 without current lcd_line4(); adcmv[0] = ReadADC(TP3); DisplayValue(adcmv[0],-3,'V',4); wait_about1s(); } #endif #ifdef AUTOSCALE_ADC ADC_PORT = TXD_VAL; // ADC-Port 1 to GND ADC_DDR = 1<<TP1 | TXD_MSK; // ADC-Pin 1 to output 0V R_DDR = 2<<(TP3*2); // Pin 3 over R_H to GND do { adcmv[0] = ReadADC(TP3); } while (adcmv[0] > 980); R_DDR = 0; // all Pins to input ADCconfig.U_Bandgap = 0; // do not use internal Ref adcmv[0] = ReadADC(TP3); // get cap voltage with VCC reference ADCconfig.U_Bandgap = ADC_internal_reference; adcmv[1] = ReadADC(TP3); // get cap voltage with internal reference ADCconfig.U_Bandgap = 0; // do not use internal Ref adcmv[2] = ReadADC(TP3); // get cap voltage with VCC reference ADCconfig.U_Bandgap = ADC_internal_reference; udiff = (int8_t)(((signed long)(adcmv[0] + adcmv[2] - adcmv[1] - adcmv[1])) * ADC_internal_reference / (2*adcmv[1]))+REF_R_KORR; lcd_line2(); lcd_fix2_string(REF_R_str); // "REF_R=" udiff2 = udiff + (int8_t)eeprom_read_byte((uint8_t *)(&RefDiff)); (void) eeprom_write_byte((uint8_t *)(&RefDiff), (uint8_t)udiff2); // hold offset for true reference Voltage lcd_string(itoa(udiff2, outval, 10)); // output correction voltage #endif wait_about4s(); break; } lcd_line2(); DisplayValue(cap.cval,cap.cpre,'F',4); wait_about200ms(); // wait additional time } // end for ww #endif ADCconfig.Samples = ANZ_MESS; // set to configured number of ADC samples lcd_clear(); lcd_line2(); lcd_fix2_string(VERSION_str); // "Version ..." lcd_line1(); lcd_fix_string(ATE); // "Selftest End" #ifdef FREQUENCY_50HZ //#define TEST_SLEEP_MODE // only select for checking the sleep delay lcd_fix_string(T50HZ); // " 50Hz" ADC_PORT = TXD_VAL; ADC_DDR = 1<<TP1 | TXD_MSK; // Pin 1 to GND R_DDR = (1<<(TP3*2)) | (1<<(TP2*2)); for(ww=0;ww<30;ww++) { // repeat the signal up to 30 times (1 minute) for (ii=0;ii<100;ii++) { // for 2 s generate 50 Hz R_PORT = (1<<(TP2*2)); // Pin 2 over R_L to VCC, Pin 3 over R_L to GND #ifdef TEST_SLEEP_MODE sleep_5ms(2); // test of timing of sleep mode call #else wait10ms(); // normal delay #endif R_PORT = (1<<(TP3*2)); // Pin 3 over R_L to VCC, Pin 2 over R_L to GND #ifdef TEST_SLEEP_MODE sleep_5ms(2); // test of timing of sleep mode call #else wait10ms(); // normal delay #endif wdt_reset(); } if (!(ON_PIN_REG & (1<<RST_PIN))) { // if key is pressed, don't repeat break; } } #endif PartFound = PART_NONE; wait_about1s(); #endif } #ifdef RequireShortedProbes /* * check for a short circuit between two probes * from Markus R. * * requires: * - ID of first probe (0-2) * - ID of second probe (0-2) * * returns: * - 0 if not shorted * - 1 if shorted */ uint8_t ShortedProbes(uint8_t Probe1, uint8_t Probe2) { uint8_t Flag1 = 0; // return value unsigned int U1; // voltage at probe #1 in mV unsigned int U2; // voltage at probe #2 in mV unsigned int URH; // half of reference voltage // Set up a voltage divider between the two probes: // - Probe1: Rl pull-up // - Probe2: Rl pull-down R_PORT = pgm_read_byte(&PinRLtab[Probe1]); R_DDR = pgm_read_byte(&PinRLtab[Probe1]) | pgm_read_byte(&PinRLtab[Probe2]); // read voltages U1 = ReadADC(Probe1); U2 = ReadADC(Probe2); // We expect both probe voltages to be about the same and // to be half of Vcc (allowed difference +/- 20mV). URH = ADCconfig.U_AVCC / 2; if ((U1 > URH - 20) && (U1 < URH + 20)) { if ((U2 > URH - 20) && (U2 < URH + 20)) { Flag1 = 1; } } // reset port R_DDR = 0; return Flag1; } /* * check for a short circuit between all probes * from Markus R. * * returns: * - 0 if no probes are short-circuited * - number of probe pairs short-circuited (3 = all) */ uint8_t AllProbesShorted(void) { uint8_t Flag2; // return value // check all possible combinations Flag2 = ShortedProbes(TP1, TP2); Flag2 += ShortedProbes(TP1, TP3); Flag2 += ShortedProbes(TP2, TP3); return Flag2; } #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 hp1; unsigned int hp2; unsigned int hp3; unsigned int lp1; unsigned int lp2; unsigned int tp1; unsigned int tp2; } adc; uint8_t LoPinRL; // mask to switch the LowPin with R_L uint8_t LoPinRH; // mask to switch the LowPin with R_H 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 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 ii; // temporary variable #ifdef COMMON_EMITTER unsigned int tmp16; // temporary variable #else #warning "without common emitter hFE" #endif #if FLASHEND > 0x1fff int udiff; #endif #ifdef COMMON_COLLECTOR unsigned long c_hfe; // amplification factor for common Collector (Emitter follower) #endif struct resis_t *thisR; unsigned long lrx1; unsigned long lirx1; unsigned long lirx2; /* switch HighPin directls to VCC switch R_L port for LowPin to GND TristatePin remains switched to input , no action required */ wdt_reset(); //#ifdef AUTO_CAL // uint16_t resis680pl; // uint16_t resis680mi; // resis680pl = eeprom_read_word(&R680pl); // resis680mi = eeprom_read_word(&R680mi); // #define RR680PL resis680pl // #define RR680MI resis680mi //#else // #define RR680PL (R_L_VAL + PIN_RP) // #define RR680MI (R_L_VAL + PIN_RM) //#endif LoPinRL = pgm_read_byte(&PinRLtab[LowPin]); // instruction for LowPin R_L LoPinRH = LoPinRL + LoPinRL; // instruction for LowPin R_H TriPinRL = pgm_read_byte(&PinRLtab[TristatePin]); // instruction for TristatePin R_L TriPinRH = TriPinRL + TriPinRL; // instruction for TristatePin R_H HiPinRL = pgm_read_byte(&PinRLtab[HighPin]); // instruction for HighPin R_L HiPinRH = HiPinRL + HiPinRL; // instruction for HighPin R_H HiADCp = pgm_read_byte(&PinADCtab[HighPin]); // instruction for ADC High-Pin LoADCp = pgm_read_byte(&PinADCtab[LowPin]); // instruction for ADC Low-Pin HiADCm = HiADCp | TXD_MSK; HiADCp |= TXD_VAL; LoADCm = LoADCp | TXD_MSK; LoADCp |= TXD_VAL; // setting of Pins 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 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_line2(); lcd_clear_line(); lcd_line2(); #endif //if(adc.lp_otr > 92) { // there is some current without TristatePin current if(adc.lp_otr > 455) { // there is more than 650uA current without TristatePin current #if DebugOut == 5 lcd_testpin(LowPin); lcd_data('F'); lcd_testpin(HighPin); lcd_space(); wait_about1s(); #endif // Test if N-JFET or if self-conducting N-MOSFET R_DDR = LoPinRL | TriPinRH; // switch R_H for Tristate-Pin (probably Gate) to GND adc.lp1 = W20msReadADC(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 = W20msReadADC(LowPin); // measure voltage at the assumed Source again // If it is a self-conducting MOSFET or JFET, then must be: adc.lp2 > adc.lp1 if (adc.lp2>(adc.lp1+488)) { if (PartFound != PART_FET) { // 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 = W20msReadADC(TristatePin); // read voltage of assumed Gate if (adc.lp2>3911) { // MOSFET PartFound = PART_FET; // N-Kanal-MOSFET PartMode = PART_MODE_N_D_MOS; // Depletion-MOSFET } else { // JFET (pn-passage between Gate and Source is conducting ) PartFound = PART_FET; // N-Kanal-JFET PartMode = PART_MODE_N_JFET; } #if DebugOut == 5 lcd_data('N'); lcd_data('J'); #endif //if ((PartReady == 0) || (adc.lp1 > trans.uBE[0])) // there is no way to find out the right Source / Drain trans.uBE[0] = adc.lp1; gthvoltage = adc.lp1 - adc.tp1; // voltage GS (Source - Gate) trans.uBE[1] = (unsigned int)(((unsigned long)adc.lp1 * 1000) / RR680MI); // Id 0.01mA trans.b = TristatePin; // save Pin numbers found for this FET trans.c = HighPin; trans.e = LowPin; } } 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 = W20msReadADC(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 = W20msReadADC(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+488)) { if (PartFound != PART_FET) { // 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 = W20msReadADC(TristatePin); //read voltage at the assumed Gate if (adc.tp2<977) { // MOSFET PartFound = PART_FET; // P-Kanal-MOSFET PartMode = PART_MODE_P_D_MOS; // Depletion-MOSFET } else { // JFET (pn-passage between Gate and Source is conducting) PartFound = PART_FET; // P-Kanal-JFET PartMode = PART_MODE_P_JFET; } #if DebugOut == 5 lcd_data('P'); lcd_data('J'); #endif gthvoltage = adc.tp1 - adc.hp1; // voltage GS (Gate - Source) trans.uBE[1] = (unsigned int)(((unsigned long)(ADCconfig.U_AVCC - adc.hp1) * 1000) / RR680PL); // Id 0.01mA trans.b = TristatePin; // save Pin numbers found for this FET trans.c = LowPin; trans.e = HighPin; } } } // end component has current without TristatePin signal #ifdef COMMON_COLLECTOR // Test circuit with common collector (Emitter follower) PNP ADC_PORT = TXD_VAL; ADC_DDR = LoADCm; // Collector direct to GND R_PORT = HiPinRL; // switch R_L port for HighPin (Emitter) to VCC R_DDR = TriPinRL | HiPinRL; // Base resistor R_L to GND adc.hp1 = ADCconfig.U_AVCC - W5msReadADC(HighPin); // voltage at the Emitter resistor adc.tp1 = ReadADC(TristatePin); // voltage at the base resistor if (adc.tp1 < 10) { R_DDR = TriPinRH | HiPinRL; // Tripin=RH- adc.hp1 = ADCconfig.U_AVCC - W5msReadADC(HighPin); adc.tp1 = ReadADC(TristatePin); // voltage at base resistor #ifdef LONG_HFE c_hfe = ((unsigned long)adc.hp1 * (unsigned long)(((unsigned long)R_H_VAL * 100) / (unsigned int)RR680PL)) / (unsigned int)adc.tp1; #else c_hfe = ((adc.hp1 / ((RR680PL+500)/1000)) * (R_H_VAL/500)) / (adc.tp1/500); #endif } else { c_hfe = (unsigned long)((adc.hp1 - adc.tp1) / adc.tp1); } #endif // set Pins again for circuit with common Emitter PNP R_DDR = LoPinRL; // switch R_L port for Low-Pin to output (GND) R_PORT = 0; // switch all resistor ports to GND ADC_DDR = HiADCm; // switch High-Pin to output ADC_PORT = HiADCp; // switch High-Pin to VCC wait_about5ms(); if (adc.lp_otr < 977) { // if the component has no connection between HighPin and LowPin #if DebugOut == 5 lcd_testpin(LowPin); lcd_data('P'); lcd_testpin(HighPin); lcd_space(); wait_about1s(); #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 // compute current amplification factor in both directions 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) adc.tp2 = ReadADC(TristatePin); // measure voltage at TristatePin (Base) // check, if Test is done before if ((PartFound == PART_TRANSISTOR) || (PartFound == PART_FET)) { PartReady = 1; } #ifdef COMMON_EMITTER trans.uBE[PartReady] = ReadADC(HighPin) - adc.tp2; // Base Emitter Voltage // compute current amplification factor for circuit with common Emitter // hFE = B = Collector current / Base current if(adc.tp2 < 53) { #if DebugOut == 5 lcd_data('<'); lcd_data('5'); lcd_data('3'); #endif adc.tp2 = 53; } tmp16 = adc.lp1; if (tmp16 > adc.lp_otr) { tmp16 -= adc.lp_otr; } #ifdef LONG_HFE trans.hfe[PartReady] = ((unsigned int)tmp16 * (unsigned long)(((unsigned long)R_H_VAL * 100) / (unsigned int)RR680MI)) / (unsigned int)adc.tp2; #else trans.hfe[PartReady] = ((tmp16 / ((RR680MI+500)/1000)) * (R_H_VAL/500)) / (adc.tp2/500); #endif #endif #ifdef COMMON_COLLECTOR // current amplification factor for common Collector (Emitter follower) // c_hFE = (Emitter current - Base current) / Base current #ifdef COMMON_EMITTER if (c_hfe > trans.hfe[PartReady]) { #endif trans.hfe[PartReady] = c_hfe; trans.uBE[PartReady] = ADCconfig.U_AVCC - adc.hp1 - adc.tp1; // Base Emitter Voltage common collector #ifdef COMMON_EMITTER } #endif #endif if (PartFound != PART_THYRISTOR) { if (adc.tp2 > 977) { // PNP-Transistor is found (Base voltage moves to VCC) PartFound = PART_TRANSISTOR; PartMode = PART_MODE_PNP; } else { 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_P_E_MOS; // 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 gthvoltage = 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 gthvoltage += (1023 - ADCW); // Add Tristatepin-Voltage } gthvoltage *= 4; // is equal to 44*ADCW gthvoltage /= 9; // gives resolution in mV } } trans.b = TristatePin; trans.c = LowPin; trans.e = HighPin; } // end if PartFound != PART_THYRISTOR } // end component has current => PNP #ifdef COMMON_COLLECTOR // 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 = ADCconfig.U_AVCC - ReadADC(TristatePin); // voltage at Base resistor if (adc.tp1 < 10) { R_DDR = LoPinRL | TriPinRH; R_PORT = TriPinRH; // Tripin=RH+ adc.lp1 = W5msReadADC(LowPin); adc.tp1 = ADCconfig.U_AVCC - ReadADC(TristatePin); // voltage at Base resistor #ifdef LONG_HFE c_hfe = ((unsigned long)adc.lp1 * (unsigned long)(((unsigned long)R_H_VAL * 100) / (unsigned int)RR680MI)) / (unsigned int)adc.tp1; #else c_hfe = ((adc.lp1 / ((RR680MI+500)/1000)) * (R_H_VAL/500)) / (adc.tp2/500); #endif } else { c_hfe = (adc.lp1 - adc.tp1) / adc.tp1; } #if DebugOut == 5 lcd_line4(); lcd_clear_line(); lcd_line4(); lcd_data('L'); lcd_data('P'); lcd_string(utoa(adc.lp1,outval,10)); lcd_space(); lcd_data('T'); lcd_data('P'); lcd_string(utoa(adc.tp1,outval,10)); wait_about1s(); #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 R_PORT = TriPinRL | HiPinRL; // RL port for High-Pin and Tristate-Pin to Vcc adc.hp1 = W5msReadADC(HighPin); // measure voltage at High-Pin (Collector) if (adc.hp1 < 1600) { // component has current => NPN-Transistor or somthing else #if DebugOut == 5 lcd_testpin(LowPin); lcd_data('N'); lcd_testpin(HighPin); lcd_space(); wait_about1s(); #endif if (PartReady==1) { goto widmes; } // Test auf Thyristor: // Gate discharge ChargePin10ms(TriPinRL,0); // Tristate-Pin (Gate) across R_L 10ms to GND 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 ((adc.hp3 < 1600) && (adc.hp2 > 4400)) { // 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; // Test if Triac R_DDR = 0; R_PORT = 0; ADC_PORT = LoADCp; // Low-Pin fix to VCC wait_about5ms(); R_DDR = HiPinRL; // switch R_L port HighPin to output (GND) if(W5msReadADC(HighPin) > 244) { goto savenresult; // measure voltage at the High-Pin (probably A2); if too high: // component has current => kein Triac } R_DDR = HiPinRL | TriPinRL; // switch R_L port for TristatePin (Gate) to output (GND) => Triac should be triggered if(W5msReadADC(TristatePin) < 977) { goto savenresult; // measure voltage at the Tristate-Pin (probably Gate) ; // if to low, abort } if(ReadADC(HighPin) < 733) { goto savenresult; // component has no current => no Triac => abort } R_DDR = HiPinRL; // TristatePin (Gate) to input if(W5msReadADC(HighPin) < 733) { goto savenresult; // component has no current without base current => no Triac => abort } R_PORT = HiPinRL; // switch R_L port for HighPin to VCC => switch off holding current wait_about5ms(); R_PORT = 0; // switch R_L port for HighPin again to GND; Triac should now switched off if(W5msReadADC(HighPin) > 244) { goto savenresult; // measure voltage at the High-Pin (probably A2) ; // if to high, component is not switched off => no Triac, abort } PartFound = PART_TRIAC; PartReady = 1; goto savenresult; } // Test if NPN Transistor or MOSFET //ADC_DDR = LoADCm; // Low-Pin to output 0V R_DDR = HiPinRL | TriPinRH; // R_H port of Tristate-Pin (Basis) to output R_PORT = HiPinRL | TriPinRH; // R_H port of Tristate-Pin (Basis) to VCC wait_about50ms(); adc.hp2 = ADCconfig.U_AVCC - ReadADC(HighPin); // measure the voltage at the collector resistor adc.tp2 = ADCconfig.U_AVCC - ReadADC(TristatePin); // measure the voltage at the base resistor #if DebugOut == 5 lcd_line3(); lcd_clear_line(); lcd_line3(); lcd_data('H'); lcd_data('P'); lcd_string(utoa(adc.hp2,outval,10)); lcd_space(); lcd_data('T'); lcd_data('P'); lcd_string(utoa(adc.tp2,outval,10)); #endif if((PartFound == PART_TRANSISTOR) || (PartFound == PART_FET)) { PartReady = 1; // check, if test is already done once } #ifdef COMMON_EMITTER trans.uBE[PartReady] = ADCconfig.U_AVCC - adc.tp2 - ReadADC(LowPin); // compute current amplification factor for common Emitter // hFE = B = Collector current / Base current if (adc.tp2 < 53) { #if DebugOut == 5 lcd_data('<'); lcd_data('5'); lcd_data('3'); #endif adc.tp2 = 53; } tmp16 = adc.hp2; if (tmp16 > adc.lp_otr) { tmp16 -= adc.lp_otr; } #ifdef LONG_HFE trans.hfe[PartReady] = ((unsigned int)tmp16 * (unsigned long)(((unsigned long)R_H_VAL * 100) / (unsigned int)RR680PL)) / (unsigned int)adc.tp2; #else trans.hfe[PartReady] = ((tmp16 / ((RR680PL+500)/1000)) * (R_H_VAL/500)) / (adc.tp2/500); #endif #endif #ifdef COMMON_COLLECTOR // compare current amplification factor for common Collector (Emitter follower) // hFE = (Emitterstrom - Basisstrom) / Basisstrom #ifdef COMMON_EMITTER if (c_hfe > trans.hfe[PartReady]) { #endif trans.hfe[PartReady] = c_hfe; trans.uBE[PartReady] = ADCconfig.U_AVCC - adc.lp1 - adc.tp1; #ifdef COMMON_EMITTER } #endif #endif if(adc.tp2 > 2557) { // Basis-voltage R_H is low enough PartFound = PART_TRANSISTOR; // NPN-Transistor is found (Base is near GND) PartMode = PART_MODE_NPN; } else { // Basis has low current if((adc.lp_otr < 97) && (adc.hp2 > 3400)) { // if flow voltage in switched off mode low enough? // (since D-Mode-FET will be detected in error as E-Mode ) PartFound = PART_FET; // N-Kanal-MOSFET is found (Basis/Gate will Not be pulled down) PartMode = PART_MODE_N_E_MOS; #if DebugOut == 5 lcd_line3(); lcd_clear_line(); lcd_line3(); lcd_data('N'); lcd_data('F'); wait_about1s(); #endif // 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 = HiADCm & 7; // measure Threshold voltage of Gate ADMUX = TristatePin | (1<<REFS0); // measure TristatePin, Ref. VCC gthvoltage = 1; // round up ((1*4)/9) for(ii=0;ii<11;ii++) { wdt_reset(); ChargePin10ms(TriPinRL,0); // discharge Gate 10ms with RL R_DDR = HiPinRL | TriPinRH; // slowly charge Gate R_PORT = HiPinRL | TriPinRH; while ((ADC_PIN&PinMSK)); // Wait, until the MOSFET switch and Drain moved to low // 0 is detected with input voltage of 2.12V to 2.24V (tested with mega168 & mega328) R_DDR = HiPinRL; // switch off current ADCSRA |= (1<<ADSC); // start ADC conversion while (ADCSRA&(1<<ADSC)); // wait until ADC finished gthvoltage += ADCW; // add result of ADC } gthvoltage *= 4; // is equal to 44 * ADCW gthvoltage /= 9; // scale to mV } } savenresult: trans.b = TristatePin; // save Pin-constellation trans.c = HighPin; trans.e = LowPin; } // end component conduct => npn ADC_DDR = TXD_MSK; // switch all ADC-Ports to input ADC_PORT = TXD_VAL; // switch all ADC-Ports to 0 (no Pull up) // Finish // end component has no connection between HighPin and LowPin goto widmes; } // component has current // Test if Diode ADC_PORT = TXD_VAL; for (ii=0;ii<200;ii++) { ADC_DDR = LoADCm | HiADCm; // discharge by short of Low and High side wait_about5ms(); // Low and Highpin to GND for discharge ADC_DDR = LoADCm; // switch only Low-Pin fix to GND adc.hp1 = ReadADC(HighPin); // read voltage at High-Pin if (adc.hp1 < (150/8)) break; } /* It is possible, that wrong Parts are detected without discharging, because the gate of a MOSFET can be charged. The additional measurement with the big resistor R_H is made, to differ antiparallel diodes from resistors. A diode has a voltage, that is nearly independent from the current. The voltage of a resistor is proportional to the current. */ #if 0 // first check with higher current (R_L=680) // A diode is found better with a parallel mounted capacitor, // but some capacitors can be detected a a diode. R_DDR = HiPinRL; // switch R_L port for High-Pin to output (VCC) R_PORT = HiPinRL; ChargePin10ms(TriPinRL,1); // discharge of P-Kanal-MOSFET gate adc.lp_otr = W5msReadADC(HighPin) - ReadADC(LowPin); R_DDR = HiPinRH; // switch R_H port for High-Pin output (VCC) R_PORT = HiPinRH; adc.hp2 = W5msReadADC(HighPin); // M--|<--HP--R_H--VCC R_DDR = HiPinRL; // switch R_L port for High-Pin to output (VCC) R_PORT = HiPinRL; ChargePin10ms(TriPinRL,0); // discharge for N-Kanal-MOSFET gate adc.hp1 = W5msReadADC(HighPin) - W5msReadADC(LowPin); R_DDR = HiPinRH; // switch R_H port for High-Pin to output (VCC) R_PORT = HiPinRH; adc.hp3 = W5msReadADC(HighPin); // M--|<--HP--R_H--VCC if(adc.lp_otr > adc.hp1) { adc.hp1 = adc.lp_otr; // the higher value wins adc.hp3 = adc.hp2; } #else // check first with low current (R_H=470k) // With this method the diode can be better differed from a capacitor, // but a parallel to a capacitor mounted diode can not be found. R_DDR = HiPinRH; // switch R_H port for High-Pin output (VCC) R_PORT = HiPinRH; ChargePin10ms(TriPinRL,1); // discharge of P-Kanal-MOSFET gate adc.hp2 = W5msReadADC(HighPin); // M--|<--HP--R_H--VCC ChargePin10ms(TriPinRL,0); // discharge for N-Kanal-MOSFET gate adc.hp3 = W5msReadADC(HighPin); // M--|<--HP--R_H--VCC // check with higher current (R_L=680) R_DDR = HiPinRL; // switch R_L port for High-Pin to output (VCC) R_PORT = HiPinRL; adc.hp1 = W5msReadADC(HighPin) - ReadADC(LowPin); ChargePin10ms(TriPinRL,1); // discharge for N-Kanal-MOSFET gate adc.lp_otr = W5msReadADC(HighPin) - ReadADC(LowPin); R_DDR = HiPinRH; // switch R_H port for High-Pin output (VCC) R_PORT = HiPinRH; if(adc.lp_otr > adc.hp1) { adc.hp1 = adc.lp_otr; // the higher value wins adc.hp3 = adc.hp2; } else { ChargePin10ms(TriPinRL,0); // discharge for N-Kanal-MOSFET gate } adc.hp2 = W5msReadADC(HighPin); // M--|<--HP--R_H--VCC #endif #if DebugOut == 4 lcd_line3(); lcd_clear_line(); lcd_line3(); lcd_testpin(HighPin); lcd_data('D'); lcd_testpin(LowPin); lcd_space(); lcd_data('h'); lcd_string(utoa(adc.hp3,outval,10)); lcd_space(); lcd_data('L'); lcd_string(utoa(adc.hp1,outval,10)); lcd_space(); lcd_data('H'); lcd_string(utoa(adc.hp2,outval,10)); lcd_space(); wait_about1s(); #endif //if((adc.hp1 > 150) && (adc.hp1 < 4640) && (adc.hp1 > (adc.hp3+(adc.hp3/8))) && (adc.hp3*8 > adc.hp1)) { if((adc.hp1 > 150) && (adc.hp1 < 4640) && (adc.hp2 < adc.hp1) && (adc.hp1 > (adc.hp3+(adc.hp3/8))) && (adc.hp3*16 > adc.hp1)) { // voltage is above 0,15V and below 4,64V => Ok if((PartFound == PART_NONE) || (PartFound == PART_RESISTOR)) { PartFound = PART_DIODE; // mark for diode only, if no other component is found // since there is a problem with Transistors with a protection diode #if DebugOut == 4 lcd_data('D'); #endif } diodes[NumOfDiodes].Anode = HighPin; diodes[NumOfDiodes].Cathode = LowPin; diodes[NumOfDiodes].Voltage = adc.hp1; // voltage in Millivolt NumOfDiodes++; } // end voltage is above 0,15V and below 4,64V #if DebugOut == 4 lcd_data(NumOfDiodes+'0'); #endif widmes: if (NumOfDiodes > 0) goto clean_ports; // resistor measurement wdt_reset(); // U_SCALE can be set to 4 for better resolution of ReadADC result #if U_SCALE != 1 ADCconfig.U_AVCC *= U_SCALE; // scale to higher resolution, mV scale is not required ADCconfig.U_Bandgap *= U_SCALE; #endif #if R_ANZ_MESS != ANZ_MESS ADCconfig.Samples = R_ANZ_MESS; // switch to special number of repetitions #endif #define MAX_REPEAT (700 / (5 + R_ANZ_MESS/8)) ADC_PORT = TXD_VAL; ADC_DDR = LoADCm; // switch Low-Pin to output (GND) R_DDR = HiPinRL; // switch R_L port for High-Pin to output (VCC) R_PORT = HiPinRL; #if FLASHEND > 0x1fff adc.hp2 = 0; for (ii=1;ii<MAX_REPEAT;ii++) { // wait until voltage is stable adc.tp1 = W5msReadADC(LowPin); // low-voltage at Rx with load adc.hp1 = ReadADC(HighPin); // voltage at resistor Rx with R_L udiff = adc.hp1 - adc.hp2; if (udiff < 0) udiff = -udiff; if (udiff < 3) break; adc.hp2 = adc.hp1; wdt_reset(); } if (ii == MAX_REPEAT) goto testend; #else adc.tp1 = W5msReadADC(LowPin); // low-voltage at Rx with load adc.hp1 = ReadADC(HighPin); // voltage at resistor Rx with R_L #endif if (adc.tp1 > adc.hp1) { adc.tp1 = adc.hp1; } R_PORT = 0; R_DDR = HiPinRH; // switch R_H port for High-Pin to output (GND) adc.hp2 = W5msReadADC(HighPin); // read voltage, should be down if (adc.hp2 > (20*U_SCALE)) { // if resistor, voltage should be down #if DebugOut == 3 lcd_line3(); lcd_clear_line(); lcd_line3(); lcd_testpin(LowPin); lcd_data('U'); lcd_testpin(HighPin); lcd_data('A'); lcd_string(utoa(adc.hp1, outval, 10)); lcd_data('B'); lcd_string(utoa(adc.hp2, outval, 10)); lcd_space(); #endif goto testend; } R_PORT = HiPinRH; // switch R_H for High-Pin to VCC adc.hp2 = W5msReadADC(HighPin); // voltage at resistor Rx with R_H ADC_DDR = HiADCm; // switch High-Pin to output ADC_PORT = HiADCp; // switch High-Pin to VCC R_PORT = 0; R_DDR = LoPinRL; // switch R_L for Low-Pin to GND #if FLASHEND > 0x1fff adc.lp2 = 0; for (ii=1;ii<MAX_REPEAT;ii++) { // wait until voltage is stable adc.tp2 = W5msReadADC(HighPin); // high voltage with load adc.lp1 = ReadADC(LowPin); // voltage at the other end of Rx udiff = adc.lp1 - adc.lp2; if (udiff < 0) udiff = -udiff; if (udiff < 3) break; adc.lp2 = adc.lp1; wdt_reset(); } if (ii == MAX_REPEAT) goto testend; #else adc.tp2 = W5msReadADC(HighPin); // high voltage with load adc.lp1 = ReadADC(LowPin); // voltage at the other end of Rx #endif if (adc.tp2 < adc.lp1) { adc.tp2 = adc.lp1; } R_DDR = LoPinRH; // switch R_H for Low-Pin to GND adc.lp2 = W5msReadADC(LowPin); if((adc.hp1 < (4400*U_SCALE)) && (adc.hp2 > (97*U_SCALE))) { //voltage break down isn't insufficient #if DebugOut == 3 lcd_data('F'); #endif goto testend; } //if ((adc.hp2 + (adc.hp2 / 61)) < adc.hp1) if (adc.hp2 < (4972*U_SCALE)) { // voltage breaks down with low test current and it is not nearly shorted => resistor //if (adc.lp1 < 120) { // take measurement with R_H if (adc.lp1 < (169*U_SCALE)) { // take measurement with R_H ii = 'H'; if (adc.lp2 < (38*U_SCALE)) { // measurement > 60MOhm to big resistance goto testend; } // two measurements with R_H resistors (470k) are made: // lirx1 (measurement at HighPin) lirx1 = (unsigned long)((unsigned int)R_H_VAL) * (unsigned long)adc.hp2 / (ADCconfig.U_AVCC - adc.hp2); // lirx2 (measurement at LowPin) lirx2 = (unsigned long)((unsigned int)R_H_VAL) * (unsigned long)(ADCconfig.U_AVCC - adc.lp2) / adc.lp2; #define U_INT_LIMIT (990*U_SCALE) // 1V switch limit in ReadADC for atmega family #ifdef __AVR_ATmega8__ #define FAKT_LOW 2 // resolution is about twice as good #else #define FAKT_LOW 4 // resolution is about four times better #endif #ifdef AUTOSCALE_ADC if (adc.hp2 < U_INT_LIMIT) { lrx1 = (lirx1*FAKT_LOW + lirx2) / (FAKT_LOW+1); // weighted average of both R_H measurements } else if (adc.lp2 < U_INT_LIMIT){ lrx1 = (lirx2*FAKT_LOW + lirx1) / (FAKT_LOW+1); // weighted average of both R_H measurements } else #endif { lrx1 = (lirx1 + lirx2) / 2; // average of both R_H measurements } lrx1 *= 100; lrx1 += RH_OFFSET; // add constant for correction of systematic error } else { ii = 'L'; // two measurements with R_L resistors (680) are made: // lirx1 (measurement at HighPin) if (adc.tp1 > adc.hp1) { adc.hp1 = adc.tp1; // diff negativ is illegal } lirx1 =(unsigned long)RR680PL * (unsigned long)(adc.hp1 - adc.tp1) / (ADCconfig.U_AVCC - adc.hp1); if (adc.tp2 < adc.lp1) { adc.lp1 = adc.tp2; // diff negativ is illegal } // lirx2 (Measurement at LowPin) lirx2 =(unsigned long)RR680MI * (unsigned long)(adc.tp2 -adc.lp1) / adc.lp1; //lrx1 =(unsigned long)R_L_VAL * (unsigned long)adc.hp1 / (adc.hp3 - adc.hp1); #ifdef AUTOSCALE_ADC if (adc.hp1 < U_INT_LIMIT) { lrx1 = (lirx1*FAKT_LOW + lirx2) / (FAKT_LOW+1); // weighted average of both R_L measurements } else if (adc.lp1 < U_INT_LIMIT) { lrx1 = (lirx2*FAKT_LOW + lirx1) / (FAKT_LOW+1); // weighted average of both R_L measurements } else #endif { lrx1 = (lirx1 + lirx2) / 2; // average of both R_L measurements } } // lrx1 is tempory result #if 0 // The zero resistance is in 0.01 Ohm units and usually so little, that correction for resistors above 10 Ohm // is not necassary ii = eeprom_read_byte(&EE_ESR_ZEROtab[LowPin+HighPin]) / 10; // Resistance offset in 0,1 Ohm units if (ii < lrx1) { lrx1 -= ii; } else { lrx1 = 0; } #endif #if DebugOut == 3 lcd_line3(); lcd_clear_line(); lcd_line3(); lcd_testpin(LowPin); lcd_data(ii); lcd_testpin(HighPin); lcd_space(); if (ii == 'H') { lcd_data('X'); DisplayValue(lirx1,1,LCD_CHAR_OMEGA,4) lcd_space(); lcd_data('Y'); DisplayValue(lirx2,1,LCD_CHAR_OMEGA,4) lcd_space(); } else { lcd_data('x'); DisplayValue(lirx1,-1,LCD_CHAR_OMEGA,4) lcd_space(); lcd_data('y'); DisplayValue(lirx2,-1,LCD_CHAR_OMEGA,4) } lcd_space(); lcd_line4(); lcd_clear_line(); lcd_line4(); DisplayValue(lirx2,-1,LCD_CHAR_OMEGA,4) lcd_space(); lcd_line2(); #endif if((PartFound == PART_DIODE) || (PartFound == PART_NONE) || (PartFound == PART_RESISTOR)) { for (ii=0; ii<ResistorsFound; ii++) { // search measurements with inverse polarity thisR = &resis[ii]; if (thisR->rt != TristatePin) continue; // must be measurement with inverse polarity // resolution is 0.1 Ohm, 1 Ohm = 10 ! lirx1 = (labs((long)lrx1 - (long)thisR->rx) * 10) / (lrx1 + thisR->rx + 100); if (lirx1 > 0) { #if DebugOut == 3 lcd_data('R'); lcd_data('!'); lcd_data('='); DisplayValue(thisR->rx,-1,LCD_CHAR_OMEGA,3) lcd_space(); DisplayValue(lirx1,-1,LCD_CHAR_OMEGA,3) lcd_space(); #endif goto testend; // <10% mismatch } PartFound = PART_RESISTOR; goto testend; } // end for // no same resistor with the same Tristate-Pin found, new one thisR = &resis[ResistorsFound]; // pointer to a free resistor structure thisR->rx = lrx1; // save resistor value #if FLASHEND > 0x1fff thisR->lx = 0; // no inductance #endif thisR->ra = LowPin; // save Pin numbers thisR->rb = HighPin; thisR->rt = TristatePin; // Tristate is saved for easier search of inverse measurement ResistorsFound++; // 1 more resistor found #if DebugOut == 3 lcd_data(ResistorsFound+'0'); lcd_data('R'); #endif } } testend: #if U_SCALE != 1 ADCconfig.U_AVCC /= U_SCALE; // scale back to mV resolution ADCconfig.U_Bandgap /= U_SCALE; #endif #if R_ANZ_MESS != ANZ_MESS ADCconfig.Samples = ANZ_MESS; // switch back to standard number of repetition #endif #ifdef DebugOut #if DebugOut < 10 wait_about2s(); #endif #endif clean_ports: ADC_DDR = TXD_MSK; // all ADC-Pins Input ADC_PORT = TXD_VAL; // all ADC outputs to Ground, keine Pull up R_DDR = 0; // all resistor-outputs to Input R_PORT = 0; // all resistor-outputs to Ground, no Pull up } // end CheckPins() /* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */ // Get residual current in reverse direction of a diode //================================================================= void GetIr(uint8_t hipin, uint8_t lopin) { unsigned int u_res; // reverse voltage at 470k unsigned int ir_nano; //unsigned int ir_micro; uint8_t LoPinR_L; uint8_t HiADC; HiADC = pgm_read_byte(&PinADCtab[hipin]); ADC_PORT = HiADC | TXD_VAL; // switch ADC port to high level ADC_DDR = HiADC | TXD_MSK; // switch High Pin direct to VCC LoPinR_L = pgm_read_byte(&PinRLtab[lopin]); // R_L mask for LowPin R_L load R_PORT = 0; // switch R-Port to GND R_DDR = LoPinR_L + LoPinR_L; // switch R_H port for LowPin to output (GND) u_res = W5msReadADC(lopin); // read voltage if (u_res == 0) return; // no Output, if no current in reverse direction lcd_fix_string(Ir_str); // output text " Ir=" #ifdef WITH_IRMICRO if (u_res < 2500) { #endif // R_H_VAL has units of 10 Ohm, u_res has units of mV, ir_nano has units of nA ir_nano = (unsigned long)(u_res * 100000UL) / R_H_VAL; DisplayValue(ir_nano,-9,'A',2); // output two digits of current with nA units #ifdef WITH_IRMICRO } else { R_DDR = LoPinR_L; // switch R_L port for LowPin to output (GND) u_res = W5msReadADC(lopin); // read voltage ir_nano = 0xffff; // set to max // RR680MI has units of 0.1 Ohm, u_res has units of mV, ir_micro has units of uA ir_micro = (unsigned long)(u_res * 10000UL) / RR680MI; DisplayValue(ir_micro,-6,'A',2); // output two digits of current in uA units } #endif ADC_DDR = TXD_MSK; // switch off ADC_PORT = TXD_VAL; // switch off R_DDR = 0; // switch off current return; } /* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */ /* extern 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 INHIBIT_SLEEP_MODE //#define StartADCwait() ADCSRA = (1<<ADSC) | (1<<ADEN) | (1<<ADIF) | AUTO_CLOCK_DIV; /* enable ADC and start */ #define StartADCwait() ADCSRA = StartADCmsk; /* Start conversion */\ while (ADCSRA & (1 << ADSC)) /* wait until conversion is done */ #else #define StartADCwait() ADCSRA = (1<<ADEN) | (1<<ADIF) | (1<<ADIE) | AUTO_CLOCK_DIV; /* enable ADC and Interrupt */\ set_sleep_mode(SLEEP_MODE_ADC);\ sleep_mode(); /* Start ADC, return, if ADC has finished */ #endif unsigned int ReadADC (uint8_t Probe) { unsigned int U; // return value (mV) uint8_t Samples; // loop counter unsigned long Value; // ADC value Probe |= (1 << REFS0); // use internal reference anyway #ifdef AUTOSCALE_ADC sample: #endif ADMUX = Probe; // set input channel and U reference #ifdef AUTOSCALE_ADC // if voltage reference changes, wait for voltage stabilization if ((Probe & (1 << REFS1)) != 0) { // switch to 1.1V Reference #ifdef NO_AREF_CAP wait100us(); // time for voltage stabilization #else wait_about10ms(); // time for voltage stabilization #endif } #endif // allways do one dummy read of ADC, 112us StartADCwait(); // start ADC and wait // sample ADC readings Value = 0UL; // reset sampling variable Samples = 0; // number of samples to take while (Samples < ADCconfig.Samples) { // take samples StartADCwait(); // start ADC and wait Value += ADCW; // add ADC reading #ifdef AUTOSCALE_ADC // auto-switch voltage reference for low readings if ((Samples == 4) && (ADCconfig.U_Bandgap > 255) && ((uint16_t)Value < 1024) && !(Probe & (1 << REFS1))) { Probe |= (1 << REFS1); // select internal bandgap reference #if PROCESSOR_TYP == 1280 Probe &= ~(1 << REFS0); // ATmega640/1280/2560 1.1V Reference with REFS0=0 #endif goto sample; // re-run sampling } #endif Samples++; // one more done } #ifdef AUTOSCALE_ADC // convert ADC reading to voltage - single sample: U = ADC reading * U_ref / 1024 // get voltage of reference used if (Probe & (1 << REFS1)) U = ADCconfig.U_Bandgap; // bandgap reference else U = ADCconfig.U_AVCC; // Vcc reference #else U = ADCconfig.U_AVCC; // Vcc reference #endif // convert to voltage Value *= U; // ADC readings * U_ref Value /= 1023; // / 1024 for 10bit ADC // de-sample to get average voltage Value /= ADCconfig.Samples; U = (unsigned int)Value; return U; //return ((unsigned int)(Value / (1023 * (unsigned long)ADCconfig.Samples))); } unsigned int W5msReadADC (uint8_t Probe) { wait_about5ms(); return (ReadADC(Probe)); } unsigned int W10msReadADC (uint8_t Probe) { wait_about10ms(); return (ReadADC(Probe)); } unsigned int W20msReadADC (uint8_t Probe) { wait_about20ms(); return (ReadADC(Probe)); } /* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */ // new code by K.-H. Kubbeler // ReadCapacity tries to find the value of a capacitor by measuring the load time. // first of all the capacitor is discharged. // Then a series of up to 500 load pulses with 10ms duration each is done across the R_L (680Ohm) // resistor. // After each load pulse the voltage of the capacitor is measured without any load current. // If voltage reaches a value of more than 300mV and is below 1.3V, the capacity can be // computed from load time and voltage by a interpolating a build in table. // If the voltage reaches a value of more than 1.3V with only one load pulse, // another measurement methode is used: // The build in 16bit counter can save the counter value at external events. // One of these events can be the output change of a build in comparator. // The comparator can compare the voltage of any of the ADC input pins with the voltage // of the internal reference (1.3V or 1.1V). // After setting up the comparator and counter properly, the load of capacitor is started // with connecting the positive pin with the R_H resistor (470kOhm) to VCC and immediately // the counter is started. By counting the overflow Events of the 16bit counter and watching // the counter event flag the total load time of the capacitor until reaching the internal // reference voltage can be measured. // If any of the tries to measure the load time is successful, // the following variables are set: // cap.cval = value of the capacitor // cap.cval_uncorrected = value of the capacitor uncorrected // cap.esr = serial resistance of capacitor, 0.01 Ohm units // cap.cpre = units of cap.cval (-12==pF, -9=nF, -6=uF) // ca = Pin number (0-2) of the LowPin // cb = Pin number (0-2) of the HighPin //================================================================= void ReadCapacity(uint8_t HighPin, uint8_t LowPin) { // check if capacitor and measure the capacity value unsigned int tmpint; unsigned int adcv[4]; #ifdef INHIBIT_SLEEP_MODE unsigned int ovcnt16; #endif uint8_t HiPinR_L, HiPinR_H; uint8_t LoADC; uint8_t ii; #if FLASHEND > 0x1fff unsigned int vloss; // lost voltage after load pulse in 0.1% #endif #ifdef AUTO_CAL pin_combination = (HighPin * 3) + LowPin - 1; // coded Pin combination for capacity zero offset #endif LoADC = pgm_read_byte(&PinADCtab[LowPin]) | TXD_MSK; HiPinR_L = pgm_read_byte(&PinRLtab[HighPin]); // R_L mask for HighPin R_L load HiPinR_H = HiPinR_L + HiPinR_L; // double for HighPin R_H load #if DebugOut == 10 lcd_line3(); lcd_clear_line(); lcd_line3(); lcd_testpin(LowPin); lcd_data('C'); lcd_testpin(HighPin); lcd_space(); #endif if(PartFound == PART_RESISTOR) { #if DebugOut == 10 lcd_data('R'); wait_about2s(); #endif return; // We have found a resistor already } for (ii=0;ii<NumOfDiodes;ii++) { if ((diodes[ii].Cathode == LowPin) && (diodes[ii].Anode == HighPin) && (diodes[ii].Voltage < 1500)) { #if DebugOut == 10 lcd_data('D'); wait_about2s(); #endif return; } } #if FLASHEND > 0x1fff cap.esr = 0; // set ESR of capacitor to zero vloss = 0; // set lost voltage to zero #endif cap.cval = 0; // set capacity value to zero cap.cpre = -12; // default unit is pF EntladePins(); // discharge capacitor ADC_PORT = TXD_VAL; // switch ADC-Port to GND R_PORT = 0; // switch R-Port to GND ADC_DDR = LoADC; // switch Low-Pin to output (GND) R_DDR = HiPinR_L; // switch R_L port for HighPin to output (GND) adcv[0] = ReadADC(HighPin); // voltage before any load // ******** should adcv[0] be measured without current??? adcv[2] = adcv[0]; // preset to prevent compiler warning for (ovcnt16=0; ovcnt16<500; ovcnt16++) { R_PORT = HiPinR_L; // R_L to 1 (VCC) R_DDR = HiPinR_L; // switch Pin to output, across R to GND or VCC wait10ms(); // wait exactly 10ms, do not sleep R_DDR = 0; // switch back to input R_PORT = 0; // no Pull up wait500us(); // wait a little time wdt_reset(); // read voltage without current, is already charged enough? adcv[2] = ReadADC(HighPin); if (adcv[2] > adcv[0]) { adcv[2] -= adcv[0]; // difference to beginning voltage } else { adcv[2] = 0; // voltage is lower or same as beginning voltage } if ((ovcnt16 == 126) && (adcv[2] < 75)) { // 300mV can not be reached well-timed break; // don't try to load any more } if (adcv[2] > 300) { break; // probably 100mF can be charged well-timed } } // wait 5ms and read voltage again, does the capacitor keep the voltage? //adcv[1] = W5msReadADC(HighPin) - adcv[0]; //wdt_reset(); #if DebugOut == 10 DisplayValue(ovcnt16,0,' ',4); DisplayValue(adcv[2],-3,'V',4); #endif if (adcv[2] < 301) { #if DebugOut == 10 lcd_data('K'); lcd_space(); wait1s(); #endif //if (NumOfDiodes != 0) goto messe_mit_rh; goto keinC; // was never charged enough, >100mF or shorted } // voltage is rised properly and keeps the voltage enough if ((ovcnt16 == 0 ) && (adcv[2] > 1300)) { goto messe_mit_rh; // Voltage of more than 1300mV is reached in one pulse, too fast loaded } // Capacity is more than about 50uF #ifdef NO_CAP_HOLD_TIME ChargePin10ms(HiPinR_H,0); // switch HighPin with R_H 10ms auf GND, then currentless adcv[3] = ReadADC(HighPin) - adcv[0]; // read voltage again, is discharged only a little bit ? if (adcv[3] > adcv[0]) { adcv[3] -= adcv[0]; // difference to beginning voltage } else { adcv[3] = 0; // voltage is lower to beginning voltage } #if DebugOut == 10 lcd_data('U'); lcd_data('3'); lcd_data(':'); lcd_string(utoa(adcv[3],outval,10)); lcd_space(); wait_about2s(); #endif if ((adcv[3] + adcv[3]) < adcv[2]) { #if DebugOut == 10 lcd_data('H'); lcd_space(); wait_about1s(); #endif if (ovcnt16 == 0 ) { goto messe_mit_rh; // Voltage of more than 1300mV is reached in one pulse, but not hold } goto keinC; // implausible, not yet the half voltage } cap.cval_uncorrected.dw = ovcnt16 + 1; cap.cval_uncorrected.dw *= getRLmultip(adcv[2]); // get factor to convert time to capacity from table #else // wait the half the time which was required for loading adcv[3] = adcv[2]; // preset to prevent compiler warning for (tmpint=0; tmpint<=ovcnt16; tmpint++) { wait5ms(); adcv[3] = ReadADC(HighPin); // read voltage again, is discharged only a little bit ? wdt_reset(); } if (adcv[3] > adcv[0]) { adcv[3] -= adcv[0]; // difference to beginning voltage } else { adcv[3] = 0; // voltage is lower or same as beginning voltage } if (adcv[2] > adcv[3]) { // build difference to load voltage adcv[3] = adcv[2] - adcv[3]; // lost voltage during load time wait } else { adcv[3] = 0; // no lost voltage } #if FLASHEND > 0x1fff // compute equivalent parallel resistance from voltage drop if (adcv[3] > 0) { // there is any voltage drop (adcv[3]) ! // adcv[2] is the loaded voltage. vloss = (unsigned long)(adcv[3] * 1000UL) / adcv[2]; } #endif if (adcv[3] > 100) { // more than 100mV is lost during load time #if DebugOut == 10 lcd_data('L'); lcd_space(); wait_about1s(); #endif if (ovcnt16 == 0 ) { goto messe_mit_rh; // Voltage of more than 1300mV is reached in one pulse, but not hold } goto keinC; // capacitor does not keep the voltage about 5ms } cap.cval_uncorrected.dw = ovcnt16 + 1; // compute factor with load voltage + lost voltage during the voltage load time cap.cval_uncorrected.dw *= getRLmultip(adcv[2]+adcv[3]); // get factor to convert time to capacity from table #endif cap.cval = cap.cval_uncorrected.dw; // set result to uncorrected cap.cpre = -9; // switch units to nF Scale_C_with_vcc(); // cap.cval for this type is at least 40000nF, so the last digit will be never shown cap.cval *= (1000 - C_H_KORR); // correct with C_H_KORR with 0.1% resolution, but prevent overflow cap.cval /= 100; #if DebugOut == 10 lcd_line3(); lcd_clear_line(); lcd_line3(); lcd_testpin(LowPin); lcd_data('C'); lcd_testpin(HighPin); lcd_space(); DisplayValue(cap.cval,cap.cpre,'F',4); lcd_space(); lcd_string(utoa(ovcnt16,outval,10)); wait_about3s(); #endif goto checkDiodes; //================================================================================== // Measurement of little capacity values messe_mit_rh: // little capacity value, about < 50 uF EntladePins(); // discharge capacitor // measure with the R_H (470kOhm) resistor R_PORT = 0; // R_DDR ist HiPinR_L ADC_DDR = (1<<TP1) | (1<<TP2) | (1<<TP3) | (1<<TxD); // switch all Pins to output ADC_PORT = TXD_VAL; // switch all ADC Pins to GND R_DDR = HiPinR_H; // switch R_H resistor port for HighPin to output (GND) // setup Analog Comparator ADC_COMP_CONTROL = (1<<ACME); // enable Analog Comparator Multiplexer ACSR = (1<<ACBG) | (1<<ACI) | (1<<ACIC); // enable, 1.3V, no Interrupt, Connect to Timer1 ADMUX = (1<<REFS0) | HighPin; // switch Mux to High-Pin ADCSRA = (1<<ADIF) | AUTO_CLOCK_DIV; // disable ADC wait200us(); // wait for bandgap to start up // setup Counter1 ovcnt16 = 0; TCCR1A = 0; // set Counter1 to normal Mode TCNT1 = 0; // set Counter to 0 TI1_INT_FLAGS = (1<<ICF1) | (1<<OCF1B) | (1<<OCF1A) | (1<<TOV1); // clear interrupt flags #ifndef INHIBIT_SLEEP_MODE TIMSK1 = (1<<TOIE1) | (1<<ICIE1); // enable Timer overflow interrupt and input capture interrupt unfinished = 1; #endif R_PORT = HiPinR_H; // switch R_H resistor port for HighPin to VCC if(PartFound == PART_FET) { // charge capacitor with R_H resistor TCCR1B = (1<<CS10); //Start counter 1MHz or 8MHz ADC_DDR = (((1<<TP1) | (1<<TP2) | (1<<TP3) | TXD_MSK) & ~(1<<HighPin)); // release only HighPin ADC port } else { TCCR1B = (1<<CS10); // start counter 1MHz or 8MHz ADC_DDR = LoADC; // stay LoADC Pin switched to GND, charge capacitor with R_H slowly } //****************************** #ifdef INHIBIT_SLEEP_MODE while(1) { // Wait, until Input Capture is set ii = TI1_INT_FLAGS; // read Timer flags if (ii & (1<<ICF1)) { break; } if((ii & (1<<TOV1))) { // counter overflow, 65.536 ms @ 1MHz, 8.192ms @ 8MHz TI1_INT_FLAGS = (1<<TOV1); // Reset OV Flag wdt_reset(); ovcnt16++; if(ovcnt16 == (F_CPU/5000)) { break; // Timeout for Charging, above 12 s } } } TCCR1B = (0<<ICNC1) | (0<<ICES1) | (0<<CS10); // stop counter TI1_INT_FLAGS = (1<<ICF1); // Reset Input Capture tmpint = ICR1; // get previous Input Capture Counter flag // check actual counter, if an additional overflow must be added if((TCNT1 > tmpint) && (ii & (1<<TOV1))) { // this OV was not counted, but was before the Input Capture TI1_INT_FLAGS = (1<<TOV1); // Reset OV Flag ovcnt16++; } #else while(unfinished) { set_sleep_mode(SLEEP_MODE_IDLE); sleep_mode(); // wait for interrupt wdt_reset(); if(ovcnt16 == (F_CPU/5000)) { break; // Timeout for Charging, above 12 s } } TCCR1B = (0<<ICNC1) | (0<<ICES1) | (0<<CS10); // stop counter tmpint = ICR1; // get previous Input Capture Counter flag TIMSK1 = (0<<TOIE1) | (0<<ICIE1); // disable Timer overflow interrupt and input capture interrupt if (TCNT1 < tmpint) { ovcnt16--; // one ov to much } #endif //------------------------------------------------------------ ADCSRA = (1<<ADEN) | (1<<ADIF) | AUTO_CLOCK_DIV; // enable ADC R_DDR = 0; // switch R_H resistor port for input R_PORT = 0; // switch R_H resistor port pull up for HighPin off adcv[2] = ReadADC(HighPin); // get loaded voltage load_diff = adcv[2] + REF_C_KORR - ref_mv; // build difference of capacitor voltage to Reference Voltage //------------------------------------------------------------ if (ovcnt16 >= (F_CPU/10000)) { #if DebugOut == 10 lcd_data('k'); wait_about1s(); #endif goto keinC; // no normal end } //cap.cval_uncorrected = CombineII2Long(ovcnt16, tmpint); cap.cval_uncorrected.w[1] = ovcnt16; cap.cval_uncorrected.w[0] = tmpint; cap.cpre = -12; // cap.cval unit is pF if (ovcnt16 > 65) { cap.cval_uncorrected.dw /= 100; // switch to next unit cap.cpre += 2; // set unit, prevent overflow } cap.cval_uncorrected.dw *= RHmultip; // 708 cap.cval_uncorrected.dw /= (F_CPU / 10000); // divide by 100 (@ 1MHz clock), 800 (@ 8MHz clock) cap.cval = cap.cval_uncorrected.dw; // set the corrected cap.cval Scale_C_with_vcc(); if (cap.cpre == -12) { #if COMP_SLEW1 > COMP_SLEW2 if (cap.cval < COMP_SLEW1) { // add slew rate dependent offset cap.cval += (COMP_SLEW1 / (cap.cval+COMP_SLEW2 )); } #endif #ifdef AUTO_CAL // auto calibration mode, cap_null can be updated in selftest section tmpint = eeprom_read_byte(&c_zero_tab[pin_combination]); // read zero offset if (cap.cval > tmpint) { cap.cval -= tmpint; // subtract zero offset (pF) } else { cap.cval = 0; // unsigned long may not reach negativ value } #else if (HighPin == TP2) cap.cval += TP2_CAP_OFFSET; // measurements with TP2 have 2pF less capacity if (cap.cval > C_NULL) { cap.cval -= C_NULL; // subtract constant offset (pF) } else { cap.cval = 0; // unsigned long may not reach negativ value } #endif } #if DebugOut == 10 R_DDR = 0; // switch all resistor ports to input lcd_line4(); lcd_clear_line(); lcd_line4(); lcd_testpin(LowPin); lcd_data('c'); lcd_testpin(HighPin); lcd_space(); DisplayValue(cap.cval,cap.cpre,'F',4); wait_about3s(); #endif R_DDR = HiPinR_L; // switch R_L for High-Pin to GND #if F_CPU < 2000001 if(cap.cval < 50) #else if(cap.cval < 25) #endif { // cap.cval can only be so little in pF unit, cap.cpre must not be testet! #if DebugOut == 10 lcd_data('<'); lcd_space(); wait_about1s(); #endif goto keinC; // capacity to low, < 50pF @1MHz (25pF @8MHz) } // end low capacity checkDiodes: if((NumOfDiodes > 0) && (PartFound != PART_FET)) { #if DebugOut == 10 lcd_data('D'); lcd_space(); wait_about1s(); #endif // nearly shure, that there is one or more diodes in reverse direction, // which would be wrongly detected as capacitor } else { PartFound = PART_CAPACITOR; // capacitor is found if ((cap.cpre > cap.cpre_max) || ((cap.cpre == cap.cpre_max) && (cap.cval > cap.cval_max))) { // we have found a greater one cap.cval_max = cap.cval; cap.cpre_max = cap.cpre; #if FLASHEND > 0x1fff cap.v_loss = vloss; // lost voltage in 0.01% #endif cap.ca = LowPin; // save LowPin cap.cb = HighPin; // save HighPin } } keinC: // discharge capacitor again //EntladePins(); // discharge capacitors // ready // switch all ports to input ADC_DDR = TXD_MSK; // switch all ADC ports to input ADC_PORT = TXD_VAL; // switch all ADC outputs to GND, no pull up R_DDR = 0; // switch all resistor ports to input R_PORT = 0; // switch all resistor outputs to GND, no pull up return; } // end ReadCapacity() unsigned int getRLmultip(unsigned int cvolt) { // interpolate table RLtab corresponding to voltage cvolt // Widerstand 680 Ohm 300 325 350 375 400 425 450 475 500 525 550 575 600 625 650 675 700 725 750 775 800 825 850 875 900 925 950 975 1000 1025 1050 1075 1100 1125 1150 1175 1200 1225 1250 1275 1300 1325 1350 1375 1400 mV //uint16_t RLtab[] MEM_TEXT = {22447,20665,19138,17815,16657,15635,14727,13914,13182,12520,11918,11369,10865,10401, 9973, 9577, 9209, 8866, 8546, 8247, 7966, 7702, 7454, 7220, 6999, 6789, 6591, 6403, 6224, 6054, 5892, 5738, 5590, 5449, 5314, 5185, 5061, 4942, 4828, 4718, 4613, 4511, 4413, 4319, 4228}; #define RL_Tab_Abstand 25 // displacement of table 25mV #define RL_Tab_Beginn 300 // begin of table ist 300mV #define RL_Tab_Length 1100 // length of table is 1400-300 unsigned int uvolt; unsigned int y1, y2; uint8_t tabind; uint8_t tabres; if (cvolt >= RL_Tab_Beginn) { uvolt = cvolt - RL_Tab_Beginn; } else { uvolt = 0; // limit to begin of table } tabind = uvolt / RL_Tab_Abstand; tabres = uvolt % RL_Tab_Abstand; tabres = RL_Tab_Abstand - tabres; if (tabind > (RL_Tab_Length/RL_Tab_Abstand)) { tabind = (RL_Tab_Length/RL_Tab_Abstand); // limit to end of table } y1 = MEM_read_word(&RLtab[tabind]); y2 = MEM_read_word(&RLtab[tabind+1]); return ( ((y1 - y2) * tabres + (RL_Tab_Abstand/2)) / RL_Tab_Abstand + y2); // interpolate table } void Scale_C_with_vcc(void) { while (cap.cval > 100000) { cap.cval /= 10; cap.cpre ++; // prevent overflow } cap.cval *= ADCconfig.U_AVCC; // scale with measured voltage cap.cval /= U_VCC; // Factors are computed for U_VCC } #ifndef INHIBIT_SLEEP_MODE // Interrupt Service Routine for timer1 Overflow ISR(TIMER1_OVF_vect, ISR_BLOCK) { ovcnt16++; // count overflow } // Interrupt Service Routine for timer1 capture event (Comparator) ISR(TIMER1_CAPT_vect, ISR_BLOCK) { unfinished = 0; // clear unfinished flag } #endif /* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */ // new code by K.-H. Kubbeler // The 680 Ohm resistor (R_L_VAL) at the Lowpin will be used as current sensor // The current with a coil will with (1 - e**(-t*R/L)), where R is // the sum of Pin_RM , R_L_VAL , Resistance of coil and Pin_RP. // L in the inductance of the coil. //================================================================= void ReadInductance(void) { #if FLASHEND > 0x1fff // check if inductor and measure the inductance value unsigned int tmpint; unsigned int umax; unsigned int total_r; // total resistance of current loop unsigned int mess_r; // value of resistor used for current measurement unsigned long inductance[4]; // four inductance values for different measurements union t_combi{ unsigned long dw; // time_constant uint16_t w[2]; } timeconstant; uint16_t per_ref1,per_ref2; // percentage uint8_t LoPinR_L; // Mask for switching R_L resistor of low pin uint8_t HiADC; // Mask for switching the high pin direct to VCC uint8_t ii; uint8_t count; // counter for the different measurements //uint8_t found; // variable used for searching resistors #define found 0 uint8_t cnt_diff; // resistance dependent offset uint8_t LowPin; // number of pin with low voltage uint8_t HighPin; // number of pin with high voltage int8_t ukorr; // correction of comparator voltage uint8_t nr_pol1; // number of successfull inductance measurement with polarity 1 uint8_t nr_pol2; // number of successfull inductance measurement with polarity 2 if(PartFound != PART_RESISTOR) { return; // We have found no resistor } if (ResistorsFound != 1) { return; // do not search for inductance, more than 1 resistor } //for (found=0;found<ResistorsFound;found++) { // if (resis[found].rx > 21000) continue; if (resis[found].rx > 21000) return; // we can check for Inductance, if resistance is below 2100 Ohm for (count=0; count<4; count++) { // Try four times (different direction and with delayed counter start) if (count < 2) { // first and second pass, direction 1 LowPin = resis[found].ra; HighPin = resis[found].rb; } else { // third and fourth pass, direction 2 LowPin = resis[found].rb; HighPin = resis[found].ra; } HiADC = pgm_read_byte(&PinADCtab[HighPin]); LoPinR_L = pgm_read_byte(&PinRLtab[LowPin]); // R_L mask for HighPin R_L load //================================================================================== // Measurement of Inductance values R_PORT = 0; // switch R port to GND ADC_PORT = TXD_VAL; // switch ADC-Port to GND if ((resis[found].rx < 240) && ((count & 0x01) == 0)) { // we can use PinR_L for measurement mess_r = RR680MI - R_L_VAL; // use only pin output resistance ADC_DDR = HiADC | (1<<LowPin) | TXD_MSK; // switch HiADC and Low Pin to GND, } else { R_DDR = LoPinR_L; // switch R_L resistor port for LowPin to output (GND) ADC_DDR = HiADC | TXD_MSK; // switch HiADC Pin to GND mess_r = RR680MI; // use 680 Ohm and PinR_L for current measurement } // Look, if we can detect any current for (ii=0;ii<20;ii++) { // wait for current is near zero umax = W10msReadADC(LowPin); total_r = ReadADC(HighPin); if ((umax < 2) && (total_r < 2)) break; // low current detected } // setup Analog Comparator ADC_COMP_CONTROL = (1<<ACME); // enable Analog Comparator Multiplexer ACSR = (1<<ACBG) | (1<<ACI) | (1<<ACIC); // enable, 1.3V, no Interrupt, Connect to Timer1 ADMUX = (1<<REFS0) | LowPin; // switch Mux to Low-Pin ADCSRA = (1<<ADIF) | AUTO_CLOCK_DIV; // disable ADC // setup Counter1 timeconstant.w[1] = 0; // set ov counter to 0 TCCR1A = 0; // set Counter1 to normal Mode TCNT1 = 0; // set Counter to 0 TI1_INT_FLAGS = (1<<ICF1) | (1<<OCF1B) | (1<<OCF1A) | (1<<TOV1); // reset TIFR or TIFR1 HiADC |= TXD_VAL; wait200us(); // wait for bandgap to start up if ((count & 0x01) == 0 ) { // first start counter, then start current TCCR1B = (1<<ICNC1) | (0<<ICES1) | (1<<CS10); // start counter 1MHz or 8MHz ADC_PORT = HiADC; // switch ADC-Port to VCC } else { // first start current, then start counter with delay // parasitic capacity of coil can cause high current at the beginning ADC_PORT = HiADC; // switch ADC-Port to VCC #if F_CPU >= 8000000UL wait3us(); // ignore current peak from capacity #else wdt_reset(); // delay wdt_reset(); // delay #endif TI1_INT_FLAGS = (1<<ICF1); // Reset Input Capture TCCR1B = (1<<ICNC1) | (0<<ICES1) | (1<<CS10); // start counter 1MHz or 8MHz } //****************************** while(1) { // Wait, until Input Capture is set ii = TI1_INT_FLAGS; // read Timer flags if (ii & (1<<ICF1)) { break; } if((ii & (1<<TOV1))) { // counter overflow, 65.536 ms @ 1MHz, 8.192ms @ 8MHz TI1_INT_FLAGS = (1<<TOV1); // Reset OV Flag wdt_reset(); timeconstant.w[1]++; // count one OV if(timeconstant.w[1] == (F_CPU/100000UL)) { break; // Timeout for Charging, above 0.13 s } } } TCCR1B = (0<<ICNC1) | (0<<ICES1) | (0<<CS10); // stop counter TI1_INT_FLAGS = (1<<ICF1); // Reset Input Capture timeconstant.w[0] = ICR1; // get previous Input Capture Counter flag // check actual counter, if an additional overflow must be added if((TCNT1 > timeconstant.w[0]) && (ii & (1<<TOV1))) { // this OV was not counted, but was before the Input Capture TI1_INT_FLAGS = (1<<TOV1); // Reset OV Flag timeconstant.w[1]++; // count one additional OV } ADC_PORT = TXD_VAL; // switch ADC-Port to GND ADCSRA = (1<<ADEN) | (1<<ADIF) | AUTO_CLOCK_DIV; // enable ADC for (ii=0;ii<20;ii++) { // wait for current is near zero umax = W10msReadADC(LowPin); total_r = ReadADC(HighPin); if ((umax < 2) && (total_r < 2)) break; // low current detected } #define CNT_ZERO_42 6 #define CNT_ZERO_720 7 //#if F_CPU == 16000000UL // #undef CNT_ZERO_42 // #undef CNT_ZERO_720 // #define CNT_ZERO_42 7 // #define CNT_ZERO_720 10 //#endif total_r = (mess_r + resis[found].rx + RRpinMI); //cnt_diff = 0; //if (total_r > 7000) cnt_diff = 1; //if (total_r > 14000) cnt_diff = 2; cnt_diff = total_r / ((14000UL * 8) / (F_CPU/1000000UL)); // Voltage of comparator in % of umax #ifdef AUTO_CAL tmpint = (ref_mv + (int16_t)eeprom_read_word((uint16_t *)(&ref_offset))) ; #else tmpint = (ref_mv + REF_C_KORR); #endif if (mess_r < R_L_VAL) { // measurement without 680 Ohm cnt_diff = CNT_ZERO_42; if (timeconstant.dw < 225) { ukorr = (timeconstant.w[0] / 5) - 20; } else { ukorr = 25; } tmpint -= (((REF_L_KORR * 10) / 10) + ukorr); } else { // measurement with 680 Ohm resistor // if 680 Ohm resistor is used, use REF_L_KORR for correction cnt_diff += CNT_ZERO_720; tmpint += REF_L_KORR; } if (timeconstant.dw > cnt_diff) timeconstant.dw -= cnt_diff; else timeconstant.dw = 0; if ((count&0x01) == 1) { // second pass with delayed counter start timeconstant.dw += (3 * (F_CPU/1000000UL))+10; } if (timeconstant.w[1] >= (F_CPU/100000UL)) timeconstant.dw = 0; // no transition found if (timeconstant.dw > 10) { timeconstant.dw -= 1; } // compute the maximum Voltage umax with the Resistor of the coil umax = ((unsigned long)mess_r * (unsigned long)ADCconfig.U_AVCC) / total_r; per_ref1 = ((unsigned long)tmpint * 1000) / umax; //per_ref2 = (uint8_t)MEM2_read_byte(&LogTab[per_ref1]); // -log(1 - per_ref1/100) per_ref2 = get_log(per_ref1); // -log(1 - per_ref1/1000) //********************************************************* #if 0 if (count == 0) { lcd_line3(); DisplayValue(count,0,' ',4); DisplayValue(timeconstant.dw,0,'+',4); DisplayValue(cnt_diff,0,' ',4); DisplayValue(total_r,-1,'r',4); lcd_space(); DisplayValue(per_ref1,-1,'%',4); lcd_line4(); DisplayValue(tmpint,-3,'V',4); lcd_space(); DisplayValue(umax,-3,'V',4); lcd_space(); DisplayValue(per_ref2,-1,'%',4); wait_about4s(); wait_about2s(); } #endif //********************************************************* // lx in 0.01mH units, L = Tau * R per_ref1 = ((per_ref2 * (F_CPU/1000000UL)) + 5) / 10; inductance[count] = (timeconstant.dw * total_r ) / per_ref1; if (((count&0x01) == 0) && (timeconstant.dw > ((F_CPU/1000000UL)+3))) { // transition is found, measurement with delayed counter start is not necessary inductance[count+1] = inductance[count]; // set delayed measurement to same value count++; // skip the delayed measurement } wdt_reset(); } // end for count ADC_PORT = TXD_VAL; // switch ADC Port to GND wait_about20ms(); #if 0 if (inductance[1] > inductance[0]) { resis[found].lx = inductance[1]; // use value found with delayed counter start } else { resis[found].lx = inductance[0]; } if (inductance[3] > inductance[2]) inductance[2] = inductance[3]; // other polarity, delayed start if (inductance[2] < resis[found].lx) resis[found].lx = inductance[2]; // use the other polarity #else nr_pol1 = 0; if (inductance[1] > inductance[0]) { nr_pol1 = 1; } nr_pol2 = 2; if (inductance[3] > inductance[2]) { nr_pol2 = 3; } if (inductance[nr_pol2] < inductance[nr_pol1]) nr_pol1 = nr_pol2; resis[found].lx = inductance[nr_pol1]; resis[found].lpre = -5; // 10 uH units if (((nr_pol1 & 1) == 1) || (resis[found].rx >= 240)) { // with 680 Ohm resistor total_r is more than 7460 resis[found].lpre = -4; // 100 uH units resis[found].lx = (resis[found].lx + 5) / 10; } #endif //} // end loop for all resistors // switch all ports to input ADC_DDR = TXD_MSK; // switch all ADC ports to input R_DDR = 0; // switch all resistor ports to input #endif return; } // end ReadInductance() #if FLASHEND > 0x1fff // get_log interpolate a table with the function -log(1 - (permil/1000)) uint16_t get_log(uint16_t permil) { // for remember: // uint16_t LogTab[] PROGMEM = {0, 20, 41, 62, 83, 105, 128, 151, 174, 198, 223, 248, 274, 301, 329, 357, 386, 416, 446, 478, 511, 545, 580, 616, 654, 693, 734, 777, 821, 868, 916, 968, 1022, 1079, 1139, 1204, 1273, 1347, 1427, 1514, 1609, 1715, 1833, 1966, 2120, 2303, 2526 }; #define Log_Tab_Distance 20 // displacement of table is 20 mil uint16_t y1, y2; // table values uint16_t result; // result of interpolation uint8_t tabind; // index to table value uint8_t tabres; // distance to lower table value, fraction of Log_Tab_Distance tabind = permil / Log_Tab_Distance; // index to table tabres = permil % Log_Tab_Distance; // fraction of table distance // interpolate the table of factors y1 = pgm_read_word(&LogTab[tabind]); // get the lower table value y2 = pgm_read_word(&LogTab[tabind+1]); // get the higher table value result = ((y2 - y1) * tabres ) / Log_Tab_Distance + y1; // interpolate return(result); } #endif /* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */ #define MAX_CNT 255 /* The sleep mode for ADC can be used. It is implemented for 8MHz and 16MHz operation */ /* But the ESR result is allways higher than the results with wait mode. */ /* The time of ESR measurement is higher with the sleep mode (checked with oszilloscope) */ /* The reason for the different time is unknown, the start of the next ADC measurement */ /* should be initiated before the next ADC-clock (8 us). One ADC takes 13 ADC clock + 1 clock setup. */ /* The setting to sleep mode takes 10 clock tics, the wakeup takes about 24 clock tics, but 8us are 64 clock tics. */ /* I have found no reason, why a reset of the ADC clock divider should occur during ESR measurement. */ //#define ADC_Sleep_Mode //#define ESR_DEBUG #ifdef ADC_Sleep_Mode //#define StartADCwait() ADCSRA = (1<<ADEN) | (1<<ADIF) | (1<<ADIE) | AUTO_CLOCK_DIV; /* enable ADC and Interrupt */ //#define StartADCwait() set_sleep_mode(SLEEP_MODE_ADC); //sleep_mode() /* Start ADC, return if ADC has finished */ #define StartADCwait() sleep_cpu() #else //#define StartADCwait() ADCSRA = (1<<ADSC) | (1<<ADEN) | (1<<ADIF) | AUTO_CLOCK_DIV; /* enable ADC and start */ #define StartADCwait() ADCSRA = StartADCmsk; /* Start conversion */\ while (ADCSRA & (1 << ADSC)) /* wait until conversion is done */ #endif /************************************************************************/ /* Predefine the wait time for switch off the load current for big caps */ /************************************************************************/ // wdt_reset(); // with wdt_reset the timing can be adjusted, // when time is too short, voltage is down before SH of ADC // when time is too long, capacitor will be overloaded. // That will cause too high voltage without current. #ifdef ADC_Sleep_Mode // Interrupt mode, big cap #if F_CPU == 8000000UL #define DelayBigCap() wait10us(); /* 2.5 ADC clocks = 20us */ \ wait5us(); /* */ \ wait2us(); /* with only 17 us delay the voltage goes down before SH */ \ /* delay 17us + 3 clock tics (CALL instead of RCALL) = 17.375 us @ 8 MHz */ \ /* + 21 clock tics delay from interrupt return, +2.625us = 20.0 */ \ wdt_reset(); /* 20.125 us */ \ wdt_reset() /* 20.250 us */ #endif #if F_CPU == 16000000UL #define DelayBigCap() us500delay(18); /* 2.5 ADC clocks = 20us */ \ /* with only 18 us delay the voltage goes down before SH */ \ /* delay 18us 500ns + 1 clock tics (CALL instead of RCALL) = 18.5625 us */ \ /* + 21 clock tics delay from interrupt return, +1.3125us = 19.8750 */ \ wdt_reset(); /* 19.9375 us */ \ wdt_reset(); /* 20.0000 us */ \ wdt_reset(); /* 20.0625 us */ \ wdt_reset(); /* 20.1250 us */ \ wdt_reset(); /* 20.1875 us */ \ wdt_reset() /* 20.2500 us */ #endif #else // Polling mode, big cap #if F_CPU == 8000000UL #define DelayBigCap() wait10us(); /* 2.5 ADC clocks = 20us */ \ wait5us(); /* */ \ wait4us(); /* pulse length 19.375 us */ /* delay 19us + 3 clock tics (CALL instead of RCALL) = 19.375 us @ 8 MHz */ /* + 7 clock tics delay from while loop, +0.875us = 20.250 */ // wdt_reset() /* 20.375 us + */ #endif #if F_CPU == 16000000UL #define DelayBigCap() delayMicroseconds(20) // #define DelayBigCap() us500delay(19); /* 2.5 ADC clocks = 20us */ \ // /* with only 18 us delay the voltage goes down before SH */ \ // /* delay 19us 500ns + 1 clock tics (CALL instead of RCALL) = 19.5625 us */ \ // /* + 7 clock tics delay from "while (ADCSRA&(1<<ADSC))" loop = 20.0000 */ \ // wdt_reset(); /* 20.0625 us */ \ // wdt_reset(); /* 20.1250 us */ \ // wdt_reset(); /* 20.1875 us */ \ // wdt_reset() /* 20.2500 us */ #endif #endif /**************************************************************************/ /* Predefine the wait time for switch off the load current for small caps */ /**************************************************************************/ // SH at 2.5 ADC clocks behind start = 5 us #ifdef ADC_Sleep_Mode // Interrupt mode, small cap #if F_CPU == 8000000UL #define DelaySmallCap() wait2us(); /* with only 4 us delay the voltage goes down before SH */ \ /* delay 2us + 1 clock tics (CALL instead of RCALL) = 2.125 us @ 8 MHz */ \ /* + 21 clock tics delay from interrupt return, +2.625us = 4.75 */ \ wdt_reset(); /* 4.875 us */ \ wdt_reset(); /* 5.000 us */ \ wdt_reset() /* 5.125 us */ #endif #if F_CPU == 16000000UL #define DelaySmallCap() us500delay(3); /* with only 18 us delay the voltage goes down before SH */ \ /* delay 3us 500ns + 1 clock tics (CALL instead of RCALL) = 3.5625 us */ \ /* + 21 clock tics delay from interrupt return, +1.3125us = 4.875 */ \ wdt_reset(); /* 4.9375 us */ \ wdt_reset(); /* 5.0000 us */ \ wdt_reset(); /* 5.0625 us */ \ wdt_reset() /* 5.1250 us */ #endif #else // Polling mode, small cap #if F_CPU == 8000000UL #define DelaySmallCap() wait4us(); /* with only 4 us delay the voltage goes down before SH */ \ /* delay 4us + 1 clock tics (CALL instead of RCALL) = 4.125 us @ 8 MHz */ \ /* + 7 clock tics delay from while loop, +0.875us = 5.000 */ \ wdt_reset() /* 5.125 us */ #endif #if F_CPU == 16000000UL #define DelaySmallCap() us500delay(4); /* with only 4 us delay the voltage goes down before SH */ \ /* delay 4us 500ns + 1 clock tics (CALL instead of RCALL) = 4.5625 us */ \ /* + 7 clock tics delay from "while (ADCSRA&(1<<ADSC))" loop, +0.4375 = 5.0000 */ \ wdt_reset(); /* 5.0625 us */ \ wdt_reset() /* 5.1250 us */ #endif #endif //================================================================= uint16_t GetESR(uint8_t hipin, uint8_t lopin) { #if FLASHEND > 0x1fff // measure the ESR value of capacitor unsigned int adcv[4]; // array for 4 ADC readings unsigned long sumvolt[4]; // array for 3 sums of ADC readings unsigned long cap_val_nF; uint16_t esrvalue; uint8_t HiPinR_L; // used to switch 680 Ohm to HighPin uint8_t HiADC; // used to switch Highpin directly to GND or VCC uint8_t LoPinR_L; // used to switch 680 Ohm to LowPin uint8_t LoADC; // used to switch Lowpin directly to GND or VCC uint8_t ii,jj; // tempory values uint8_t StartADCmsk; // Bit mask to start the ADC uint8_t SelectLowPin,SelectHighPin; uint8_t big_cap; int8_t esr0; // used for ESR zero correction big_cap = 1; if (PartFound == PART_CAPACITOR) { ii = cap.cpre_max; cap_val_nF = cap.cval_max; while (ii < -9) { // set cval to nF unit cap_val_nF /= 10; // reduce value by factor ten ii++; // take next decimal prefix } if (cap_val_nF < (1800/18)) return(0xffff); // capacity lower than 1.8 uF //if (cap_val_nF > (1800/18)) { // normal ADC-speed, ADC-Clock 8us #ifdef ADC_Sleep_Mode StartADCmsk = (1<<ADEN) | (1<<ADIF) | (1<<ADIE) | AUTO_CLOCK_DIV; // enable ADC and Interrupt ADCSRA = StartADCmsk; // enable ADC and Interrupt #else StartADCmsk = (1<<ADSC) | (1<<ADEN) | (1<<ADIF) | AUTO_CLOCK_DIV; // enable and start ADC #endif //} else { // fast ADC-speed, ADC-Clock 2us #ifdef ADC_Sleep_Mode //StartADCmsk = (1<<ADEN) | (1<<ADIF) | (1<<ADIE) | FAST_CLOCK_DIV; // enable ADC and Interrupt //ADCSRA = StartADCmsk; // enable ADC and Interrupt //SMCR = (1 << SM0) | (1 <<SE); // set ADC Noise Reduction and Sleep Enable #else //StartADCmsk = (1<<ADSC) | (1<<ADEN) | (1<<ADIF) | FAST_CLOCK_DIV; // enable and start ADC #endif //big_cap = 0; //} } LoADC = pgm_read_byte(&PinADCtab[lopin]) | TXD_MSK; HiADC = pgm_read_byte(&PinADCtab[hipin]) | TXD_MSK; LoPinR_L = pgm_read_byte(&PinRLtab[lopin]); // R_L mask for LowPin R_L load HiPinR_L = pgm_read_byte(&PinRLtab[hipin]); // R_L mask for HighPin R_L load #if PROCESSOR_TYP == 1280 // ATmega640/1280/2560 1.1V Reference with REFS0=0 SelectLowPin = (lopin | (1<<REFS1) | (0<<REFS0)); // switch ADC to LowPin, Internal Ref. SelectHighPin = (hipin | (1<<REFS1) | (0<<REFS0)); // switch ADC to HighPin, Internal Ref. #else SelectLowPin = (lopin | (1<<REFS1) | (1<<REFS0)); // switch ADC to LowPin, Internal Ref. SelectHighPin = (hipin | (1<<REFS1) | (1<<REFS0)); // switch ADC to HighPin, Internal Ref. #endif // Measurement of ESR of capacitors AC Mode sumvolt[0] = 1; // set sum of LowPin voltage to 1 to prevent divide by zero sumvolt[2] = 1; // clear sum of HighPin voltage with current // offset is about (x*10*200)/34000 in 0.01 Ohm units sumvolt[1] = 0; // clear sum of HighPin voltage without current sumvolt[3] = 0; // clear sum of HighPin voltage without current EntladePins(); // discharge capacitor ADC_PORT = TXD_VAL; // switch ADC-Port to GND ADMUX = SelectLowPin; // set Mux input and Voltage Reference to internal 1.1V #ifdef NO_AREF_CAP wait100us(); // time for voltage stabilization #else wait_about10ms(); // time for voltage stabilization with 100nF #endif // start voltage must be negativ ADC_DDR = HiADC; // switch High Pin to GND R_PORT = LoPinR_L; // switch R-Port to VCC R_DDR = LoPinR_L; // switch R_L port for HighPin to output (VCC) wait10us(); wait2us(); R_DDR = 0; // switch off current R_PORT = 0; StartADCwait(); // set ADCSRA Interrupt Mode, sleep // Measurement frequency is given by sum of ADC-Reads < 680 Hz for normal ADC speed. // For fast ADC mode the frequency is below 2720 Hz (used for capacity value below 3.6 uF). // ADC Sample and Hold (SH) is done 1.5 ADC clock number after real start of conversion. // Real ADC-conversion is started with the next ADC-Clock (125kHz) after setting the ADSC bit. for(ii=0;ii<MAX_CNT;ii++) { ADC_DDR = LoADC; // switch Low-Pin to output (GND) R_PORT = LoPinR_L; // switch R-Port to VCC R_DDR = LoPinR_L; // switch R_L port for LowPin to output (VCC) ADMUX = SelectLowPin; StartADCwait(); // set ADCSRA Interrupt Mode, sleep StartADCwait(); // set ADCSRA Interrupt Mode, sleep adcv[0] = ADCW; // Voltage LowPin with current ADMUX = SelectHighPin; //if (big_cap != 0) { StartADCwait(); // ADCSRA = (1<<ADEN) | (1<<ADIF) | (1<<ADIE) | AUTO_CLOCK_DIV; ADCSRA = (1<<ADSC) | (1<<ADEN) | (1<<ADIF) | AUTO_CLOCK_DIV; // enable ADC and start with ADSC wait4us(); R_PORT = HiPinR_L; // switch R-Port to VCC R_DDR = HiPinR_L; // switch R_L port for HighPin to output (VCC) DelayBigCap(); // wait predefined time //} else { // StartADCwait(); // ADCSRA = (1<<ADEN) | (1<<ADIF) | (1<<ADIE) | AUTO_CLOCK_DIV; // R_PORT = HiPinR_L; // switch R-Port to VCC // R_DDR = HiPinR_L; // switch R_L port for HighPin to output (VCC) // ADCSRA = (1<<ADSC) | (1<<ADEN) | (1<<ADIF) | FAST_CLOCK_DIV; // enable ADC and start with ADSC // // SH at 2.5 ADC clocks behind start = 5 us // DelaySmallCap(); // wait predefined time //} R_DDR = 0; // switch current off, SH is 1.5 ADC clock behind real start R_PORT = 0; while (ADCSRA&(1<<ADSC)); // wait for conversion finished adcv[1] = ADCW; // Voltage HighPin with current #ifdef ADC_Sleep_Mode ADCSRA = StartADCmsk; // enable ADC and Interrupt #endif wdt_reset(); // ******** Reverse direction, connect High side with GND ******** ADC_DDR = HiADC; // switch High Pin to GND R_PORT = HiPinR_L; // switch R-Port to VCC R_DDR = HiPinR_L; // switch R_L port for HighPin to output (VCC) wdt_reset(); ADMUX = SelectHighPin; StartADCwait(); // set ADCSRA Interrupt Mode, sleep StartADCwait(); // set ADCSRA Interrupt Mode, sleep adcv[2] = ADCW; // Voltage HighPin with current ADMUX = SelectLowPin; //if (big_cap != 0) { StartADCwait(); // set ADCSRA Interrupt Mode, sleep ADCSRA = (1<<ADSC) | (1<<ADEN) | (1<<ADIF) | AUTO_CLOCK_DIV; // enable ADC and start with ADSC wait4us(); R_PORT = LoPinR_L; R_DDR = LoPinR_L; // switch LowPin with 680 Ohm to VCC DelayBigCap(); // wait predefined time //} else { // StartADCwait(); // set ADCSRA Interrupt Mode, sleep // R_PORT = LoPinR_L; // R_DDR = LoPinR_L; // switch LowPin with 680 Ohm to VCC // ADCSRA = (1<<ADSC) | (1<<ADEN) | (1<<ADIF) | FAST_CLOCK_DIV; // enable ADC and start with ADSC // // 2.5 ADC clocks = 5 us // DelaySmallCap(); // wait predefined time //} R_DDR = 0; // switch current off R_PORT = 0; while (ADCSRA&(1<<ADSC)); // wait for conversion finished adcv[3] = ADCW; // Voltage LowPin with current #ifdef ADC_Sleep_Mode ADCSRA = StartADCmsk; // enable ADC and Interrupt #endif sumvolt[0] += adcv[0]; // add sum of both LowPin voltages with current sumvolt[1] += adcv[1]; // add HighPin voltages with current sumvolt[2] += adcv[2]; // add LowPin voltages with current sumvolt[3] += adcv[3]; // add HighPin voltages with current } // end for sumvolt[0] += sumvolt[2]; #ifdef ESR_DEBUG lcd_testpin(hipin); lcd_testpin(lopin); lcd_data(' '); DisplayValue(sumvolt[0],0,'L',4); // LowPin 1 lcd_line3(); DisplayValue(sumvolt[1],0,'h',4); // HighPin 1 lcd_data(' '); DisplayValue(sumvolt[3],0,'H',4); // LowPin 2 lcd_line4(); #endif if ((sumvolt[1] + sumvolt[3]) > sumvolt[0]) { sumvolt[2] = (sumvolt[1] + sumvolt[3]) - sumvolt[0]; // difference HighPin - LowPin Voltage with current } else { sumvolt[2] = 0; } if (PartFound == PART_CAPACITOR) { sumvolt[2] -= (1745098UL*MAX_CNT) / (cap_val_nF * (cap_val_nF + 19)); } #ifdef ESR_DEBUG DisplayValue(sumvolt[2],0,'d',4); // HighPin - LowPin lcd_data(' '); #endif esrvalue = (sumvolt[2] * 10 * (unsigned long)RRpinMI) / (sumvolt[0]+sumvolt[2]); esrvalue += esrvalue / 14; // esrvalue + 7% esr0 = (int8_t)pgm_read_byte(&EE_ESR_ZEROtab[hipin+lopin]); if (esrvalue > esr0) { esrvalue -= esr0; } else { esrvalue = 0; } #ifdef ADC_Sleep_Mode SMCR = (0 << SM0) | (0 << SE); // clear ADC Noise Reduction and Sleep Enable #endif return (esrvalue); #else return (0); #endif } void us500delay(unsigned int us) // = delayMicroseconds(us) + 500ns { #if F_CPU >= 20000000L __asm__ __volatile__ ( "nop" "\n\t" "nop"); // just waiting 2 cycles if (--us == 0) return; us = (us<<2) + us; // x5 us #elif F_CPU >= 16000000L if (--us == 0) return; us <<= 2; #else if (--us == 0) return; if (--us == 0) return; us <<= 1; #endif __asm__ __volatile__ ( "1: sbiw %0,1" "\n\t" // 2 cycles "brne 1b" : "=w" (us) : "0" (us) // 2 cycles ); } /* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */ // new code by K.-H. Kubbeler // ca = Pin number (0-2) of the LowPin // cb = Pin number (0-2) of the HighPin //================================================================= void GetVloss() { #if FLASHEND > 0x1fff // measure voltage drop after load pulse unsigned int tmpint; unsigned int adcv[4]; union t_combi{ unsigned long dw; // capacity value in 100nF units uint16_t w[2]; } lval; uint8_t ii; uint8_t HiPinR_L; uint8_t LoADC; if (cap.v_loss > 0) return; // Voltage loss is already known LoADC = pgm_read_byte(&PinADCtab[cap.ca]) | TXD_MSK; HiPinR_L = pgm_read_byte(&PinRLtab[cap.cb]); // R_L mask for HighPin R_L load EntladePins(); // discharge capacitor ADC_PORT = TXD_VAL; // switch ADC-Port to GND R_PORT = 0; // switch R-Port to GND ADC_DDR = LoADC; // switch Low-Pin to output (GND) R_DDR = HiPinR_L; // switch R_L port for HighPin to output (GND) adcv[0] = ReadADC(cap.cb); // voltage before any load // ******** should adcv[0] be measured without current??? if (cap.cpre_max > -9) return; // too much capacity lval.dw = cap.cval_max; //for (ii=cap.cpre_max+12;ii<5;ii++) { for (ii=cap.cpre_max+12;ii<4;ii++) { lval.dw = (lval.dw + 5) / 10; } //if ((lval.dw == 0) || (lval.dw > 500)) { if ((lval.dw == 0) || (lval.dw > 5000)) { // capacity more than 50uF, Voltage loss is already measured return; } R_PORT = HiPinR_L; // R_L to 1 (VCC) R_DDR = HiPinR_L; // switch Pin to output, across R to GND or VCC for (tmpint=0; tmpint<lval.w[0]; tmpint+=2) { //wait50us(); // wait exactly 50us wait5us(); // wait exactly 5us } R_DDR = 0; // switch back to input R_PORT = 0; // no Pull up //wait10us(); // wait a little time wdt_reset(); // read voltage without current ADCconfig.Samples = 5; // set ADC to only 5 samples adcv[2] = ReadADC(cap.cb); if (adcv[2] > adcv[0]) { adcv[2] -= adcv[0]; // difference to beginning voltage } else { adcv[2] = 0; // voltage is lower or same as beginning voltage } // wait 2x the time which was required for loading for (tmpint=0; tmpint<lval.w[0]; tmpint++) { //wait50us(); wait5us(); } adcv[3] = ReadADC(cap.cb); // read voltage again, is discharged only a little bit ? ADCconfig.Samples = ANZ_MESS; // set ADC back to configured No. of samples wdt_reset(); if (adcv[3] > adcv[0]) { adcv[3] -= adcv[0]; // difference to beginning voltage } else { adcv[3] = 0; // voltage is lower or same as beginning voltage } if (adcv[2] > adcv[3]) { // build difference to load voltage adcv[1] = adcv[2] - adcv[3]; // lost voltage during load time wait } else { adcv[1] = 0; // no lost voltage } // compute voltage drop as part from loaded voltage if (adcv[1] > 0) { // there is any voltage drop (adcv[1]) ! // adcv[2] is the loaded voltage. cap.v_loss = (unsigned long)(adcv[1] * 500UL) / adcv[2]; } #if 0 lcd_line3(); DisplayValue(adcv[2],0,' ',4); DisplayValue(adcv[1],0,' ',4); lcd_line4(); DisplayValue(lval.w[0],0,'x',4); #endif // discharge capacitor again EntladePins(); // discharge capacitors // ready // switch all ports to input ADC_DDR = TXD_MSK; // switch all ADC ports to input ADC_PORT = TXD_VAL; // switch all ADC outputs to GND, no pull up R_DDR = 0; // switch all resistor ports to input R_PORT = 0; // switch all resistor outputs to GND, no pull up #endif return; } // end GetVloss() /* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */ void Calibrate_UR(void) { // get reference voltage, calibrate VCC with external 2.5V and // get the port output resistance #ifdef AUTO_CAL uint16_t sum_rm; // sum of 3 Pin voltages with 680 Ohm load uint16_t sum_rp; // sum of 3 Pin voltages with 680 Ohm load uint16_t u680; // 3 * (Voltage at 680 Ohm) #endif //-------------------------------------------- ADCconfig.U_AVCC = U_VCC; // set initial VCC Voltage ADCconfig.Samples = 190; // set number of ADC reads near to maximum #if FLASHEND > 0x1fff ADC_PORT = TXD_VAL; // switch to 0V ADC_DDR = (1<<TPREF) | TXD_MSK; // switch pin with 2.5V reference to GND wait1ms(); ADC_DDR = TXD_MSK; // switch pin with reference back to input trans.uBE[1] = W5msReadADC(TPREF); // read voltage of 2.5V precision reference if ((trans.uBE[1] > 2250) && (trans.uBE[1] < 2750)) { // precision voltage reference connected, update U_AVCC WithReference = 1; ADCconfig.U_AVCC = (unsigned long)((unsigned long)ADCconfig.U_AVCC * 2495) / trans.uBE[1]; } #endif #ifdef WITH_AUTO_REF (void) ReadADC(MUX_INT_REF); // read reference voltage ref_mv = W5msReadADC(MUX_INT_REF); // read reference voltage RefVoltage(); // compute RHmultip = f(reference voltage) #else ref_mv = DEFAULT_BAND_GAP; // set to default Reference Voltage #endif ADCconfig.U_Bandgap = ADC_internal_reference; // set internal reference voltage for ADC //-------------------------------------------- #ifdef AUTO_CAL // measurement of internal resistance of the ADC port outputs switched to GND ADC_DDR = 1<<TP1 | TXD_MSK; // ADC-Pin 1 to output 0V R_PORT = 1<<(TP1*2); // R_L-PORT 1 to VCC R_DDR = 1<<(TP1*2); // Pin 1 to output and over R_L to VCC sum_rm = W5msReadADC(TP1); ADC_DDR = 1<<TP2 | TXD_MSK; // ADC-Pin 2 to output 0V R_PORT = 1<<(TP2*2); // R_L-PORT 2 to VCC R_DDR = 1<<(TP2*2); // Pin 2 to output and over R_L to VCC sum_rm += W5msReadADC(TP2); ADC_DDR = 1<<TP3 | TXD_MSK; // ADC-Pin 3 to output 0V R_PORT = 1<<(TP3*2); // R_L-PORT 3 to VCC R_DDR = 1<<(TP3*2); // Pin 3 to output and over R_L to VCC sum_rm += W5msReadADC(TP3); // add all three values // measurement of internal resistance of the ADC port output switched to VCC R_PORT = 0; // R-Ports to GND ADC_PORT = 1<<TP1 | TXD_VAL; // ADC-Port 1 to VCC ADC_DDR = 1<<TP1 | TXD_MSK; // ADC-Pin 1 to output 0V R_DDR = 1<<(TP1*2); // Pin 1 to output and over R_L to GND sum_rp = ADCconfig.U_AVCC - W5msReadADC(TP1); ADC_PORT = 1<<TP2 | TXD_VAL; // ADC-Port 2 to VCC ADC_DDR = 1<<TP2 | TXD_MSK; // ADC-Pin 2 to output 0V R_DDR = 1<<(TP2*2); // Pin 2 to output and over R_L to GND sum_rp += ADCconfig.U_AVCC - W5msReadADC(TP2); ADC_PORT = 1<<TP3 | TXD_VAL; // ADC-Port 3 to VCC ADC_DDR = 1<<TP3 | TXD_MSK; // ADC-Pin 3 to output 0V R_DDR = 1<<(TP3*2); // Pin 3 to output and over R_L to GND sum_rp += ADCconfig.U_AVCC - W5msReadADC(TP3); u680 = ((ADCconfig.U_AVCC * 3) - sum_rm - sum_rp); // three times the voltage at the 680 Ohm pin_rmi = (unsigned long)((unsigned long)sum_rm * (unsigned long)R_L_VAL) / (unsigned long)u680; //adcmv[2] = pin_rm; // for last output in row 2 pin_rpl = (unsigned long)((unsigned long)sum_rp * (unsigned long)R_L_VAL) / (unsigned long)u680; resis680pl = pin_rpl + R_L_VAL; resis680mi = pin_rmi + R_L_VAL; #endif ADCconfig.Samples = ANZ_MESS; // set to configured number of ADC samples } /* -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- */ // Interfacing a HD44780 compatible LCD with 4-Bit-Interface mode #ifdef STRIP_GRID_BOARD #warning "strip-grid-board layout selected!" #endif void lcd_set_cursor(uint8_t row, uint8_t col) { int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; if ( row >= 2 ) { row = 1; } lcd_command(CMD_SetDDRAMAddress | (col + row_offsets[row])); uart_newline(); } void lcd_string(char *data) { while(*data) { lcd_data(*data); data++; } } void lcd_pgm_string(const unsigned char *data) { unsigned char cc; while(1) { cc = pgm_read_byte(data); if((cc == 0) || (cc == 128)) return; lcd_data(cc); data++; } } void lcd_pgm_custom_char(uint8_t location, const unsigned char *chardata) { location &= 0x7; lcd_command(CMD_SetCGRAMAddress | (location << 3)); for(uint8_t i=0;i<8;i++) { lcd.write(pgm_read_byte(chardata)); chardata++; } } // sends numeric character (Pin Number) to the LCD // from binary 0 we send ASCII 1 void lcd_testpin(unsigned char temp) { lcd_data(temp + '1'); } // send space character to LCD void lcd_space(void) { lcd_data(' '); } void lcd_fix_string(const unsigned char *data) { unsigned char cc; while(1) { cc = MEM_read_byte(data); if((cc == 0) || (cc == 128)) return; lcd_data(cc); data++; } } // sends data byte to the LCD void lcd_data(unsigned char temp1) { lcd.write(temp1); switch(temp1) { case LCD_CHAR_DIODE1: { uart_putc('>'); uart_putc('|'); break; } case LCD_CHAR_DIODE2: { uart_putc('|'); uart_putc('<'); break; } case LCD_CHAR_CAP: { uart_putc('|'); uart_putc('|'); break; } case LCD_CHAR_RESIS1: case LCD_CHAR_RESIS2: { uart_putc('R'); break; } case LCD_CHAR_U: { // micro uart_putc('u'); // ASCII u break; } case LCD_CHAR_OMEGA: { // Omega uart_putc('o'); // "ohm" uart_putc('h'); uart_putc('m'); break; } default: { uart_putc(temp1); } } } void lcd_clear(void) { lcd.clear(); uart_newline(); } void uart_putc(uint8_t data) { Serial.write(data); delay(2); } |
You can download from here:https://drive.google.com/file/d/1z2j9Zr7CijGt0VChcBTT3DBR4hKjEBeh/view?usp=sharing