![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
j
thermistor/thermistor.cpp
- Committer:
- zinnetyazicii53
- Date:
- 2019-09-11
- Revision:
- 1:dc9389ccc09d
File content as of revision 1:dc9389ccc09d:
#include "mbed.h" #include "thermistor.h" Thermistor::Thermistor(AnalogIn *aIn) { _aIn = aIn; } double Thermistor::getTemperature() { this->getResistance(); if(this->_resistance > RES_25C){ this->_temperature = (25.0 - ((this->_resistance - RES_25C) / RES_DIFF_PER_C)); } else if(this->_resistance < RES_25C){ this->_temperature = (25.0 + ((RES_25C - this->_resistance) / RES_DIFF_PER_C)); } else { this->_temperature = 25.0; } printf("resistance : %f\n", _resistance); return this->_temperature; } void Thermistor::getResistance() { double sum = 0.0; uint16_t adc_data[SAMPLE_COUNT], average; int i = 0; while(i < SAMPLE_COUNT) { adc_data[i] = ((_aIn->read_u16() >> 4) & 0x0FFF); sum += adc_data[i++]; } average = sum / SAMPLE_COUNT; this->_resistance = (((BALANCE_RES_S * 0x0FFF) / average)) - BALANCE_RES_S; }