Index: firmware/App/Controllers/Thermistors.c =================================================================== diff -u -r2f2d0ccadd8a09037eb3d0dd144549b2c8c8129b -r45263215b372cd579e8e16bb8073c287c726c55d --- firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision 2f2d0ccadd8a09037eb3d0dd144549b2c8c8129b) +++ firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision 45263215b372cd579e8e16bb8073c287c726c55d) @@ -15,13 +15,17 @@ // ********** private definitions ********** #define THERMISTORS_DATA_PUBLISH_INTERVAL (MS_PER_SECOND / TASK_GENERAL_INTERVAL) ///< Thermistors publish data time interval. -#define THERMISTORS_ADC_READ_INTERVAL (MS_PER_SECOND / (2 * TASK_GENERAL_INTERVAL)) ///< Thermistors ADC read time interval. -#define ADC_FPGA_READ_DELAY_COUNT 1 ///< FGPA read delay upon startup. -#define ONBOARD_THERMISTOR_SOURCE_VOLTAGE 3 ///< Onboard thermistor source voltage. -#define ONBOARD_THERMISTOR_REFERENCE_RESISTOR 10 ///< Onboard thermistor reference resistor. -#define ONBOARD_THERMISTOR_BETA_VALUE 3380 ///< Onboard thermistor beta value. -#define ONBOARD_THERMISTOR_REFERENCE_TEMPERATURE 298 ///< Onboard thermistor reference temperature. -#define TWELVE_BIT_RESOLUTION 4096 ///< 12 bit resolution conversion. +#define THERMISTORS_ADC_READ_INTERVAL (MS_PER_SECOND / (2 * TASK_GENERAL_INTERVAL)) ///< Thermistors ADC read time interval. +#define ADC_FPGA_READ_DELAY_COUNT 1 ///< FGPA read delay upon startup. +#define ONBOARD_THERMISTOR_SOURCE_VOLTAGE 3 ///< Onboard thermistor source voltage. +#define ONBOARD_THERMISTOR_REFERENCE_RESISTOR 10 ///< Onboard thermistor reference resistor. +#define ONBOARD_THERMISTOR_BETA_VALUE 3380 ///< Onboard thermistor beta value. +#define ONBOARD_THERMISTOR_REFERENCE_TEMPERATURE 298 ///< Onboard thermistor reference temperature. +#define TWELVE_BIT_RESOLUTION 4096 ///< 12 bit resolution conversion. +#define CELSIUS_TO_KELVIN_CONVERSION 273.15 ///< Celsius to Kelvin temperature conversion. +#define ADC_TEMP_SENSORS_CONVERSION_CONST 272.5 ///< ADC temperature sensors conversion constant. +#define MIN_ALLOWED_TEMPERATURE 10 ///< Thermistors/sensors minimum allowed temperature reading. +#define MAX_ALLOWED_TEMPERATURE 70 ///< Thermistors/sensors maximum allowed temperature reading. /// Thermistors self test states typedef enum thermistors_Self_Test_States @@ -47,26 +51,27 @@ OVERRIDE_F32_T temperatureValue; ///< Thermistor temperature value } THERMISTOR_T; - -static SELF_TEST_STATUS_T thermistorsSelfTestReslt = SELF_TEST_STATUS_IN_PROGRESS; ///< Thermistors self test result -static THERMISTORS_SELF_TEST_STATES_T thermistorsSelfTestState = THERMISTORS_SELF_TEST_START; ///< Thermistors self test state -static THERMISTORS_EXEC_STATES_T thermistorsExecState = THERMISTORS_EXEC_STATE_START; ///< Thermistors exec state -static THERMISTOR_T thermistorsStatus[ NUM_OF_THERMISTORS ]; ///< Thermistors array - +static SELF_TEST_STATUS_T thermistorsSelfTestReslt = SELF_TEST_STATUS_IN_PROGRESS; ///< Thermistors self test result +static THERMISTORS_SELF_TEST_STATES_T thermistorsSelfTestState = THERMISTORS_SELF_TEST_START; ///< Thermistors self test state +static THERMISTORS_EXEC_STATES_T thermistorsExecState = THERMISTORS_EXEC_STATE_START; ///< Thermistors exec state +static THERMISTOR_T thermistorsStatus[ NUM_OF_THERMISTORS ]; ///< Thermistors array static OVERRIDE_U32_T thermistorsPublishInterval = { THERMISTORS_DATA_PUBLISH_INTERVAL, - THERMISTORS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Thermistors publish time interval override + THERMISTORS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Thermistors publish time interval override +static U32 dataPublishCounter; ///< Thermistors data publish timer counter +static U32 adcReadCounter; ///< Thermistors ADC read counter -static U32 dataPublishCounter; ///< Thermistors data publish timer counter -static U32 adcReadCounter; ///< Thermistors ADC read counter +static const F32 fpgaBoardTempSensorConvCoeff = 503.975 / TWELVE_BIT_RESOLUTION; ///< FPGA board temperature sensor conversion coefficient +static const F32 adcTempSensorsConversionCoeff1 = 1 / 13584; ///< ADC temperature sensors conversion coefficient 1 +static const F32 adcTempSensorsConversionCoeff2 = 0x800000 / 13584; ///< ADC temperature sensors conversion coefficient 2 // ********** private function prototypes ********** static THERMISTORS_EXEC_STATES_T handleExecStart( void ); static THERMISTORS_EXEC_STATES_T handleExecGetADCValues( void ); -static void convertADCtoTemperature( THERMISTORS_TEMP_SENSORS_T thermistor ); -static F32 calcualteOnBoardThemristorTemperature( U32 adcValue ); - +static void monitorThermistors( void ); +static void convertADCtoTemperature( void ); +static F32 calculateOnBoardThemristorTemperature( U32 adcValue ); static void publishThermistorsData( void ); static U32 getPublishThermistorsDataInterval( void ); @@ -211,65 +216,105 @@ *************************************************************************/ static THERMISTORS_EXEC_STATES_T handleExecGetADCValues( void ) { - THERMISTORS_TEMP_SENSORS_T thermistor; - THERMISTORS_EXEC_STATES_T state = THERMISTORS_EXEC_STATE_GET_ADC_VALUES; // If time has elapsed to read the ADCs, read them all if ( ++adcReadCounter >= THERMISTORS_ADC_READ_INTERVAL ) { - thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].rawADCRead = getIntADCReading( INT_ADC_BOARD_THERMISTOR ); + // Get all the raw readings in ADC + thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].rawADCRead = getIntADCReading( INT_ADC_BOARD_THERMISTOR ); + thermistorsStatus[ TEMPSENSOR_FPGA_SENSOR ].rawADCRead = getFPGABoardTemp(); + thermistorsStatus[ TEMPSENSOR_LOAD_CELL_A1 ].rawADCRead = getFPGALoadCellsA1B1Temp(); + thermistorsStatus[ TEMPSENSOR_LOAD_CELL_A2 ].rawADCRead = getFPGALoadCellsA2B2Temp(); + thermistorsStatus[ TEMPSENSOR_THDO_RTD ].rawADCRead = getFPGATHDoInternalTemp(); + thermistorsStatus[ TEMPSENSOR_TDI_RTD ].rawADCRead = getFPGATDiInternalTemp(); + thermistorsStatus[ TEMPSENSOR_CONDUCTIVITY ].rawADCRead = getFPGAConductivitySnsrInternalTemp(); // Zero the counter for the next round of reading adcReadCounter = 0; - // Loop through the list and update the temperature values - for ( thermistor = THERMISTOR_ONBOARD_NTC; thermistor < NUM_OF_THERMISTORS; thermistor++ ) - { - convertADCtoTemperature( thermistor ); - } + // Convert all the latest ADCs to temperature + convertADCtoTemperature(); + + // Monitor the values for a gross range check + monitorThermistors(); } return state; } /*********************************************************************//** * @brief + * The monitorThermistors function monitors the thermistors and sensors + * for gross temperature range check. + * @details Inputs: none + * @details Outputs: none + * @return none + *************************************************************************/ +static void monitorThermistors( void ) +{ + THERMISTORS_TEMP_SENSORS_T thermistor; + F32 temperature; + + for ( thermistor = THERMISTOR_ONBOARD_NTC; thermistor < NUM_OF_THERMISTORS; thermistor++ ) + { + temperature = getThermistorTemperatureValue( thermistor ); + + // If the thermisotrs and sensors read temperature out of range, raise an alarm + if ( temperature < MIN_ALLOWED_TEMPERATURE || temperature >= MAX_ALLOWED_TEMPERATURE ) + { + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_THERMISOTRS_TEMPERATURE_OUT_OF_RANGE, thermistor, temperature ); + } + } +} + +/*********************************************************************//** + * @brief * The convertADCtoTemperature function converts the ADC values of different * thermistors and temperature sensors to temperature value. * @details Inputs: thermistorsStatus * @details Outputs: thermistorsStatus * @param thermistor (also covers the temperature sensors) to convert its value * @return none *************************************************************************/ -static void convertADCtoTemperature( THERMISTORS_TEMP_SENSORS_T thermistor ) +static void convertADCtoTemperature( void ) { + THERMISTORS_TEMP_SENSORS_T thermistor; F32 temperature; + U32 rawADC; - // Each of the sensors/thermistors have different equations to convert ADC read to temperature - switch ( thermistor ) + // Loop through the list and update the temperature values + for ( thermistor = THERMISTOR_ONBOARD_NTC; thermistor < NUM_OF_THERMISTORS; thermistor++ ) { - case THERMISTOR_ONBOARD_NTC: - temperature = calcualteOnBoardThemristorTemperature( thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].rawADCRead ); - thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].temperatureValue.data = temperature; - break; + rawADC = thermistorsStatus[ thermistor ].rawADCRead; - case TEMPSENSOR_FPGA_SENSOR: - //TODO do stuff - break; + // Each of the sensors/thermistors have different equations to convert ADC read to temperature + switch ( thermistor ) + { + case THERMISTOR_ONBOARD_NTC: + temperature = calculateOnBoardThemristorTemperature( rawADC ); + thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].temperatureValue.data = temperature; + break; - case TEMPSENSOR_LOAD_CELL_A1: - case TEMPSENSOR_LOAD_CELL_A2: - case TEMPSENSOR_THDO_RTD: - case TEMPSENSOR_TDI_RTD: - case THERMISTOR_CONDUCTIVITY: + case TEMPSENSOR_FPGA_SENSOR: + temperature = ( rawADC * fpgaBoardTempSensorConvCoeff ) - CELSIUS_TO_KELVIN_CONVERSION; + thermistorsStatus[ TEMPSENSOR_FPGA_SENSOR ].temperatureValue.data = temperature; + break; - // TODO fill up the case - break; + // All these sensors have the same conversion procedure + case TEMPSENSOR_LOAD_CELL_A1: + case TEMPSENSOR_LOAD_CELL_A2: + case TEMPSENSOR_THDO_RTD: + case TEMPSENSOR_TDI_RTD: + case TEMPSENSOR_CONDUCTIVITY: + temperature = ( ( rawADC * adcTempSensorsConversionCoeff1 ) - adcTempSensorsConversionCoeff2 ) - ADC_TEMP_SENSORS_CONVERSION_CONST; + thermistorsStatus[ thermistor ].temperatureValue.data = temperature; + break; - default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_THERMISTOR_SELECTED, thermistor ); - break; + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_THERMISTOR_SELECTED, thermistor ); + break; + } } } @@ -282,7 +327,7 @@ * @param ADC value to be converted into temperature in C * @return calculated temperature in C *************************************************************************/ -static F32 calcualteOnBoardThemristorTemperature( U32 adcValue ) +static F32 calculateOnBoardThemristorTemperature( U32 adcValue ) { //TODO add comments F32 thermistorVoltage = ( adcValue * ONBOARD_THERMISTOR_SOURCE_VOLTAGE ) / TWELVE_BIT_RESOLUTION; @@ -328,11 +373,19 @@ if ( ++dataPublishCounter > getPublishThermistorsDataInterval() ) { THERMISTORS_DATA_T sensorsData; - //TODO add the rest too - sensorsData.OnboardThermistor = getThermistorTemperatureValue( THERMISTOR_ONBOARD_NTC ); - broadcastThermistorsData( &sensorsData ); + // Get all the sensors/thermistors values for publication + sensorsData.onboardThermistor = getThermistorTemperatureValue( THERMISTOR_ONBOARD_NTC ); + sensorsData.fpgaBoardTempSensor = getFPGABoardTemp(); + sensorsData.loadCellA1TempSensor = getFPGALoadCellsA1B1Temp(); + sensorsData.loadCellA2TempSensor = getFPGALoadCellsA2B2Temp(); + sensorsData.rtdInternalTempSensor = getFPGATHDoInternalTemp(); + sensorsData.rtdTDiInternalTempSensor = getFPGATDiInternalTemp(); + sensorsData.conductivityTempSensor = getFPGAConductivitySnsrInternalTemp(); + // Broadcast the thermistors data + broadcastThermistorsData( &sensorsData ); + // Reset the counter dataPublishCounter = 0; } } @@ -341,24 +394,108 @@ * TEST SUPPORT FUNCTIONS *************************************************************************/ -BOOL testSetMeasuredThermistorOverride( U32 thermistor, F32 temperature ) +/*********************************************************************//** + * @brief + * The testSetThermistorPublishIntervalOverride function overrides the + * thermistors data publish interval. + * @details Inputs: thermistorsPublishInterval + * @details Outputs: thermistorsPublishInterval + * @param value which is override value for the thermistors data publish + * interval + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetThermistorPublishIntervalOverride( U32 value ) { + BOOL result = FALSE; + if ( TRUE == isTestingActivated() ) + { + U32 intvl = value / TASK_GENERAL_INTERVAL; + + result = TRUE; + thermistorsPublishInterval.ovData = intvl; + thermistorsPublishInterval.override = OVERRIDE_KEY; + } + + return result; } -BOOL testResetMeasuredThermistorOverride( U32 thermistor ) +/*********************************************************************//** + * @brief + * The testResetThermistorPublishIntervalOverride function resets the override + * of the thermistors publish interval. + * @details Inputs: thermistorsPublishInterval + * @details Outputs: thermistorsPublishInterval + * @return TRUE if override reset successful, FALSE if not + *************************************************************************/ +BOOL testResetThermistorPublishIntervalOverride( void ) { + BOOL result = FALSE; + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + thermistorsPublishInterval.override = OVERRIDE_RESET; + thermistorsPublishInterval.ovData = thermistorsPublishInterval.ovInitData; + } + + return result; } -BOOL testSetThermistorPublishIntervalOverride( U32 value ) +/*********************************************************************//** + * @brief + * The testSetMeasuredThermistorOverride function overrides the value of + * a thermistor. + * @details Inputs: thermistorsStatus + * @details Outputs: thermistorsStatus + * @param thermistor which its value is overridden + * @param temperature value to override + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetMeasuredThermistorOverride( U32 thermistor, F32 temperature ) { + BOOL result = FALSE; + if ( thermistor < NUM_OF_THERMISTORS && 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 ) + { + result = TRUE; + thermistorsStatus[ thermistor ].temperatureValue.ovData = temperature; + thermistorsStatus[ thermistor ].temperatureValue.override = OVERRIDE_KEY; + } + } + + return result; } -BOOL testResetThermistorPublishIntervalOverride( void ) +/*********************************************************************//** + * @brief + * The testResetMeasuredThermistorOverride function resets the override + * value of a thermistor. + * @details Inputs: thermistorsStatus + * @details Outputs: thermistorsStatus + * @param thermistor which its value is overridden + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testResetMeasuredThermistorOverride( U32 thermistor ) { + BOOL result = FALSE; -} + if ( thermistor < NUM_OF_THERMISTORS ) + { + if ( isTestingActivated() ) + { + result = TRUE; + thermistorsStatus[ thermistor ].temperatureValue.override = OVERRIDE_RESET; + thermistorsStatus[ thermistor ].temperatureValue.ovData = thermistorsStatus[ thermistor ].temperatureValue.ovInitData; + } + } + return result; +} + +/**@}*/