Paste #ceF -- näytä pelkkänä tekstinä -- uusi tämän pohjalta
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | int8_t measure_convert_return_internal_temperature_celsius_x1(){ //Function to measure convert and return temperature in celsius x1 format using internal diode thermometer. NOTE: ususable without EEPROM stored calibration to offset result. adc_set_refs_internal_1v1_bandgap(); //Switch reference selection to Internal 1V1 bandgap adc_ad_channel_switch(AD_CHANNEL_INTERNAL_THERMOMETER); //Switch AD channel to internal thermometer _delay_ms(1); //1ms settling time required before conversion! uint16_t adc_value = adc_read_ad_channel_ui16_noise_reduction(); //Get ADC value from function that does ADC noise reduction during conversion adc_set_refs_vcc(); //Switch reference selection back to VCC. Internal 1.1V bandgap reference is mainly used here if(adc_value<INTERNAL_THERMOMETER_25C_ADC_VALUE){ //If we are interpolating -40C to 25C range return (int8_t)((interpolate_i16(INTERNAL_THERMOMETER_M40C_TEMPERATURE, INTERNAL_THERMOMETER_25C_TEMPERATURE, (uint8_t)(INTERNAL_THERMOMETER_25C_ADC_VALUE - INTERNAL_THERMOMETER_M40C_ADC_VALUE),(adc_value - INTERNAL_THERMOMETER_M40C_ADC_VALUE))) + global_temperature_offset_celsius_x1); //Interpolate temperature in range -40C - 25C } else{ //Else we are interpolating 25C - 85C range return (int8_t)(interpolate_i16(INTERNAL_THERMOMETER_25C_TEMPERATURE, INTERNAL_THERMOMETER_85C_TEMPERATURE, (uint8_t)(INTERNAL_THERMOMETER_85C_ADC_VALUE - INTERNAL_THERMOMETER_25C_ADC_VALUE),(adc_value - INTERNAL_THERMOMETER_25C_ADC_VALUE)) + global_temperature_offset_celsius_x1); //Interpolate temperature in range 25C - 85C } } |