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

Dependencies:   mbed ntc

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001  #include "mbed.h"
00002  #include "ntc.h" 
00003  
00004  #define NTC_VREF        3.3f
00005   #define NTC_AD_RESOL    65536.0f
00006  
00007  // Connections:
00008  
00009  //      3.3V (or other Vref)
00010  //     --+--
00011  //       |
00012  //      -+-
00013  //     |   |
00014  //     |   |
00015  //     |   | Series
00016  //     |   | Resistor
00017  //     |   |
00018  //      -+-
00019  //       |
00020  //       +---> To A:D
00021  //       |
00022  //      -+-
00023  //     |   |
00024  //     |   |
00025  //     |   | NTC
00026  //     |   | 
00027  //     |   |
00028  //      -+-
00029  //       |
00030  //     --+--
00031  //      ---  Ground
00032  //       -
00033  
00034  
00035  const NTC_TypeDef ntc_my_paramtr = {
00036    // Vref
00037    NTC_VREF,           // Vref
00038    NTC_AD_RESOL,       // A:D 16-bit resolution
00039    // muRata NCP15XH103J03RC
00040    10000,              // NTC resistance
00041    5,                  // NTC initial tolerance
00042    0,                  // NTC B0/50 (none)
00043    3380,               // NTC B25/50
00044    3428,               // NTC B25/80
00045    3434,               // NTC B25/85
00046    3355,               // NTC B25/100
00047    0,                  // NTC other beta (none)
00048    1,                  // NTC beta tolerance
00049    // 3.32k 1% 100ppm
00050    3320,               // Series resistor value
00051    1,                  // Series resistor tolerance
00052    100                 // Series Resistor tempco ppm
00053  };    
00054  
00055  NTC ntc(A1, &ntc_my_paramtr);                   //initialize NTC temperature A:D
00056  
00057  main() {
00058      printf("\r\n\r\n-------------------------------------------\r\n");
00059      printf("NTC Res: %5d   B0/50: %4d   B25/50: %4d   B25/80: %4d   B25/85: %4d   B25/100: %4d   B_OTHER: %4d   SeriesR: %d\r\n", 
00060                  ntc.get_ntc_res(), ntc.get_ntc_beta(NTC::B0_50 ), ntc.get_ntc_beta(NTC::B25_50 ), ntc.get_ntc_beta(NTC::B25_80 ), ntc.get_ntc_beta(NTC::B25_85 ), 
00061                  ntc.get_ntc_beta(NTC::B25_100 ), ntc.get_ntc_beta(NTC::B_OTHER ),  ntc.get_series_res());
00062      uint16_t ad = ntc.read_ad_reg();
00063      printf("NTC A:D Val: %5d   Volt A:D: %.6f   NTC-R_now: %7.1f    Temp: %+.2f\r\n", ad, 
00064              NTC_VREF / NTC_AD_RESOL * (float)ad, ntc.get_ntc_res_viaAD(ad), ntc.get_ntc_temp(NTC::B25_85 , ad));
00065  
00066      while(1) {
00067          printf("Temp: %+.2f\r\n", ntc.get_ntc_temp(NTC::B25_85 ));
00068          wait(2.0);
00069      }
00070          
00071  }