NTC temperature sensor going to A:D input. Topology is: (Vref or 3.3V) -> Series_resistor -> A:D_input -> NTC -> GND. Easy modification of NTC parameters w/o recompile of library
Diff: ntc.h
- Revision:
- 3:1eb4f5296281
- Parent:
- 2:c843c06cc651
- Child:
- 4:5d0dfa665cba
--- a/ntc.h Fri Apr 07 16:36:47 2017 +0000 +++ b/ntc.h Sat Apr 08 01:17:20 2017 +0000 @@ -1,7 +1,10 @@ /* * mbed library for NTC analog pin that translates an A:D input - * voltage to a temperature value + * voltage to a temperature value. + * + * * topology: Vref -> SeriesRes -> A:D -> NTC -> GND + * */ #ifndef MBED_NTC @@ -54,11 +57,41 @@ * #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 - * 3.3f, // Vref - * 65535.0f, // A:D 16-bit resolution + * NTC_VREF, // Vref + * NTC_AD_RES // A:D 16-bit resolution * // muRata NCP15XH103J03RC * 10000, // NTC resistance * 5, // NTC initial tolerance @@ -78,9 +111,11 @@ * 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()); + * 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, 3.3f / 65536.0f * (float)ad, ntc.get_ntc_res_viaAD(ad), ntc.get_ntc_temp(NTC::B25_85, ad)); + * 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)); @@ -162,17 +197,17 @@ /** calculate NTC resistance based on A:D reading * @param none * @param din optional read from read_ad_reg(). - * @param din if missing or 0, read_ad_reg() is executed first. - * @param din if != 0, then local value of din is used. + * @param din -> if missing or 0, read_ad_reg() value is used for calculation + * @param din -> if != 0, then value of din is used for calculation * @return resistance of NTC */ float get_ntc_res_viaAD(uint16_t din = NULL); /** calculate NTC temperaure * @param curve Beta curve to use. See ntcBetaCurve {}; - * @param din optional read from read_ad_reg(). - * @param din if missing or 0, read_ad_reg() is executed first. - * @param din if != 0, then local value of din is used. + * @param din optional read from read_ad_reg() + * @param din -> if missing or 0, read_ad_reg() value is used for calculation + * @param din -> if != 0, then value of din is used for calculation * @return temperature of NTC */ float get_ntc_temp(int curve, uint16_t din = NULL);