Index: firmware/App/Controllers/Thermistors.c =================================================================== diff -u -re3705410a6e4df70c2a4f2d590e977326e11d7b3 -rddb9707d9e6e46c4b384782aeec20d41f3822996 --- firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision e3705410a6e4df70c2a4f2d590e977326e11d7b3) +++ firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision ddb9707d9e6e46c4b384782aeec20d41f3822996) @@ -22,8 +22,7 @@ #define THERMISTOR_REFERENCE_VOLTAGE 3.0 ///< Thermistors source voltage. #define THERMISTOR_REFERENCE_RESISTOR_AT_25 10000.0 ///< Thermistors reference resistor in ohms. #define THERMISTOR_REFERENCE_TEMPERATURE 298.0 ///< Thermistors reference temperature in kelvin. -#define ONBOARD_THERMISTOR_BETA_VALUE 3380.0 ///< Onboard thermistor beta value. -#define POWER_SUPPLY_THERMISTOR_BETA_VALUE 3345.0 ///< Power supply beta value. +#define THERMISTOR_BETA_VALUE 3380.0 ///< Thermistors beta value. #define CELSIUS_TO_KELVIN_CONVERSION 273.15 ///< Celsius to Kelvin temperature conversion. #define MIN_ALLOWED_TEMPERATURE 0.0 ///< Thermistors/sensors minimum allowed temperature reading. #define MAX_ALLOWED_TEMPERATURE 80.0 ///< Thermistors/sensors maximum allowed temperature reading. @@ -32,17 +31,16 @@ /// Thermistors exec states typedef enum thermistors_Exec_States { - THERMISTORS_EXEC_STATE_START_STATE = 0, ///< Thermistors exec state start state - THERMISTORS_EXEC_STATE_GET_ADC_VALUES_STATE, ///< Thermistors exec state get ADC values state - NUM_OF_THERMISTORS_EXEC_STATES, ///< Number of thermistors exec state + THERMISTORS_EXEC_STATE_START_STATE = 0, ///< Thermistors exec state start state. + THERMISTORS_EXEC_STATE_GET_ADC_VALUES_STATE, ///< Thermistors exec state get ADC values state. + NUM_OF_THERMISTORS_EXEC_STATES, ///< Number of thermistors exec state. } THERMISTORS_EXEC_STATES_T; /// Thermistor struct typedef struct { - S32 rawADCRead; ///< Thermistor raw ADC read - OVERRIDE_F32_T temperatureValue; ///< Thermistor temperature value - F32 betaValue; ///< Thermistor beta value used to calculate temperature + S32 rawADCRead; ///< Thermistor raw ADC read. + OVERRIDE_F32_T temperatureValue; ///< Thermistor temperature value. } THERMISTOR_T; static THERMISTORS_EXEC_STATES_T thermistorsExecState = THERMISTORS_EXEC_STATE_START_STATE; ///< Thermistors exec state. @@ -53,8 +51,8 @@ static U32 adcReadCounter; ///< Thermistors ADC read counter. static const F32 THERMISTOR_VOLTAGE_CONV_COEFF = THERMISTOR_REFERENCE_VOLTAGE / - (F32)TWELVE_BIT_RESOLUTION; ///< On board thermistor ADC to voltage conversion coefficient. -static const F32 ON_BOARD_THERMISTOR_REF_TEMP_INV = 1 / THERMISTOR_REFERENCE_TEMPERATURE; ///< On board thermistor reference inverse. + (F32)TWELVE_BIT_RESOLUTION; ///< Thermistors ADC to voltage conversion coefficient. +static const F32 THERMISTOR_REF_TEMP_INV = 1 / THERMISTOR_REFERENCE_TEMPERATURE; ///< Thermistors reference inverse. // ********** private function prototypes ********** @@ -63,7 +61,7 @@ static void monitorThermistors( void ); static void convertADC2Temperature( void ); -static F32 calculateOnBoardThemristorTemperature( U32 adcValue, F32 betaValue ); +static F32 calculateThemristorTemperature( U32 adcValue ); static void publishThermistorsData( void ); static U32 getPublishThermistorsDataInterval( void ); @@ -80,11 +78,6 @@ thermistorsExecState = THERMISTORS_EXEC_STATE_START_STATE; dataPublishCounter = 0; - // Initialize the beta values of each thermistor - thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].betaValue = ONBOARD_THERMISTOR_BETA_VALUE; - thermistorsStatus[ THERMISTOR_POWER_SUPPLY_1 ].betaValue = POWER_SUPPLY_THERMISTOR_BETA_VALUE; - thermistorsStatus[ THERMISTOR_POWER_SUPPLY_2 ].betaValue = POWER_SUPPLY_THERMISTOR_BETA_VALUE; - // Initialize a persistent alarm for thermistors temeprature out of range initPersistentAlarm( ALARM_ID_DG_THERMISTORS_TEMPERATURE_OUT_OF_RANGE, MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD, MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD ); } @@ -153,7 +146,7 @@ // Check if the thermistor of sensor is in range if ( thermistor < NUM_OF_THERMISTORS ) { - if ( thermistorsStatus[ thermistor ].temperatureValue.override == OVERRIDE_KEY ) + if ( OVERRIDE_KEY == thermistorsStatus[ thermistor ].temperatureValue.override ) { temperature = thermistorsStatus[ thermistor ].temperatureValue.ovData; } @@ -254,59 +247,55 @@ * @brief * The convertADCtoTemperature function converts the ADC values of different * thermistors and temperature sensors to temperature value. - * @details Inputs: thermistorsStatus, fpgaBoardTempSensorConvCoeff, - * adcTempSensorsConversionCoeff1, adcTempSensorsConversionCoeff2 + * @details Inputs: none * @details Outputs: thermistorsStatus * @return none *************************************************************************/ static void convertADC2Temperature( void ) { THERMISTORS_TEMP_SENSORS_T thermistor; F32 temperature; - U32 rawADC; + S32 rawADC; // Loop through the list and update the temperature values for ( thermistor = THERMISTOR_ONBOARD_NTC; thermistor < NUM_OF_THERMISTORS; thermistor++ ) { - rawADC = thermistorsStatus[ thermistor ].rawADCRead; + rawADC = (S32)thermistorsStatus[ thermistor ].rawADCRead; - temperature = calculateOnBoardThemristorTemperature( rawADC, thermistorsStatus[ thermistor ].betaValue ); + temperature = calculateThemristorTemperature( rawADC ); thermistorsStatus[ thermistor ].temperatureValue.data = temperature; } } /*********************************************************************//** * @brief - * The calculateOnBoardThemristorTemperature function converts the ADC value - * of the onboard thermistor into temperature in C. Below are the calculation + * The calculateThemristorTemperature function converts the ADC value + * of thermistors into temperature in C. Below are the calculation * steps: * voltage = ADC x 3 / 2^12 * voltage = 3 x 10 / ( 10 + R(T) ) * R(T) = 10000 x e^(beta x (1/T - 1/298)) * Solve for T which is temperature in Kelvin - * @details Inputs: onBoardThermistorVoltageConvCoeff, - * onBoardThermistorBetaValueInv + * @details Inputs: none * @details Outputs: none * @param ADC value to be converted into temperature in C - * @param beta value which is used to calculate temperature from ADC * @return calculated temperature in C *************************************************************************/ -static F32 calculateOnBoardThemristorTemperature( U32 adcValue, F32 betaValue ) +static F32 calculateThemristorTemperature( U32 adcValue ) { // Voltage = ADC x 3 / 2^12 for 12 bits resolution and a 3V ADC // The value of 3 / 2^12 has been calculated in a const to prevent the division again - F32 const thermistorVoltage = adcValue * THERMISTOR_VOLTAGE_CONV_COEFF; + F32 thermistorVoltage = adcValue * THERMISTOR_VOLTAGE_CONV_COEFF; // Calculate the thermistor resistor by solving: thermistorVoltage = (3 x 10) / (10 + R(T)) - F32 const thermistorResistor = ( ( THERMISTOR_REFERENCE_RESISTOR_AT_25 * THERMISTOR_REFERENCE_VOLTAGE ) - - ( THERMISTOR_REFERENCE_RESISTOR_AT_25 * thermistorVoltage ) ) / thermistorVoltage; + F32 thermistorResistor = ( ( THERMISTOR_REFERENCE_RESISTOR_AT_25 * THERMISTOR_REFERENCE_VOLTAGE ) - + ( THERMISTOR_REFERENCE_RESISTOR_AT_25 * thermistorVoltage ) ) / thermistorVoltage; // 1/T = Ln(thermistorResistor/10000)/3380 + 1/298 - F32 const invTemperature = ( logf( thermistorResistor / THERMISTOR_REFERENCE_RESISTOR_AT_25 ) / betaValue ) + - ON_BOARD_THERMISTOR_REF_TEMP_INV; + F32 invTemperature = ( logf( thermistorResistor / THERMISTOR_REFERENCE_RESISTOR_AT_25 ) / THERMISTOR_BETA_VALUE ) + THERMISTOR_REF_TEMP_INV; // Inverse the value to get the temperature in Kelvin and then convert it to Celsius - F32 const temperature = ( 1 / invTemperature ) - CELSIUS_TO_KELVIN_CONVERSION; + F32 temperature = ( 1 / invTemperature ) - CELSIUS_TO_KELVIN_CONVERSION; return temperature; } @@ -425,11 +414,11 @@ { BOOL result = FALSE; - if ( thermistor < NUM_OF_THERMISTORS && isTestingActivated() ) + if ( ( thermistor < NUM_OF_THERMISTORS ) && ( TRUE == isTestingActivated() ) ) { // There is a temperature range that the thermistors can be set to, otherwise, the driver // will throw an alarm. Also, the fans driver depends on these values to continuously control the fans - if ( temperature >= MIN_ALLOWED_TEMPERATURE && temperature < MAX_ALLOWED_TEMPERATURE ) + if ( ( temperature >= MIN_ALLOWED_TEMPERATURE ) && ( temperature < MAX_ALLOWED_TEMPERATURE ) ) { result = TRUE; thermistorsStatus[ thermistor ].temperatureValue.ovData = temperature; @@ -453,7 +442,7 @@ { BOOL result = FALSE; - if ( isTestingActivated() ) + if ( TRUE == isTestingActivated() ) { if ( thermistor < NUM_OF_THERMISTORS ) {