Umair Aftab
/
Analog_Temp_2
Analog read for TM36 Temperature sensors.
main.cpp@0:ab91d2a9a3bd, 2014-03-07 (annotated)
- Committer:
- umairaftab
- Date:
- Fri Mar 07 04:18:43 2014 +0000
- Revision:
- 0:ab91d2a9a3bd
Working ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
umairaftab | 0:ab91d2a9a3bd | 1 | #include "mbed.h" |
umairaftab | 0:ab91d2a9a3bd | 2 | |
umairaftab | 0:ab91d2a9a3bd | 3 | //Print temperature from LM61 analog temperature sensor |
umairaftab | 0:ab91d2a9a3bd | 4 | |
umairaftab | 0:ab91d2a9a3bd | 5 | //set p15 to analog input to read LM61 sensor's voltage output |
umairaftab | 0:ab91d2a9a3bd | 6 | AnalogIn LM61(PTB0); |
umairaftab | 0:ab91d2a9a3bd | 7 | |
umairaftab | 0:ab91d2a9a3bd | 8 | //also setting unused analog input pins to digital outputs reduces A/D noise a bit |
umairaftab | 0:ab91d2a9a3bd | 9 | //see http://mbed.org/users/chris/notebook/Getting-best-ADC-performance/ |
umairaftab | 0:ab91d2a9a3bd | 10 | DigitalOut P16(PTB1); |
umairaftab | 0:ab91d2a9a3bd | 11 | DigitalOut P17(PTB2); |
umairaftab | 0:ab91d2a9a3bd | 12 | DigitalOut P18(PTB3); |
umairaftab | 0:ab91d2a9a3bd | 13 | DigitalOut P19(PTC0); |
umairaftab | 0:ab91d2a9a3bd | 14 | //DigitalOut P20(p20); |
umairaftab | 0:ab91d2a9a3bd | 15 | |
umairaftab | 0:ab91d2a9a3bd | 16 | int main() |
umairaftab | 0:ab91d2a9a3bd | 17 | { |
umairaftab | 0:ab91d2a9a3bd | 18 | float tempC, tempF; |
umairaftab | 0:ab91d2a9a3bd | 19 | float val; |
umairaftab | 0:ab91d2a9a3bd | 20 | |
umairaftab | 0:ab91d2a9a3bd | 21 | while(1) { |
umairaftab | 0:ab91d2a9a3bd | 22 | //conversion to degrees C - from sensor output voltage per LM61 data sheet |
umairaftab | 0:ab91d2a9a3bd | 23 | tempC = ((LM61*3.3)-0.500)*100.0; |
umairaftab | 0:ab91d2a9a3bd | 24 | val = |
umairaftab | 0:ab91d2a9a3bd | 25 | //convert to degrees F |
umairaftab | 0:ab91d2a9a3bd | 26 | tempF = (9.0*tempC)/5.0 + 32.0; |
umairaftab | 0:ab91d2a9a3bd | 27 | //print current temp |
umairaftab | 0:ab91d2a9a3bd | 28 | printf("%5.2F C %5.2F F \n\r", tempC, tempF); |
umairaftab | 0:ab91d2a9a3bd | 29 | wait(.5); |
umairaftab | 0:ab91d2a9a3bd | 30 | } |
umairaftab | 0:ab91d2a9a3bd | 31 | } |