Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -r660a97b10ac500184b1c9554cf770e2f5df7f615 -rdc0d9b087c609e71cacdb7f0395cccf29d749c00 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 660a97b10ac500184b1c9554cf770e2f5df7f615) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision dc0d9b087c609e71cacdb7f0395cccf29d749c00) @@ -14,12 +14,14 @@ * @date (original) 08-Apr-2020 * ***************************************************************************/ -#include // For temperature calculation +#ifndef _VECTORCAST_ + #include // For temperature calculation +#endif + +#include "TemperatureSensors.h" #include "FPGA.h" -#include "PersistentAlarm.h" #include "SystemCommMessages.h" -#include "TemperatureSensors.h" #include "Timers.h" #include "TaskPriority.h" #include "TaskGeneral.h" @@ -121,6 +123,10 @@ static U32 elapsedTime; ///< Elapsed time variable static U32 internalHeatersConversionTimer; ///< Conversion timer variable to calculate the heaters internal temperature +static U32 inletWaterHighTempCounter; ///< Temperature too high persistence counter +static U32 inletWaterLowTempCounter; ///< Temperature too low persistence counter +static U32 inletWaterTempInRangeCounter; ///< Temperature in range persistence counter + static F32 tempValuesForPublication [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors data publication array static U32 dataPublicationTimerCounter; ///< Temperature sensors data publish timer counter static OVERRIDE_U32_T tempSensorsPublishInterval = { TEMP_SENSORS_DATA_PUBLISH_INTERVAL, @@ -181,6 +187,9 @@ tempSensorsExecState = TEMPSENSORS_EXEC_STATE_START; elapsedTime = 0; internalHeatersConversionTimer = 0; + inletWaterLowTempCounter = 0; + inletWaterHighTempCounter = 0; + inletWaterTempInRangeCounter = 0; dataPublicationTimerCounter = 0; /* NOTE: The temperature sensors do not have conversion coefficient. @@ -234,11 +243,8 @@ // Initialize the heaters calculated internal temperature sensors. The constants are zero since they will not be used for conversion // Windowed time count for FPGA temperature sensor error - initTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_TEMPERATURE_SENSOR_ERROR, MAX_TEMPERATURE_SENSOR_FAILURES, MAX_TEMPERATURE_SENSOR_FAILURE_WINDOW_MS ); - - initPersistentAlarm( ALARM_ID_INLET_WATER_HIGH_TEMPERATURE, ALARM_DATA_TYPE_F32, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT ); - - initPersistentAlarm( ALARM_ID_INLET_WATER_LOW_TEMPERATURE, ALARM_DATA_TYPE_F32, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT ); + initTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_TEMPERATURE_SENSOR_ERROR, + MAX_TEMPERATURE_SENSOR_FAILURES, MAX_TEMPERATURE_SENSOR_FAILURE_WINDOW_MS ); } /************************************************************************* @@ -316,16 +322,41 @@ * @details * Inputs : Inlet water temperature value * Outputs : Trigger alarms when temperature is out of allowed range + * @param none * @return none *************************************************************************/ void checkInletWaterTemperature( void ) { F32 const temperature = getTemperatureValue( TEMPSENSORS_INLET_PRIMARY_HEATER ); - BOOL const isWaterTempTooHigh = temperature > MAX_WATER_INPUT_TEMPERATURE; - BOOL const isWaterTempTooLow = temperature < MIN_WATER_INPUT_TEMPERATURE; - - checkPersistentAlarm( ALARM_ID_INLET_WATER_HIGH_TEMPERATURE, isWaterTempTooHigh, temperature ); - checkPersistentAlarm( ALARM_ID_INLET_WATER_LOW_TEMPERATURE, isWaterTempTooLow, temperature ); + if ( temperature < MIN_WATER_INPUT_TEMPERATURE ) + { + ++inletWaterLowTempCounter; + inletWaterTempInRangeCounter = 0; + if ( inletWaterLowTempCounter > INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT ) + { + SET_ALARM_WITH_1_F32_DATA( ALARM_ID_INLET_WATER_LOW_TEMPERATURE, temperature ); + } + } + else if ( temperature > MAX_WATER_INPUT_TEMPERATURE ) + { + ++inletWaterHighTempCounter; + inletWaterTempInRangeCounter = 0; + if ( inletWaterHighTempCounter > INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT ) + { + SET_ALARM_WITH_1_F32_DATA( ALARM_ID_INLET_WATER_HIGH_TEMPERATURE, temperature ); + } + } + else + { + ++inletWaterTempInRangeCounter; + inletWaterLowTempCounter = 0; + inletWaterHighTempCounter = 0; + if ( inletWaterTempInRangeCounter > INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT ) + { + clearAlarm( ALARM_ID_INLET_WATER_LOW_TEMPERATURE ); + clearAlarm( ALARM_ID_INLET_WATER_HIGH_TEMPERATURE ); + } + } } /************************************************************************* @@ -335,7 +366,7 @@ * @details * Inputs : none * Outputs : none - * @param sensor Temperature sensor index + * @param sensor ID of sensor to get temperature for * @return temperature *************************************************************************/ F32 getTemperatureValue ( U32 sensorIndex ) @@ -365,13 +396,12 @@ * ADC read from FPGA * @details * Inputs : none - * Outputs : none - * @param avgADC Running average ADC - * @param gain ADC gain - * @param refResistance ADC reference resistance - * @param zeroDegResistance ADC zero degree resistance - * @param adcConversionCoeff ADC conversion coefficient - * @return temperature + * Outputs : temperatureValues + * @param avgADC average ADC value for given temperature sensor to convert + * @param gain gain value to apply + * @param refResistance resistance value to apply + * @param zeroDegResistance resistance value at zero degrees + * @return temperature (in degrees C) *************************************************************************/ static F32 getADC2TempConversion ( F32 avgADC, U32 gain, U32 refResistance, U32 zeroDegResistance, F32 adcConversionCoeff ) { @@ -457,7 +487,7 @@ * function to process the ADC value and covert it to temperature * @details * Inputs : none - * Outputs : Processed valid ADC reading + * Outputs : none * @param sensorIndex ID of temperature sensor to process * @param adc ADC value for the temperature sensor * @param fpgaError reported FPGA error status @@ -483,7 +513,7 @@ * process the ADC and convert it to temperature * @details * Inputs : none - * Outputs : Processed heater ADC reading + * Outputs : none * @param sensorIndex ID of temperature sensor to process * @param adc reported ADC value for temperature sensor * @param fpgaError reported error status by FPGA @@ -527,11 +557,11 @@ * and the ADC value is not the same as the previous ADC read, it returns a * TRUE, signaling that the ADC is valid to be processed. * @details - * Inputs : readCount - * Outputs : readCount, internalErrorCount - * @param sensorIndex Temperature sensor index - * @param fpgaError FPGA error count - * @param fpgaCount FPGA read count + * Inputs : readAndErrorCounts + * Outputs : readAndErrorCounts + * @param sensorIndex ID of temperature sensor to check + * @param fpgaError reported error status by FPGA + * @param fpgaCount reported read count by FPGA * @return isADCValid (BOOL) *************************************************************************/ static BOOL isADCReadValid ( U32 sensorIndex, U32 fpgaError, U32 fpgaCount ) @@ -574,10 +604,10 @@ * index and calculates the running sum and the moving average of the ADCs * The temperatureSensorsADCRead and tempSensorsAvgADCValues are updated * @details - * Inputs : adcNextIndex, rawADCReads, adcRunningSum - * Outputs : adcNextIndex, rawADCReads, adcRunningSum, temperatureValues - * @param sensorIndex Temperature sensor index - * @param adc adc reading from fpga + * Inputs : runningSumAndIndex, rawADCReads, sampleCount, temperatureValues + * Outputs : runningSumAndIndex, rawADCReads, sampleCount, temperatureValues + * @param sensorIndex ID of temperature sensor to process + * @param adc reported ADC value for temperature sensor * @return none *************************************************************************/ static void processADCRead ( U32 sensorIndex, S32 adc ) @@ -606,7 +636,7 @@ * The handleSelfTestStart function transitions the self test state to * check ADC * @details - * Inputs : tempSensorsSelfTestResult + * Inputs : none * Outputs : none * @return state (TEMPSENSORS_SELF_TEST_STATES_T) *************************************************************************/ @@ -622,7 +652,7 @@ * reads are above the maximum 24bit ADC count, it will throw an alarm and * switches to the next state * @details - * Inputs : TPi ADC reading from FPGA + * Inputs : none * Outputs : none * @return TEMPSENSORS_SELF_TEST_CONSISTENCY_CHECK (TEMPSENSORS_SELF_TEST_STATES_T) *************************************************************************/ @@ -646,8 +676,9 @@ * The handleSelfTestConsistencyCheck function checks the values of the * sensors to make sure they are within the allowed range from each other * @details - * Inputs : TPi and TPo ADC reading from FPGA + * Inputs : none * Outputs : none + * @param none * @return TEMPSENSORS_SELF_TEST_COMPLETE (TEMPSENSORS_SELF_TEST_STATES_T) *************************************************************************/ static TEMPSENSORS_SELF_TEST_STATES_T handleSelfTestConsistencyCheck ( void ) @@ -809,8 +840,8 @@ * @details * Inputs : temperatureValues * Outputs : temperatureValues - * @param sensorIndex Temperature sensor index - * @param temperature Temperature value to override if testing activated + * @param sensor ID of temperature sensor to override + * @param temperature override temperature value (in degrees C) * @return result *************************************************************************/ BOOL testSetMeasuredTemperatureOverride ( U32 sensorIndex, F32 temperature ) @@ -837,7 +868,7 @@ * @details * Inputs : temperatureValues * Outputs : temperatureValues - * @param sensorIndex Temperature sensor index + * @param sensor ID of temperature sensor to reset override * @return result *************************************************************************/ BOOL testResetMeasuredTemperatureOverride ( U32 sensorIndex )