Index: firmware/App/Controllers/Thermistors.c =================================================================== diff -u -rc8fa40dde08a25bf61fae9f4fe770606a234db57 -re3705410a6e4df70c2a4f2d590e977326e11d7b3 --- firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision c8fa40dde08a25bf61fae9f4fe770606a234db57) +++ firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision e3705410a6e4df70c2a4f2d590e977326e11d7b3) @@ -1,12 +1,12 @@ #include // For temperature calculations -#include "Thermistors.h" #include "FPGA.h" -#include "TaskGeneral.h" #include "InternalADC.h" -#include "SystemCommMessages.h" #include "PersistentAlarm.h" +#include "SystemCommMessages.h" +#include "Thermistors.h" +#include "TaskGeneral.h" /** * @addtogroup Thermistors @@ -15,86 +15,70 @@ // ********** 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.0 ///< FGPA read delay upon startup. -#define TWELVE_BIT_RESOLUTION 4096U ///< 12 bit resolution conversion. -#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 CELSIUS_TO_KELVIN_CONVERSION 273.15 ///< Celsius to Kelvin temperature conversion. -#define MIN_ALLOWED_TEMPERATURE 5.0 ///< Thermistors/sensors minimum allowed temperature reading. -#define MAX_ALLOWED_TEMPERATURE 70.0 ///< Thermistors/sensors maximum allowed temperature reading. -#define MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD ( 5 * MS_PER_SECOND ) ///< Thermistors/sensors maximum allowed temperature out of range period. +#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.0 ///< FGPA read delay upon startup. +#define TWELVE_BIT_RESOLUTION 4096U ///< 12 bit resolution conversion. +#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 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. +#define MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD ( 5 * MS_PER_SECOND ) ///< Thermistors/sensors maximum allowed temperature out of range period. -/// Thermistors self test states -typedef enum thermistors_Self_Test_States -{ - THERMISTROS_SELF_TEST_CHECK_RANGE_STATE = 0, ///< Thermistors self test range check state - THERMISTORS_SELF_TEST_COMPLETE_STATE, ///< Thermistors self test complete state - NUM_OF_THERMISTORS_SELF_TEST_STATES, ///< Number of thermistors self test states -} THERMISTORS_SELF_TEST_STATES_T; - /// 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 + F32 betaValue; ///< Thermistor beta value used to calculate temperature } THERMISTOR_T; -static SELF_TEST_STATUS_T thermistorsSelfTestReslt = SELF_TEST_STATUS_IN_PROGRESS; ///< Thermistors self test result. -static THERMISTORS_SELF_TEST_STATES_T thermistorsSelfTestState = THERMISTROS_SELF_TEST_CHECK_RANGE_STATE; ///< Thermistors self test state. -static THERMISTORS_EXEC_STATES_T thermistorsExecState = THERMISTORS_EXEC_STATE_START_STATE; ///< Thermistors exec state. -static THERMISTOR_T thermistorsStatus[ NUM_OF_THERMISTORS ]; ///< Thermistors array. +static THERMISTORS_EXEC_STATES_T thermistorsExecState = THERMISTORS_EXEC_STATE_START_STATE; ///< 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. -static U32 dataPublishCounter; ///< Thermistors data publish timer counter. -static U32 adcReadCounter; ///< Thermistors ADC read counter. + 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 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; ///< 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. // ********** private function prototypes ********** -static THERMISTORS_SELF_TEST_STATES_T handleSelfTestCheckRange( void ); - static THERMISTORS_EXEC_STATES_T handleExecStart( void ); static THERMISTORS_EXEC_STATES_T handleExecGetADCValues( void ); static void monitorThermistors( void ); static void convertADC2Temperature( void ); -static F32 calculateTemperature( U32 adcValue, F32 betaValue ); +static F32 calculateOnBoardThemristorTemperature( U32 adcValue, F32 betaValue ); static void publishThermistorsData( void ); static U32 getPublishThermistorsDataInterval( void ); /*********************************************************************//** * @brief * The initThermistors function initializes the thermistors module. - * @details Inputs: thermistorsSelfTestReslt, thermistorsExecState, - * thermistorsExecState, dataPublishCounter - * @details Outputs: thermistorsSelfTestReslt, thermistorsExecState, - * thermistorsExecState, dataPublishCounter + * @details Inputs: none + * @details Outputs: thermistorsExecState, dataPublishCounter * @return none *************************************************************************/ void initThermistors( void ) { // Reset the thermistors values for a run - thermistorsSelfTestReslt = SELF_TEST_STATUS_IN_PROGRESS; - thermistorsExecState = THERMISTORS_EXEC_STATE_START_STATE; - thermistorsSelfTestState = THERMISTROS_SELF_TEST_CHECK_RANGE_STATE; - dataPublishCounter = 0; + thermistorsExecState = THERMISTORS_EXEC_STATE_START_STATE; + dataPublishCounter = 0; // Initialize the beta values of each thermistor thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].betaValue = ONBOARD_THERMISTOR_BETA_VALUE; @@ -108,30 +92,19 @@ /*********************************************************************//** * @brief * The execThermistorsSelfTest function executes the thermistors self test. - * @details Inputs: thermistorsSelfTestState - * @details Outputs: thermistorsSelfTestState + * @details Inputs: none + * @details Outputs: none * @return Status of self test *************************************************************************/ SELF_TEST_STATUS_T execThermistorsSelfTest( void ) { - switch ( thermistorsSelfTestState ) - { - case THERMISTROS_SELF_TEST_CHECK_RANGE_STATE: - thermistorsSelfTestState = handleSelfTestCheckRange(); - break; + SELF_TEST_STATUS_T status = SELF_TEST_STATUS_IN_PROGRESS; - case THERMISTORS_SELF_TEST_COMPLETE_STATE: - // Done with POST. Do nothing. - break; + // TODO implement the calibration processing function. + // It returns a pass for now + status = SELF_TEST_STATUS_PASSED; - default: - // Wrong state was called, raise an alarm - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_THERMISTORS_INVALID_SELF_TEST_STATE, thermistorsSelfTestState ); - thermistorsSelfTestState = THERMISTORS_SELF_TEST_COMPLETE_STATE; - break; - } - - return thermistorsSelfTestReslt; + return status; } /*********************************************************************//** @@ -199,55 +172,6 @@ /*********************************************************************//** * @brief - * The handleSelfTestRangeCheck function checks whether the thermistors - * are in range upon staring the device. - * @details Inputs: thermistorsStatus, adcReadCounter - * @details Outputs: thermistorsStatus, adcReadCounter - * @return next state of self test - *************************************************************************/ -static THERMISTORS_SELF_TEST_STATES_T handleSelfTestCheckRange( void ) -{ - THERMISTORS_SELF_TEST_STATES_T state = THERMISTROS_SELF_TEST_CHECK_RANGE_STATE; - - // Give a short time for FPGA to boot up and start sending the ADC reads - if ( ++adcReadCounter > ADC_FPGA_READ_DELAY_COUNT ) - { - THERMISTORS_TEMP_SENSORS_T thermistor; - F32 temperature; - - // Assuming self test passed - thermistorsSelfTestReslt = SELF_TEST_STATUS_PASSED; - - // Get all the raw readings in ADC - thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].rawADCRead = getIntADCReading( INT_ADC_BOARD_THERMISTOR ); - thermistorsStatus[ THERMISTOR_POWER_SUPPLY_1 ].rawADCRead = getIntADCReading( INT_ADC_POWER_SUPPLY_1_THERMISTOR ); - thermistorsStatus[ THERMISTOR_POWER_SUPPLY_2 ].rawADCRead = getIntADCReading( INT_ADC_POWER_SUPPLY_2_THERMISTOR ); - - // Convert the ADC values to temperature - convertADC2Temperature(); - - for ( thermistor = THERMISTOR_ONBOARD_NTC; thermistor < NUM_OF_THERMISTORS; thermistor++ ) - { - // Get the actual temperature value and not the override value - temperature = thermistorsStatus[ thermistor ].temperatureValue.data; - // If the values are out of range, raise an alarm - if ( temperature < MIN_ALLOWED_TEMPERATURE || temperature >= MAX_ALLOWED_TEMPERATURE ) - { - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_THERMISTORS_TEMPERATURE_OUT_OF_RANGE, thermistor, temperature ); - // If any thermistor/sensor is not in range, POST has failed - thermistorsSelfTestReslt = SELF_TEST_STATUS_FAILED; - } - } - // Done with POST - state = THERMISTORS_SELF_TEST_COMPLETE_STATE; - adcReadCounter = 0; - } - - return state; -} - -/*********************************************************************//** - * @brief * The handleExecStart function handles the start state of the exec state * machine. * @details Inputs: adcReadCounter @@ -290,7 +214,7 @@ // Monitor the values for a gross range check // Monitor is called in this function because this driver is constantly reading - // the thermisotor values. Also the internal ADC values are processed with moving average in the internalADC driver + // the thermistor values. Also the internal ADC values are processed with moving average in the internalADC driver // So the thermistors drivers just gets the latest ADC value and converts it to temperature monitorThermistors(); @@ -333,7 +257,6 @@ * @details Inputs: thermistorsStatus, fpgaBoardTempSensorConvCoeff, * adcTempSensorsConversionCoeff1, adcTempSensorsConversionCoeff2 * @details Outputs: thermistorsStatus - * @param thermistor (also covers the temperature sensors) to convert its value * @return none *************************************************************************/ static void convertADC2Temperature( void ) @@ -347,14 +270,14 @@ { rawADC = thermistorsStatus[ thermistor ].rawADCRead; - temperature = calculateTemperature( rawADC, thermistorsStatus[ thermistor ].betaValue ); + temperature = calculateOnBoardThemristorTemperature( rawADC, thermistorsStatus[ thermistor ].betaValue ); thermistorsStatus[ thermistor ].temperatureValue.data = temperature; } } /*********************************************************************//** * @brief - * The calcualteOnBoardThemristorTemperature function converts the ADC value + * The calculateOnBoardThemristorTemperature function converts the ADC value * of the onboard thermistor into temperature in C. Below are the calculation * steps: * voltage = ADC x 3 / 2^12 @@ -368,10 +291,8 @@ * @param beta value which is used to calculate temperature from ADC * @return calculated temperature in C *************************************************************************/ -static F32 calculateTemperature( U32 adcValue, F32 betaValue ) +static F32 calculateOnBoardThemristorTemperature( U32 adcValue, F32 betaValue ) { - - // 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;