BD1020HFV Temperature sensor test code
Dependencies: mbed
main.cpp@2:913fc12a42a7, 2016-09-21 (annotated)
- Committer:
- MikkoZ
- Date:
- Wed Sep 21 09:57:41 2016 +0000
- Revision:
- 2:913fc12a42a7
- Parent:
- 1:ba7e525074f9
Alternative temperature formula added.; ; - Added temperature formula; - Added comments about values used in both formulas; ; Tested on GR-Peach + Rohm tile shield + BD1020 on analog_2 connector
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MACRUM | 0:ee7b9cc966d7 | 1 | #include "mbed.h" |
MACRUM | 0:ee7b9cc966d7 | 2 | |
MACRUM | 0:ee7b9cc966d7 | 3 | Serial pc(USBTX, USBRX); |
MACRUM | 0:ee7b9cc966d7 | 4 | AnalogIn sensor(A2); |
MACRUM | 0:ee7b9cc966d7 | 5 | |
MACRUM | 0:ee7b9cc966d7 | 6 | int main() { |
MikkoZ | 2:913fc12a42a7 | 7 | float temperature1; |
MikkoZ | 2:913fc12a42a7 | 8 | float temperature2; |
MikkoZ | 2:913fc12a42a7 | 9 | pc.printf("\n\r"); |
MikkoZ | 2:913fc12a42a7 | 10 | pc.printf("BD1020HFV Temperature sensor test program.\n\r"); |
MikkoZ | 2:913fc12a42a7 | 11 | pc.printf("All values are approximates based on specification graph.\n\r"); |
MikkoZ | 2:913fc12a42a7 | 12 | pc.printf("Formula values should be calibrated before use.\n\r"); |
MACRUM | 0:ee7b9cc966d7 | 13 | while(1) { |
MikkoZ | 2:913fc12a42a7 | 14 | //Input voltage 0-3.3V == 0.0-1.0f |
MikkoZ | 2:913fc12a42a7 | 15 | //-40'C == 1.87V |
MikkoZ | 2:913fc12a42a7 | 16 | // 0'C == 1.546V |
MikkoZ | 2:913fc12a42a7 | 17 | //192'C == 0V (out of scale) |
MikkoZ | 2:913fc12a42a7 | 18 | //1.87V / 232'C = 0.008060V/'C |
MikkoZ | 2:913fc12a42a7 | 19 | |
MikkoZ | 2:913fc12a42a7 | 20 | temperature1 = -(1000 * (sensor * 3.3f) - 1546) / 8.2; |
MikkoZ | 2:913fc12a42a7 | 21 | temperature2 = 192 - ( sensor * 3.3f / 0.008060 ); |
MikkoZ | 2:913fc12a42a7 | 22 | pc.printf("Temperature, formula1=%5.3f, formula2=%5.3f\r\n", temperature1, temperature2); |
MikkoZ | 2:913fc12a42a7 | 23 | wait(1); |
MACRUM | 0:ee7b9cc966d7 | 24 | } |
MACRUM | 0:ee7b9cc966d7 | 25 | } |