fix temp sensor & validate it (#1879)
* fix temp sensor & validate * smaller here should work
This commit is contained in:
parent
299a345c1c
commit
568ec91fc0
|
@ -70,6 +70,8 @@ case EFI_ADC_8:
|
|||
return "EFI_ADC_8";
|
||||
case EFI_ADC_9:
|
||||
return "EFI_ADC_9";
|
||||
case EFI_ADC_TEMP_SENSOR:
|
||||
return "EFI_ADC_TEMP_SENSOR";
|
||||
case EFI_ADC_ERROR:
|
||||
return "EFI_ADC_ERROR";
|
||||
case EFI_ADC_NONE:
|
||||
|
|
|
@ -265,6 +265,7 @@ typedef enum __attribute__ ((__packed__)) {
|
|||
EFI_ADC_14 = 15, // PC4
|
||||
EFI_ADC_15 = 16, // PC5
|
||||
|
||||
// todo: bad choice of value since now we have ADC_CHANNEL_SENSOR and could end up with 17 and 18 also
|
||||
EFI_ADC_ERROR = 17,
|
||||
EFI_ADC_TEMP_SENSOR = 17, // Internal temp sensor
|
||||
|
||||
EFI_ADC_ERROR = 50,
|
||||
} adc_channel_e;
|
||||
|
|
|
@ -248,13 +248,18 @@ static void fast_adc_callback(GPTDriver*) {
|
|||
}
|
||||
#endif /* HAL_USE_GPT */
|
||||
|
||||
float getMCUInternalTemperature(void) {
|
||||
float getMCUInternalTemperature() {
|
||||
#if defined(ADC_CHANNEL_SENSOR)
|
||||
float TemperatureValue = adcToVolts(slowAdc.getAdcValueByHwChannel(ADC_CHANNEL_SENSOR));
|
||||
TemperatureValue -= 0.760; // Subtract the reference voltage at 25 deg C
|
||||
TemperatureValue /= .0025; // Divide by slope 2.5mV
|
||||
float TemperatureValue = adcToVolts(slowAdc.getAdcValueByHwChannel(EFI_ADC_TEMP_SENSOR));
|
||||
TemperatureValue -= 0.760f; // Subtract the reference voltage at 25 deg C
|
||||
TemperatureValue /= 0.0025f; // Divide by slope 2.5mV
|
||||
|
||||
TemperatureValue += 25.0; // Add the 25 deg C
|
||||
|
||||
if (TemperatureValue > 150.0f || TemperatureValue < -50.0f) {
|
||||
firmwareError(OBD_PCM_Processor_Fault, "Invalid CPU temperature measured!");
|
||||
}
|
||||
|
||||
return TemperatureValue;
|
||||
#else
|
||||
return 0;
|
||||
|
@ -620,7 +625,7 @@ void initAdcInputs() {
|
|||
|
||||
#if defined(ADC_CHANNEL_SENSOR)
|
||||
// Internal temperature sensor, Available on ADC1 only
|
||||
slowAdc.enableChannel((adc_channel_e)ADC_CHANNEL_SENSOR);
|
||||
slowAdc.enableChannel(EFI_ADC_TEMP_SENSOR);
|
||||
#endif /* ADC_CHANNEL_SENSOR */
|
||||
|
||||
slowAdc.init();
|
||||
|
|
Loading…
Reference in New Issue