/ Freq_Meter
Committer:
thomasosullivan
Date:
Wed Apr 01 19:21:27 2020 +0000
Revision:
1:5aacfef29ca8
Parent:
0:7f4ed364f7ea
Child:
2:6077294f7007
test;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
decland17 0:7f4ed364f7ea 1 /*
thomasosullivan 1:5aacfef29ca8 2 hello
decland17 0:7f4ed364f7ea 3 */
decland17 0:7f4ed364f7ea 4 //Case x:
decland17 0:7f4ed364f7ea 5
decland17 0:7f4ed364f7ea 6 lcd.locate(0,0);
decland17 0:7f4ed364f7ea 7 lcd.printf("Resistance: "); //display on top line
decland17 0:7f4ed364f7ea 8
decland17 0:7f4ed364f7ea 9 DigitalOut 100ohm(D6) = 0; //Transistor connected to 100ohm resistor set to short circuit
decland17 0:7f4ed364f7ea 10 DigitalOut 1kohm(D7) = 1; //All others set to open circuit
decland17 0:7f4ed364f7ea 11 DigitalOut 10kohm(D8) = 1;
decland17 0:7f4ed364f7ea 12 DigitalOut 100kohm(D9) = 1;
decland17 0:7f4ed364f7ea 13 DigitalOut 1Mohm(D10) = 1;
decland17 0:7f4ed364f7ea 14 DigitalOut 10Mohm(D11) = 1;
decland17 0:7f4ed364f7ea 15
decland17 0:7f4ed364f7ea 16 AnalogIn vo(A0);
decland17 0:7f4ed364f7ea 17
decland17 0:7f4ed364f7ea 18 double vout = (3.3 * vo)/ 4095;
decland17 0:7f4ed364f7ea 19
decland17 0:7f4ed364f7ea 20 double rest;
decland17 0:7f4ed364f7ea 21
decland17 0:7f4ed364f7ea 22 double vt;
decland17 0:7f4ed364f7ea 23
decland17 0:7f4ed364f7ea 24 rest = (vout * 100) / (3.3 - vout);
decland17 0:7f4ed364f7ea 25
decland17 0:7f4ed364f7ea 26 switch (rest)
decland17 0:7f4ed364f7ea 27 {
decland17 0:7f4ed364f7ea 28 case 550:
decland17 0:7f4ed364f7ea 29 vt = 0.0647875;
decland17 0:7f4ed364f7ea 30 runknown = (vout * 100) / (3.3 - vt - vout);
decland17 0:7f4ed364f7ea 31 if (runknown < 10){
decland17 0:7f4ed364f7ea 32 lcd.printf("Out of Range");
decland17 0:7f4ed364f7ea 33 }
decland17 0:7f4ed364f7ea 34 else{
decland17 0:7f4ed364f7ea 35 lcd.locate(0,1);
decland17 0:7f4ed364f7ea 36 lcd.printf("%u Ω", runknown);
decland17 0:7f4ed364f7ea 37 }
decland17 0:7f4ed364f7ea 38 break;
decland17 0:7f4ed364f7ea 39
decland17 0:7f4ed364f7ea 40 case 5500:
decland17 0:7f4ed364f7ea 41 vt = 0.0189;
decland17 0:7f4ed364f7ea 42 100ohm = 1;
decland17 0:7f4ed364f7ea 43 1kohm = 0;
decland17 0:7f4ed364f7ea 44 vout = (3.3 * vo)/ 4095;
decland17 0:7f4ed364f7ea 45 runknown = (vout * 1000) / (3.3 - vt - vout);
decland17 0:7f4ed364f7ea 46 lcd.locate(0,1);
decland17 0:7f4ed364f7ea 47 if (runknown < 1000){
decland17 0:7f4ed364f7ea 48 lcd.printf("%u Ω", runknown);
decland17 0:7f4ed364f7ea 49 }
decland17 0:7f4ed364f7ea 50 else {
decland17 0:7f4ed364f7ea 51 runknown = runknown / 1000;
decland17 0:7f4ed364f7ea 52 lcd.printf("%.2f kΩ", runknown);
decland17 0:7f4ed364f7ea 53 break;
decland17 0:7f4ed364f7ea 54
decland17 0:7f4ed364f7ea 55 case 55000:
decland17 0:7f4ed364f7ea 56 vt = 0.0075148;
decland17 0:7f4ed364f7ea 57 100ohm = 1;
decland17 0:7f4ed364f7ea 58 10kohm = 0;
decland17 0:7f4ed364f7ea 59 vout = (3.3 * vo)/ 4095;
decland17 0:7f4ed364f7ea 60 runknown = (vout * 10000) / (3.3 - vt - vout);
decland17 0:7f4ed364f7ea 61 lcd.locate(0,1);
decland17 0:7f4ed364f7ea 62 runknown = runknown / 1000;
decland17 0:7f4ed364f7ea 63 lcd.printf("%.2f kΩ", runknown);
decland17 0:7f4ed364f7ea 64 break;
decland17 0:7f4ed364f7ea 65
decland17 0:7f4ed364f7ea 66 case 550000:
decland17 0:7f4ed364f7ea 67 vt = 0.00612;
decland17 0:7f4ed364f7ea 68 100ohm = 1;
decland17 0:7f4ed364f7ea 69 100kohm = 0;
decland17 0:7f4ed364f7ea 70 vout = (3.3 * vo)/ 4095;
decland17 0:7f4ed364f7ea 71 runknown = (vout * 100000) / (3.3 - vt - vout);
decland17 0:7f4ed364f7ea 72
decland17 0:7f4ed364f7ea 73 lcd.locate(0,1);
decland17 0:7f4ed364f7ea 74
decland17 0:7f4ed364f7ea 75 if (runknown < 1000000){
decland17 0:7f4ed364f7ea 76 runknown = runknown / 1000;
decland17 0:7f4ed364f7ea 77 lcd.printf("%.2f kΩ", runknown);
decland17 0:7f4ed364f7ea 78 }
decland17 0:7f4ed364f7ea 79 else {
decland17 0:7f4ed364f7ea 80 runknown = runknown / 1000000;
decland17 0:7f4ed364f7ea 81 lcd.printf("%.2f MΩ", runknown);
decland17 0:7f4ed364f7ea 82 break;
decland17 0:7f4ed364f7ea 83
decland17 0:7f4ed364f7ea 84 case 5500000:
decland17 0:7f4ed364f7ea 85 vt = 0.0059684;
decland17 0:7f4ed364f7ea 86 100ohm = 1;
decland17 0:7f4ed364f7ea 87 1Mohm = 0;
decland17 0:7f4ed364f7ea 88 vout = (3.3 * vo)/ 4095;
decland17 0:7f4ed364f7ea 89 runknown = (vout * 1000000) / (3.3 - vt - vout);
decland17 0:7f4ed364f7ea 90
decland17 0:7f4ed364f7ea 91 lcd.locate(0,1);
decland17 0:7f4ed364f7ea 92 runknown = runknown / 1000000;
decland17 0:7f4ed364f7ea 93 lcd.printf("%.2f MΩ", runknown);
decland17 0:7f4ed364f7ea 94 break;
decland17 0:7f4ed364f7ea 95
decland17 0:7f4ed364f7ea 96 case 10000000:
decland17 0:7f4ed364f7ea 97 vt = 0.0059526;
decland17 0:7f4ed364f7ea 98 100ohm = 1;
decland17 0:7f4ed364f7ea 99 10Mohm = 0;
decland17 0:7f4ed364f7ea 100 vout = (3.3 * vo)/ 4095;
decland17 0:7f4ed364f7ea 101 runknown = (vout * 10000000) / (3.3 - vt - vout);
decland17 0:7f4ed364f7ea 102
decland17 0:7f4ed364f7ea 103 lcd.locate(0,1);
decland17 0:7f4ed364f7ea 104 runknown = runknown / 1000000;
decland17 0:7f4ed364f7ea 105 lcd.printf("%.2f MΩ", runknown);
decland17 0:7f4ed364f7ea 106 break;
decland17 0:7f4ed364f7ea 107
decland17 0:7f4ed364f7ea 108 default:
decland17 0:7f4ed364f7ea 109 lcd.locate(0,1);
decland17 0:7f4ed364f7ea 110 lcd.printf("Out of Range");
decland17 0:7f4ed364f7ea 111 break;
decland17 0:7f4ed364f7ea 112
decland17 0:7f4ed364f7ea 113 }