Added diode calibration

This commit is contained in:
David Lenfesty 2019-10-25 13:26:23 -06:00 committed by GitHub
parent 69e409a28d
commit 985484179b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -66,16 +66,16 @@ uint16_t adc_run_conversion(uint8_t adc_selection) {
/** @brief Converts an ADC value from a measurement on an LM35 into a temperature.
*/
int8_t lm35_convert(uint16_t adc_reading) {
return (float) (adc_reading * ADC_VREF / ADC_RESOLUTION) / LM35_SENSITIVITY;
return (adc_reading * ADC_VREF / ADC_RESOLUTION) / LM35_SENSITIVITY;
}
/** @brief Converts and ADC value from a measurement on a diode into a temperature.
* TODO
*/
int8_t diode_convert(uint16_t adc_reading) {
// Do some funky math here
return 0;
// This could be collapsed but it doesn't really matter
int16_t value_diff = adc_reading - DIODE_VALUE_25C;
int16_t temp_diff = value_diff / DIODE_SENSITIVITY;
return temp_diff + 25;
}
int main() {

View File

@ -13,8 +13,8 @@
#define ADC_VREF 1.1
#define ADC_RESOLUTION 1023 // (2^ 10 - 1, 10 bits resolution)
#define DIODE_VALUE_0C // ADC value for diode at 0C
#define DIODE_SENSITIVITY 0.0025 // V / degree C, tuneable
#define DIODE_VALUE_25C 436 // ADC value for diode at 0C
#define DIODE_SENSITIVITY -1.85 // ADC value / degree C, tuneable
#define LM35_SENSITIVITY 0.01 // V / degree C, see LM35 datasheet