Simple program for temperature sensing using a NTC temperature sense resistor and internal mbed A:D converter

Dependencies:   mbed ntc

Revision:
0:4d7ee19a6aef
Child:
1:ccb26174e7da
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Apr 08 01:33:44 2017 +0000
@@ -0,0 +1,70 @@
+#include "mbed.h"
+#include "ntc.h"
+
+#define NTC_VREF        3.3f
+#define NTC_AD_RESOL    65536.0f
+
+// Connections:
+
+//      3.3V (or other Vref)
+//     --+--
+//       |
+//      -+-
+//     |   |
+//     |   |
+//     |   | Series
+//     |   | Resistor
+//     |   |
+//      -+-
+//       |
+//       +---> To A:D
+//       |
+//      -+-
+//     |   |
+//     |   |
+//     |   | NTC
+//     |   |
+//     |   |
+//      -+-
+//       |
+//     --+--
+//      ---  Ground
+//       -
+
+
+const NTC_TypeDef ntc_my_paramtr = {
+    // Vref
+    NTC_VREF,           // Vref
+    NTC_AD_RESOL,       // A:D 16-bit resolution
+    // muRata NCP15XH103J03RC
+    10000,              // NTC resistance
+    5,                  // NTC initial tolerance
+    3380,               // NTC B25/50
+    3428,               // NTC B25/80
+    3434,               // NTC B25/85
+    3355,               // NTC B25/100
+    1,                  // NTC beta tolerance
+    // 3.32k 1% 100ppm
+    3320,               // Series resistor value
+    1,                  // Series resistor tolerance
+    100                 // Series Resistor tempco ppm
+};
+
+NTC ntc(A1, &ntc_my_paramtr);                   //initialize NTC temperature A:D
+
+main()
+{
+    printf("\r\n\r\n-------------------------------------------\r\n");
+    printf("NTC Res: %5d   B25/50: %4d   B25/80: %4d   B25/85: %4d   B25/100: %4d   SeriesR: %d\r\n",
+           ntc.get_ntc_res(), ntc.get_ntc_beta_2550(), ntc.get_ntc_beta_2580(), ntc.get_ntc_beta_2585(), ntc.get_ntc_beta_25100(),
+           ntc.get_series_res());
+    uint16_t ad = ntc.read_ad_reg();
+    printf("NTC A:D Val: %5d   Volt A:D: %.6f   NTC-R_now: %7.1f    Temp: %+.2f\r\n", ad,
+           NTC_VREF / NTC_AD_RESOL * (float)ad, ntc.get_ntc_res_viaAD(ad), ntc.get_ntc_temp(NTC::B25_85 , ad));
+
+    while(1) {
+        printf("Temp: %+.2f\r\n", ntc.get_ntc_temp(NTC::B25_85 ));
+        wait(2.0);
+    }
+
+}
\ No newline at end of file