Index: firmware/App/Controllers/Thermistors.c =================================================================== diff -u -r27d91d88b73aa4194cef1d3b08decc12ccdecc33 -rf6016459473bdb85aebe393c07cd580b973d7247 --- firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision 27d91d88b73aa4194cef1d3b08decc12ccdecc33) +++ firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision f6016459473bdb85aebe393c07cd580b973d7247) @@ -6,6 +6,7 @@ #include "TaskGeneral.h" #include "InternalADC.h" #include "SystemCommMessages.h" +#include "PersistentAlarm.h" /** * @addtogroup Thermistors @@ -49,31 +50,31 @@ { S32 rawADCRead; ///< Thermistor raw ADC read OVERRIDE_F32_T temperatureValue; ///< Thermistor temperature value - U32 tempOutOfRangeCount; ///< Thermistor temperature out of range counter + 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; ///< 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 = THERMISTROS_SELF_TEST_CHECK_RANGE; ///< 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 -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 thermistorVoltageConvCoeff = THERMISTOR_REFERENCE_VOLTAGE - / TWELVE_BIT_RESOLUTION; ///< On board thermistor ADC to voltage conversion coefficient -static const F32 onBoardThermistorRefTempInv = 1 / THERMISTOR_REFERENCE_TEMPERATURE; ///< On board thermistor reference inverse + / TWELVE_BIT_RESOLUTION; ///< On board thermistor ADC to voltage conversion coefficient. +static const F32 onBoardThermistorRefTempInv = 1 / THERMISTOR_REFERENCE_TEMPERATURE; ///< On board thermistor reference inverse. // ********** private function prototypes ********** -static THERMISTORS_SELF_TEST_STATES_T handleSelfTestRangeCheck( void ); +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 convertADCtoTemperature( void ); +static void convertADC2Temperature( void ); static F32 calculateTemperature( U32 adcValue, F32 betaValue ); static void publishThermistorsData( void ); static U32 getPublishThermistorsDataInterval( void ); @@ -89,18 +90,20 @@ *************************************************************************/ void initThermistors( void ) { - THERMISTORS_TEMP_SENSORS_T thermistor; - // Reset the thermistors values for a run thermistorsSelfTestReslt = SELF_TEST_STATUS_IN_PROGRESS; - thermistorsExecState = THERMISTORS_EXEC_STATE_START; + thermistorsExecState = THERMISTORS_EXEC_STATE_START; thermistorsSelfTestState = THERMISTROS_SELF_TEST_CHECK_RANGE; - dataPublishCounter = 0; + dataPublishCounter = 0; - for ( thermistor = THERMISTOR_ONBOARD_NTC; thermistor < NUM_OF_THERMISTORS; thermistor++ ) - { - thermistorsStatus[ thermistor ].tempOutOfRangeCount = 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( PERSISTENT_ALARM_THERMISTOR_TEMPERATURE_OUT_OF_RANGE, ALARM_ID_DG_THERMISOTRS_TEMPERATURE_OUT_OF_RANGE, + TRUE, MAX_ALLOWED_TEMP_OUT_OF_RANGE_COUNT, MAX_ALLOWED_TEMP_OUT_OF_RANGE_COUNT ); } /*********************************************************************//** @@ -115,7 +118,7 @@ switch ( thermistorsSelfTestState ) { case THERMISTROS_SELF_TEST_CHECK_RANGE: - thermistorsSelfTestState = handleSelfTestRangeCheck(); + thermistorsSelfTestState = handleSelfTestCheckRange(); break; case THERMISTORS_SELF_TEST_COMPLETE: @@ -203,7 +206,7 @@ * @details Outputs: thermistorsStatus, adcReadCounter * @return next state of self test *************************************************************************/ -static THERMISTORS_SELF_TEST_STATES_T handleSelfTestRangeCheck( void ) +static THERMISTORS_SELF_TEST_STATES_T handleSelfTestCheckRange( void ) { THERMISTORS_SELF_TEST_STATES_T state = THERMISTROS_SELF_TEST_CHECK_RANGE; @@ -222,7 +225,7 @@ thermistorsStatus[ THERMISTOR_POWER_SUPPLY_2 ].rawADCRead = getIntADCReading( INT_ADC_POWER_SUPPLY_2_THERMISTOR ); // Convert the ADC values to temperature - convertADCtoTemperature(); + convertADC2Temperature(); for ( thermistor = THERMISTOR_ONBOARD_NTC; thermistor < NUM_OF_THERMISTORS; thermistor++ ) { @@ -289,8 +292,11 @@ // Zero the counter for the next round of reading adcReadCounter = 0; - // Convert all the latest ADCs to temperature - convertADCtoTemperature(); + // Convert and monitor functions are called here to convert and monitor + // the data at the control interval. Otherwise, they should have been called + // in the exec function, but the plan was to use the control interval + // Convert all the latest ADCs to temperature. + convertADC2Temperature(); // Monitor the values for a gross range check monitorThermistors(); @@ -319,18 +325,8 @@ // If the thermisotrs and sensors read temperature out of range, raise an alarm if ( temperature < MIN_ALLOWED_TEMPERATURE || temperature >= MAX_ALLOWED_TEMPERATURE ) { - // If a thermistor/sensor has been out of range consistently, raise an alarm - if ( ++thermistorsStatus[ thermistor ].tempOutOfRangeCount > MAX_ALLOWED_TEMP_OUT_OF_RANGE_COUNT ) - { - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_THERMISOTRS_TEMPERATURE_OUT_OF_RANGE, thermistor, temperature ); - thermistorsStatus[ thermistor ].tempOutOfRangeCount = 0; - } + checkPersistentAlarm( PERSISTENT_ALARM_THERMISTOR_TEMPERATURE_OUT_OF_RANGE, TRUE, temperature ); } - // If the next temperature reading is in range but the counter was greater than 0, reset - else if ( thermistorsStatus[ thermistor ].tempOutOfRangeCount > 0 ) - { - thermistorsStatus[ thermistor ].tempOutOfRangeCount = 0; - } } } @@ -344,7 +340,7 @@ * @param thermistor (also covers the temperature sensors) to convert its value * @return none *************************************************************************/ -static void convertADCtoTemperature( void ) +static void convertADC2Temperature( void ) { THERMISTORS_TEMP_SENSORS_T thermistor; F32 temperature; @@ -355,25 +351,8 @@ { rawADC = thermistorsStatus[ thermistor ].rawADCRead; - // Each of the sensors/thermistors have different equations to convert ADC read to temperature - switch ( thermistor ) - { - case THERMISTOR_ONBOARD_NTC: - temperature = calculateTemperature( rawADC, ONBOARD_THERMISTOR_BETA_VALUE ); - thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].temperatureValue.data = temperature; - break; - - case THERMISTOR_POWER_SUPPLY_1: - case THERMISTOR_POWER_SUPPLY_2: - temperature = calculateTemperature( rawADC, POWER_SUPPLY_THERMISTOR_BETA_VALUE ); - thermistorsStatus[ thermistor ].temperatureValue.data = temperature; - break; - - default: - // Wrong sensor was called, raise an alarm - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_THERMISTOR_SELECTED, thermistor ); - break; - } + temperature = calculateTemperature( rawADC, thermistorsStatus[ thermistor ].betaValue ); + thermistorsStatus[ thermistor ].temperatureValue.data = temperature; } } @@ -450,9 +429,9 @@ THERMISTORS_DATA_T sensorsData; // Get all the sensors/thermistors temperature values for publication - sensorsData.onboardThermistor = getThermistorTemperatureValue( THERMISTOR_ONBOARD_NTC ); - sensorsData.powerSupply1Thermistor = getThermistorTemperatureValue( THERMISTOR_POWER_SUPPLY_1 ); - sensorsData.powerSupply2Thermistor = getThermistorTemperatureValue( THERMISTOR_POWER_SUPPLY_2 ); + sensorsData.onboardThermistor = getThermistorTemperatureValue( THERMISTOR_ONBOARD_NTC ); + sensorsData.powerSupply1Thermistor = getThermistorTemperatureValue( THERMISTOR_POWER_SUPPLY_1 ); + sensorsData.powerSupply2Thermistor = getThermistorTemperatureValue( THERMISTOR_POWER_SUPPLY_2 ); // Broadcast the thermistors data broadcastThermistorsData( &sensorsData ); @@ -555,9 +534,9 @@ { BOOL result = FALSE; - if ( thermistor < NUM_OF_THERMISTORS ) + if ( isTestingActivated() ) { - if ( isTestingActivated() ) + if ( thermistor < NUM_OF_THERMISTORS ) { result = TRUE; thermistorsStatus[ thermistor ].temperatureValue.override = OVERRIDE_RESET;