Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Ohmmeter_Code.cpp
- Revision:
- 2:6077294f7007
- Parent:
- 1:5aacfef29ca8
- Child:
- 3:b6e887e4ac75
--- a/Ohmmeter_Code.cpp Wed Apr 01 19:21:27 2020 +0000 +++ b/Ohmmeter_Code.cpp Wed Apr 01 19:45:59 2020 +0000 @@ -1,5 +1,10 @@ /* -hello +the code is set up to auto range for different known resistance value +it will base the case statement on its original Restimate value +the voltage drop across the transistor is different for each case +this value was found using simulations from LTspice +a value for Runkown will be printed on the screen and this will be in a +contunious loop from the switch */ //Case x: @@ -15,29 +20,29 @@ AnalogIn vo(A0); -double vout = (3.3 * vo)/ 4095; +double vout = (3.3 * vo)/ 4095; //converts analog read from bits to voltage double rest; double vt; -rest = (vout * 100) / (3.3 - vout); - +rest = (vout * 100) / (3.3 - vout); //rest is an estimate as it does not account for the voltage drop in transistor + //this essentially decides what pin we will use for final value switch (rest) { case 550: - vt = 0.0647875; + vt = 0.0647875; // vt is based off ltspice values from simulations runknown = (vout * 100) / (3.3 - vt - vout); if (runknown < 10){ - lcd.printf("Out of Range"); + lcd.printf("Out of Range"); //this will be out of the range of our design parameters } else{ - lcd.locate(0,1); - lcd.printf("%u Ω", runknown); + lcd.locate(0,1); + lcd.printf("%u Ω", runknown); // prints on the second row of the LCD screen } break; - case 5500: + case 5500: // this case is for if R is in a different range vt = 0.0189; 100ohm = 1; 1kohm = 0; @@ -45,10 +50,10 @@ runknown = (vout * 1000) / (3.3 - vt - vout); lcd.locate(0,1); if (runknown < 1000){ - lcd.printf("%u Ω", runknown); - } + lcd.printf("%u Ω", runknown); + } // this if correct runknown to the appropriate magnitude else { - runknown = runknown / 1000; + runknown = runknown / 1000; //runkown is now printed in KΩ lcd.printf("%.2f kΩ", runknown); break; @@ -77,7 +82,7 @@ lcd.printf("%.2f kΩ", runknown); } else { - runknown = runknown / 1000000; + runknown = runknown / 1000000; // this will change the magnitude to MΩ lcd.printf("%.2f MΩ", runknown); break; @@ -107,7 +112,7 @@ default: lcd.locate(0,1); - lcd.printf("Out of Range"); + lcd.printf("Out of Range"); // this will apear if runkown is outside the design parameters break; } \ No newline at end of file