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
ntc.h
- Committer:
- loopsva
- Date:
- 2017-04-07
- Revision:
- 1:2314fd8959b2
- Parent:
- 0:c0bdc272d5da
- Child:
- 2:c843c06cc651
File content as of revision 1:2314fd8959b2:
/* * mbed library for NTC analog pin that translates an A:D input * voltage to a temperature value * topology: Vref -> SeriesRes -> A:D -> NTC -> GND */ #ifndef MBED_NTC #define MBED_NTC /** * Private data structure for NTC data values. * **/ typedef struct { float vref; /*!< Referense voltage*/ float ad_resolution; /*!< A:D resolution*/ int ntc_res; /*!< NTC resistance value at 25C*/ int ntc_tol; /*!< NTC initial tolerance %*/ int ntc_beta_2550; /*!< NTC Beta, B25/50*/ int ntc_beta_2580; /*!< NTC Beta, B25/80*/ int ntc_beta_2585; /*!< NTC Beta, B25/85*/ int ntc_beta_25100; /*!< NTC Beta, B25/100*/ int ntc_beta_tol; /*!< NTC Beta tolerance %*/ int sres_res; /*!< Series resistor value*/ int sres_tol; /*!< Series resistor tolerance %*/ int sres_ppm; /*!< Series resistor tempco in ppm*/ } NTC_TypeDef; /** * Default values for data structure above * **/ const NTC_TypeDef ntc_std_paramtr = { // Vref 3.0f, // Vref 16384.0f, // A:D resolution // muRata NCP15XH103J03RC 20000, // NTC resistance 3, // NTC initial tolerance 3300, // NTC B25/50 3322, // NTC B25/80 3333, // NTC B25/85 3344, // NTC B25/100 2, // NTC beta tolerance // 3.32k 1% 100ppm 4750, // Series resistor value 5, // Series resistor tolerance 300 // Series Resistor tempco ppm }; /** NTC temperature A:D conversion * * @code * // * // * @endcode */ class NTC { public: /** * NTC Beta curves to choose from for Temperature calculations * **/ enum ntcBetaCurve { B25_50, /*!< use B25/50 curve */ B25_80, /*!< use B25/80 curve */ B25_85, /*!< use B25/85 curve */ B25_100, /*!< use B25/100 curve */ }; /** Configure gpio pin * @param A:D I/O pin * @param parameters for NTC (NTC_TypeDef) */ NTC(PinName p_ana, const NTC_TypeDef *ntc_parameter); /** Configure gpio pin * @param A:D I/O pin * uses default parameters */ NTC(PinName p_ana); /** Read A:D register value * @param none * @return A:D value from 0-65535 */ uint16_t read_ad_reg(); /** Get the NTC resistance value * @param none * @return resistance of NTC at 25C */ int get_ntc_res(); /** Get the NTC beta value B25/50 * @param none * @return beta */ int get_ntc_beta_2550(); /** Get the NTC beta value B25/80 * @param none * @return beta */ int get_ntc_beta_2580(); /** Get the NTC beta value B25/85 * @param none * @return beta */ int get_ntc_beta_2585(); /** Get the NTC beta value B25/100 * @param none * @return beta */ int get_ntc_beta_25100(); /** Get the resistance value for the series resistor * @param none * @return resistance of series resistor */ int get_series_res(); /** 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 rawdata is used. * @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 rawdata is used. * @return temperature of NTC */ float get_ntc_temp(int curve, uint16_t din = NULL); protected: AnalogIn _ana; private: NTC_TypeDef ntc_set_data; uint16_t rawdata; }; #endif // MBED_NTC