zinnet yazıcı
/
BMA220
j
thermistor/thermistor.cpp@1:dc9389ccc09d, 2019-09-11 (annotated)
- Committer:
- zinnetyazicii53
- Date:
- Wed Sep 11 12:15:15 2019 +0000
- Revision:
- 1:dc9389ccc09d
commit to pass repo another account
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zinnetyazicii53 | 1:dc9389ccc09d | 1 | #include "mbed.h" |
zinnetyazicii53 | 1:dc9389ccc09d | 2 | #include "thermistor.h" |
zinnetyazicii53 | 1:dc9389ccc09d | 3 | |
zinnetyazicii53 | 1:dc9389ccc09d | 4 | Thermistor::Thermistor(AnalogIn *aIn) |
zinnetyazicii53 | 1:dc9389ccc09d | 5 | { |
zinnetyazicii53 | 1:dc9389ccc09d | 6 | _aIn = aIn; |
zinnetyazicii53 | 1:dc9389ccc09d | 7 | } |
zinnetyazicii53 | 1:dc9389ccc09d | 8 | |
zinnetyazicii53 | 1:dc9389ccc09d | 9 | double Thermistor::getTemperature() |
zinnetyazicii53 | 1:dc9389ccc09d | 10 | { |
zinnetyazicii53 | 1:dc9389ccc09d | 11 | this->getResistance(); |
zinnetyazicii53 | 1:dc9389ccc09d | 12 | if(this->_resistance > RES_25C){ |
zinnetyazicii53 | 1:dc9389ccc09d | 13 | this->_temperature = (25.0 - ((this->_resistance - RES_25C) / RES_DIFF_PER_C)); |
zinnetyazicii53 | 1:dc9389ccc09d | 14 | } else if(this->_resistance < RES_25C){ |
zinnetyazicii53 | 1:dc9389ccc09d | 15 | this->_temperature = (25.0 + ((RES_25C - this->_resistance) / RES_DIFF_PER_C)); |
zinnetyazicii53 | 1:dc9389ccc09d | 16 | } else { |
zinnetyazicii53 | 1:dc9389ccc09d | 17 | this->_temperature = 25.0; |
zinnetyazicii53 | 1:dc9389ccc09d | 18 | } |
zinnetyazicii53 | 1:dc9389ccc09d | 19 | printf("resistance : %f\n", _resistance); |
zinnetyazicii53 | 1:dc9389ccc09d | 20 | return this->_temperature; |
zinnetyazicii53 | 1:dc9389ccc09d | 21 | } |
zinnetyazicii53 | 1:dc9389ccc09d | 22 | |
zinnetyazicii53 | 1:dc9389ccc09d | 23 | void Thermistor::getResistance() |
zinnetyazicii53 | 1:dc9389ccc09d | 24 | { |
zinnetyazicii53 | 1:dc9389ccc09d | 25 | double sum = 0.0; |
zinnetyazicii53 | 1:dc9389ccc09d | 26 | uint16_t adc_data[SAMPLE_COUNT], average; |
zinnetyazicii53 | 1:dc9389ccc09d | 27 | int i = 0; |
zinnetyazicii53 | 1:dc9389ccc09d | 28 | while(i < SAMPLE_COUNT) { |
zinnetyazicii53 | 1:dc9389ccc09d | 29 | adc_data[i] = ((_aIn->read_u16() >> 4) & 0x0FFF); |
zinnetyazicii53 | 1:dc9389ccc09d | 30 | sum += adc_data[i++]; |
zinnetyazicii53 | 1:dc9389ccc09d | 31 | } |
zinnetyazicii53 | 1:dc9389ccc09d | 32 | average = sum / SAMPLE_COUNT; |
zinnetyazicii53 | 1:dc9389ccc09d | 33 | this->_resistance = (((BALANCE_RES_S * 0x0FFF) / average)) - BALANCE_RES_S; |
zinnetyazicii53 | 1:dc9389ccc09d | 34 | } |