Index: firmware/App/Controllers/Fans.c =================================================================== diff -u -r27d91d88b73aa4194cef1d3b08decc12ccdecc33 -rf6016459473bdb85aebe393c07cd580b973d7247 --- firmware/App/Controllers/Fans.c (.../Fans.c) (revision 27d91d88b73aa4194cef1d3b08decc12ccdecc33) +++ firmware/App/Controllers/Fans.c (.../Fans.c) (revision f6016459473bdb85aebe393c07cd580b973d7247) @@ -5,6 +5,7 @@ #include "Thermistors.h" #include "SystemCommMessages.h" #include "FPGA.h" +#include "PersistentAlarm.h" /** * @addtogroup Fans @@ -29,6 +30,8 @@ #define MIN_TARGET_RPM_IN_SELF_TEST 1000 ///< Fans min target RPM that they should be during POST. #define FANS_SELF_TEST_WAIT_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans self test wait time for the fans to get to RPM. #define FANS_SELF_TEST_TARGET_PWM 0.5 ///< Fans self test target PWM for testing the fans are running. +#define FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_COUNT ( ( 3 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) ///< Fans max allowed RPM out of range count. +#define FANS_MAX_ALLOWED_RPM 9000 ///< Fans max allowed RPM value. /// Fans self test states typedef enum fans_Self_Test @@ -78,7 +81,8 @@ static void setInletFansDutyCycle( F32 pwm ); static void setOutletFansDutyCycle( F32 pwm ); static F32 getMaximumTemperature( void ); -static void convertFansTogglePeriod2RPM( void ); +static void convertTogglePeriod2RPM( void ); +static void monitorFans( void ); static U32 getPublishFansDataInterval( void ); static void publishFansData( void ); @@ -94,11 +98,17 @@ void initFans( void ) { // Initialize the variables - fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST; - fansSelfTestReslt = SELF_TEST_STATUS_IN_PROGRESS; - fansSelfTestState = FANS_SELF_TEST_START; + fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST; + fansSelfTestReslt = SELF_TEST_STATUS_IN_PROGRESS; + fansSelfTestState = FANS_SELF_TEST_START; + fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST; fansControlCounter = 0; fansPublishCounter = 0; + + + // Initialize a persistent alarm for fans RPM out of range + initPersistentAlarm( PERSISTENT_ALARM_FANS_RPM_OUT_RANGE, ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE, + TRUE, FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_COUNT, FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_COUNT ); } /*********************************************************************//** @@ -159,8 +169,6 @@ break; } - convertFansTogglePeriod2RPM(); - publishFansData(); } @@ -200,11 +208,12 @@ static FANS_SELF_TEST_STATES_T handleSelfTestStart( void ) { FANS_SELF_TEST_STATES_T state = FANS_SELF_TEST_START; + U32 failureCount = 0; FANS_NAMES_T fan; // Get the raw toggle periods from FPGA and convert them to RPM. They all should be 0 upon staring // the device - convertFansTogglePeriod2RPM(); + convertTogglePeriod2RPM(); // Loop through all the fans to check their RPM // Upon starting the device the RPM of the fans should be 0 @@ -213,13 +222,23 @@ if ( fansStatus.rpm[ fan ] > 0 ) { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE, fan, fansStatus.rpm[ fan ] ); + failureCount++; } } - // Set the fans to the target PWM for the next stage - setInletFansDutyCycle( FANS_SELF_TEST_TARGET_PWM ); - setOutletFansDutyCycle( FANS_SELF_TEST_TARGET_PWM ); - state = FANS_SELF_TEST_CHECK_RPM; + // If there was a failure, go to complete + if ( failureCount > 0 ) + { + fansSelfTestReslt = SELF_TEST_STATUS_FAILED; + state = FAN_SELF_TEST_COMPLETE; + } + else + { + // Set the fans to the target PWM for the next stage + setInletFansDutyCycle( FANS_SELF_TEST_TARGET_PWM ); + setOutletFansDutyCycle( FANS_SELF_TEST_TARGET_PWM ); + state = FANS_SELF_TEST_CHECK_RPM; + } return state; } @@ -235,25 +254,38 @@ static FANS_SELF_TEST_STATES_T handleSelfTestCheckRPM( void ) { FANS_SELF_TEST_STATES_T state = FANS_SELF_TEST_CHECK_RPM; + U32 failureCount = 0; FANS_NAMES_T fan; // Wait for the fans to run for a certain period of time before checking their RPM if ( ++fansControlCounter > FANS_SELF_TEST_WAIT_INTERVAL ) { - convertFansTogglePeriod2RPM(); + convertTogglePeriod2RPM(); // Loop through all the fans to check their RPM. They should above the specified RPM for( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) { - if ( fansStatus.rpm[ fan ] > MIN_TARGET_RPM_IN_SELF_TEST ) + if ( fansStatus.rpm[ fan ] < MIN_TARGET_RPM_IN_SELF_TEST ) { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE, fan, fansStatus.rpm[ fan ] ); + failureCount++; } } // Turn off the fans, done with self test - setInletFansDutyCycle( 0 ); - setOutletFansDutyCycle( 0 ); + setInletFansDutyCycle( 0.0 ); + setOutletFansDutyCycle( 0.0 ); + + // If the failure count is greater than 0, fail POST + if ( failureCount > 0 ) + { + fansSelfTestReslt = SELF_TEST_STATUS_FAILED; + } + else + { + fansSelfTestReslt = SELF_TEST_STATUS_PASSED; + } + state = FAN_SELF_TEST_COMPLETE; } @@ -281,9 +313,11 @@ state = FANS_EXEC_STATE_RUN; } +#ifndef _VECTORCAST_ // To skip the wait for POST and start running. // TODO REMOVE state = FANS_EXEC_STATE_RUN; // TODO REMOVE +#endif return state; } @@ -348,6 +382,13 @@ setInletFansDutyCycle( fansStatus.targetDutyCycle ); setOutletFansDutyCycle( fansStatus.targetDutyCycle ); + // 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 RPM. + convertTogglePeriod2RPM(); + monitorFans(); + // Reset the counter fansControlCounter = 0; } @@ -414,68 +455,63 @@ /*********************************************************************//** * @brief - * The getFansRPM function runs through the list of the fans to get the - * FPGA pulse from them and converts them to RPM. + * The convertTogglePeriod2RPM function runs through the list of the fans + * to get the FPGA pulse from them and converts them to RPM. * @details Inputs: fansStatus, toggle2RPMCoefficient * @details Outputs: fansStatus * @return none ************************************************************************/ -static void convertFansTogglePeriod2RPM( void ) +static void convertTogglePeriod2RPM( void ) { FANS_NAMES_T fan; - U32 togglePeriod; + U32 togglePeriods[ NUM_OF_FANS_NAMES ]; - // Loop through the fans and get the pulse of each of them + togglePeriods[ FAN_INLET_1 ] = getFPGAInletFan1TogglePeriod(); + togglePeriods[ FAN_INLET_2 ] = getFPGAInletFan2TogglePeriod(); + togglePeriods[ FAN_INLET_3 ] = getFPGAInletFan3TogglePeriod(); + togglePeriods[ FAN_OUTLET_1 ] = getFPGAOutletFan1TogglePeriod(); + togglePeriods[ FAN_OUTLET_2 ] = getFPGAOutletFan2TogglePeriod(); + togglePeriods[ FAN_OUTLET_3 ] = getFPGAOutletFan3TogglePeriod(); + for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) { - switch ( fan ) - { - case FAN_INLET_1: - togglePeriod = getFPGAInletFan1TogglePeriod(); - break; - - case FAN_INLET_2: - togglePeriod = getFPGAInletFan2TogglePeriod(); - break; - - case FAN_INLET_3: - togglePeriod = getFPGAInletFan3TogglePeriod(); - break; - - case FAN_OUTLET_1: - togglePeriod = getFPGAOutletFan1TogglePeriod(); - break; - - case FAN_OUTLET_2: - togglePeriod = getFPGAOutletFan2TogglePeriod(); - break; - - case FAN_OUTLET_3: - togglePeriod = getFPGAOutletFan3TogglePeriod(); - break; - - default: - // Invalid fan has been selected, raise an alarm - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_FAN_SELECTED, fan ); - break; - } - // If the pulse is close to 0 or 0, FPGA will report 0xFFFF // Otherwise, convert the pulse to RPM - if ( togglePeriod == FANS_ZERO_RPM_TOGGLE_PERIOD_VALUE ) + if ( togglePeriods[ fan ] == FANS_ZERO_RPM_TOGGLE_PERIOD_VALUE ) { fansStatus.rpm[ fan ] = 0; } else { // Convert toggle period to RPM - fansStatus.rpm[ fan ] = toggle2RPMCoefficient / togglePeriod; + fansStatus.rpm[ fan ] = toggle2RPMCoefficient / togglePeriods[ fan ]; } } } /*********************************************************************//** * @brief + * The monitorFans function monitors the fans for RPM. + * @details Inputs: fansStatus + * @details Outputs: none + * @return none + *************************************************************************/ +static void monitorFans( void ) +{ + FANS_NAMES_T fan; + + for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) + { + // Call persistent alarm if a fan's RPM is out of range + if ( fansStatus.rpm[ fan ] >= FANS_MAX_ALLOWED_RPM ) + { + checkPersistentAlarm( PERSISTENT_ALARM_FANS_RPM_OUT_RANGE, TRUE, fansStatus.rpm[ fan ] ); + } + } +} + +/*********************************************************************//** + * @brief * The getPublishFansDataInterval function gets the fans data publish interval. * @details Inputs: fansPublishInterval * @details Outputs: none Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -r4d7d40a27130dc813d653f044cbb856b1b7d8481 -rf6016459473bdb85aebe393c07cd580b973d7247 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 4d7d40a27130dc813d653f044cbb856b1b7d8481) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision f6016459473bdb85aebe393c07cd580b973d7247) @@ -668,7 +668,7 @@ if ( ++trimmerHeaterTimerCounter >= CONTROLLER_CHECK_INTERVAL_COUNT ) { - F32 outletTemp = getTemperatureValue( TEMPSENSORS_OUTLET_REDUNDANCY ); + F32 outletTemp = getTemperatureValue( TEMPSENSORS_OUTLET_REDUNDANT ); trimmerHeaterDutyCycle = runPIController( PI_CONTROLLER_ID_TRIMMER_HEATER, trimmerHeaterTargetTemperature, outletTemp ); setTrimmerHeaterPWM( trimmerHeaterDutyCycle ); trimmerHeaterTimerCounter = 0; Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -r41c7186ac17200977b632102c9c6e3a07b3eb211 -rf6016459473bdb85aebe393c07cd580b973d7247 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 41c7186ac17200977b632102c9c6e3a07b3eb211) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision f6016459473bdb85aebe393c07cd580b973d7247) @@ -45,18 +45,14 @@ #define TRIMMER_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE 100U ///< Trimmer heater external temperature sensors zero degree resistance. #define TEMP_SENSORS_ADC_BITS 24U ///< External temperature sensors ADC bits. -#define TEMP_SENSORS_ADC_MAX_COUNT ( pow(2,TEMP_SENSORS_ADC_BITS) - 1 ) ///< Temperature sensors max ADC count. -#define TEMP_EQUATION_COEFF_A ( 3.9083 * pow( 10, -3 ) ) ///< ADC to temperature conversion coefficient A. -#define TEMP_EQUATION_COEFF_B ( -5.775 * pow( 10, -7 ) ) ///< ADC to temperature conversion coefficient B. - #define ADC_FPGA_READ_DELAY 30U ///< Delay in ms before reading the ADC values from FPGA. #define MAX_NUM_OF_RAW_ADC_SAMPLES 32U ///< Number of ADC reads for moving average calculations. #define MAX_ALLOWED_TEMP_DELTA_BETWEEN_SENSORS 2U ///< Maximum allowed temperature delta between sensors. #define MAX_ALLOWED_UNCHANGED_ADC_READS 4U ///< Maximum number of times that the read of a sensor cannot change. #define SHIFT_BITS_BY_2 2U ///< Shift bits by 2. #define SHIFT_BITS_BY_5_FOR_AVERAGING 5U ///< Shift the ADCs of the temperature sensors by 5 to average them. -#define INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD ( 5 * MS_PER_SECOND ) ///< Persistence period for temperature sensors out of range error. +#define INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT (5 * MS_PER_SECOND / TASK_GENERAL_INTERVAL) ///< Number of persistence count for temperature sensors out of range error. #define MIN_WATER_INPUT_TEMPERATURE 10U ///< Minimum water input temperature. #define MAX_WATER_INPUT_TEMPERATURE 35U ///< Maximum water input temperature. @@ -68,12 +64,17 @@ #define K_THERMOCOUPLE_TEMP_2_MILLI_VOLT_CONVERSION_COEFF 0.041276 ///< K thermocouple temperature to millivolt conversion coefficient. #define SIZE_OF_THERMOCOUPLE_COEFFICIENTS 10U ///< Size of the thermocouple coefficients. +#define CELSIUS_TO_KELVIN_CONVERSION 273.15 ///< Celsius to Kelvin temperature conversion. +#define ADC_BOARD_TEMP_SENSORS_CONVERSION_CONST 272.5 ///< ADC board temperature sensors conversion constant. +#define TWELVE_BIT_RESOLUTION 4096.0 ///< 12 bit resolution conversion. +#define ADC_BOARD_TEMP_SENSORS_CONST 0x800000 + #define EXTERNAL_TEMP_SENSORS_ERROR_VALUE 0x80 ///< External temperature sensors error value. #define HEATERS_INTERNAL_TEMP_SENSOR_FAULT 0x01 ///< Heaters internal temperature sensor fault. -#define TEMP_SENSORS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Temperature sensors publish data time interval. -#define MAX_TEMPERATURE_SENSOR_FAILURES 10 ///< Maximum number of temperature sensor errors within window period before alarm. -#define MAX_TEMPERATURE_SENSOR_FAILURE_WINDOW_MS ( 10 * MS_PER_SECOND ) ///< Temperature sensor error window. +#define TEMP_SENSORS_DATA_PUBLISH_INTERVAL (500 / TASK_PRIORITY_INTERVAL) ///< Temperature sensors publish data time interval. +#define MAX_TEMPERATURE_SENSOR_FAILURES 5 ///< Maximum number of temperature sensor errors within window period before alarm. +#define MAX_TEMPERATURE_SENSOR_FAILURE_WINDOW_MS (10 * MS_PER_SECOND) ///< Temperature sensor error window. /// Temperature sensor self-test states. typedef enum tempSensors_Self_Test_States @@ -118,8 +119,10 @@ static TEMPSENSORS_EXEC_STATES_T tempSensorsExecState; ///< TemperatureSensor exec state. static TEMP_SENSOR_T tempSensors [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors' data structure. +// From master static U32 elapsedTime; ///< Elapsed time variable. static U32 internalHeatersConversionTimer; ///< Conversion timer variable to calculate the heaters internal temperature. +// From master static F32 tempValuesForPublication [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors data publication array. static U32 dataPublicationTimerCounter; ///< Temperature sensors data publish timer counter. @@ -140,13 +143,18 @@ 0.971511471520E-22,-0.121047212750E-25 }; -///< Thermcouple inverse coefficient for positive cold junction temperature. +///< Thermocouple inverse coefficient for positive cold junction temperature. static const F32 positiveTCInverserCoeffs [ SIZE_OF_THERMOCOUPLE_COEFFICIENTS ] = { 0.0, 2.508355E1, 7.860106E-2, -2.503131E-1, 8.315270E-2, -1.228034E-2, 9.804036E-4, -4.413030E-5, 1.057734E-6, -1.052755E-8 }; +static const U32 tempSensorsADCMaxCount = ( 1 << TEMP_SENSORS_ADC_BITS ) - 1; ///< ADC 24 bit max count which is (2^24 - 1). +static const U32 tempEquationResistorCalc = 1 << ( TEMP_SENSORS_ADC_BITS - 1 ); ///< Temperature sensors resistor calculation (2^(24 - 1)) +static const F32 tempEquationCoeffA = 3.9083E-3; ///< ADC to temperature conversion coefficient A. +static const F32 tempEquationCoeffB = -5.775E-7; ///< ADC to temperature conversion coefficient B. + // ********** private function prototypes ********** static TEMPSENSORS_SELF_TEST_STATES_T handleSelfTestStart( void ); @@ -168,9 +176,13 @@ /*********************************************************************//** * @brief - * The initTemperatureSensors function initializes the module - * @details Inputs: none - * @details Outputs: TemperatureSensors module initialized + * The initTemperatureSensors function initializes the module.* + * @details Inputs: tempSensorsSelfTestState, tempSensorsExecState, + * elapsedTime, internalHeatersConversionTimer, dataPublicationTimerCounter, + * tempSensors + * @details Outputs: tempSensorsSelfTestState, tempSensorsExecState, + * elapsedTime, internalHeatersConversionTimer, dataPublicationTimerCounter, + * tempSensors * @return none *************************************************************************/ void initTemperatureSensors( void ) @@ -214,9 +226,9 @@ tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ].zeroDegreeResistance = COND_SENSORS_TEMP_SENSOR_0_DEGREE_RESISTANCE; // Initialize TRo and TDi constants - tempSensors[ TEMPSENSORS_OUTLET_REDUNDANCY ].gain = TRIMMER_HEATER_EXT_TEMP_SENSORS_GAIN; - tempSensors[ TEMPSENSORS_OUTLET_REDUNDANCY ].refResistance = TRIMMER_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; - tempSensors[ TEMPSENSORS_OUTLET_REDUNDANCY ].zeroDegreeResistance = TRIMMER_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; + tempSensors[ TEMPSENSORS_OUTLET_REDUNDANT ].gain = TRIMMER_HEATER_EXT_TEMP_SENSORS_GAIN; + tempSensors[ TEMPSENSORS_OUTLET_REDUNDANT ].refResistance = TRIMMER_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; + tempSensors[ TEMPSENSORS_OUTLET_REDUNDANT ].zeroDegreeResistance = TRIMMER_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; tempSensors[ TEMPSENSORS_INLET_DIALYSATE ].gain = TRIMMER_HEATER_EXT_TEMP_SENSORS_GAIN; tempSensors[ TEMPSENSORS_INLET_DIALYSATE ].refResistance = TRIMMER_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; @@ -230,16 +242,25 @@ tempSensors[ TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ].conversionCoef = HEATERS_COLD_JUNCTION_ADC_TO_TEMP_CONVERSION_COEFF; tempSensors[ TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ].conversionCoef = HEATERS_COLD_JUNCTION_ADC_TO_TEMP_CONVERSION_COEFF; - // Initialize the heaters calculated internal temperature sensors. The constants are zero since they will not be used for conversion + // FPGA board temperature conversion coefficient + tempSensors[ TEMPSENSORS_FPGA_BOARD_SENSOR ].conversionCoef = 503.975 / TWELVE_BIT_RESOLUTION; + // Board temperature sensors conversion coefficient + tempSensors[ TEMPSENSORS_LOAD_CELL_A1_B1 ].conversionCoef = 1.0 / 13584.0; + tempSensors[ TEMPSENSORS_LOAD_CELL_A2_B2 ].conversionCoef = 1.0 / 13584.0; + tempSensors[ TEMPSENSORS_INTERNAL_THDO_RTD ].conversionCoef = 1.0 / 13584.0; + tempSensors[ TEMPSENSORS_INTERNAL_TDI_RTD ].conversionCoef = 1.0 / 13584.0; + tempSensors[ TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR ].conversionCoef = 1.0 / 13584.0; + // 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 ); + initTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_TEMPERATURE_SENSOR_ERROR, MAX_TEMPERATURE_SENSOR_FAILURES, + MAX_TEMPERATURE_SENSOR_FAILURE_WINDOW_MS ); // Persistent alarms for inlet water high/low temperature initPersistentAlarm( PERSISTENT_ALARM_INLET_WATER_HIGH_TEMPERATURE, ALARM_ID_INLET_WATER_HIGH_TEMPERATURE, - FALSE, INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD, INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD ); + TRUE, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT ); initPersistentAlarm( PERSISTENT_ALARM_INLET_WATER_LOW_TEMPERATURE, ALARM_ID_INLET_WATER_LOW_TEMPERATURE, - FALSE, INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD, INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD ); + TRUE, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT ); } /*********************************************************************//** @@ -248,7 +269,7 @@ * POST during the self-test. * @details Inputs: tempSensorsSelfTestState * @details Outputs: tempSensorsSelfTestState - * @return tempSensorsSelfTestState + * @return tempSensorsSelfTestState which is the status of the self test *************************************************************************/ SELF_TEST_STATUS_T execTemperatureSensorsSelfTest( void ) { @@ -310,8 +331,8 @@ * @brief * The checkInletWaterTemperature checks inlet water temperature value * and triggers an alarm when temperature value is out of allowed range. - * @details Inputs: Inlet water temperature value - * @details Outputs: Trigger alarms when temperature is out of allowed range + * @details Inputs: none + * @details Outputs: none * @return none *************************************************************************/ void checkInletWaterTemperature( void ) @@ -326,11 +347,12 @@ /*********************************************************************//** * @brief - * The getTemperatureValue function gets the temperature of the requested sensor. - * @details Inputs: none + * The getTemperatureValue function gets the temperature of the requested + * sensor. + * @details Inputs: tempSensors * @details Outputs: none - * @param sensor temperature sensor index - * @return temperature + * @param sensorIndex which is the temperature sensor index + * @return temperature of the requested sensor *************************************************************************/ F32 getTemperatureValue( U32 sensorIndex ) { @@ -347,33 +369,39 @@ temperature = tempSensors[ sensorIndex ].temperatureValues.data; } } + else + { + // Wrong sensor was called, raise an alarm + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_TEMPERATURE_SENSOR_SELECTED, sensorIndex ); + } return temperature; } /*********************************************************************//** * @brief - * The getADC2TempConversion function calculates the temperature from ADC read from FPGA. - * @details Inputs: none + * The getADC2TempConversion function calculates the temperature from the + * moving average ADC samples. + * @details Inputs: tempEquationCoeffA, tempEquationCoeffB * @details Outputs: none - * @param avgADC Running average ADC + * @param avgADC moving average ADC * @param gain ADC gain * @param refResistance ADC reference resistance * @param zeroDegResistance ADC zero degree resistance * @param adcConversionCoeff ADC conversion coefficient - * @return temperature + * @return calculated temperature *************************************************************************/ static F32 getADC2TempConversion( F32 avgADC, U32 gain, U32 refResistance, U32 zeroDegResistance, F32 adcConversionCoeff ) { F32 temperature; if ( fabs( adcConversionCoeff ) < NEARLY_ZERO ) { - // R(RTD) = R(ref) * ( adc – 2^N - 1 ) / ( G * 2^N - 1 ); - F32 resistance = ( refResistance * ( avgADC - pow( 2,(TEMP_SENSORS_ADC_BITS - 1 ) ) ) ) / ( gain * pow( 2, ( TEMP_SENSORS_ADC_BITS - 1 ) ) ); + // R(RTD) = R(ref) * ( adc – 2^(N - 1) ) / ( G * 2^(N - 1) ); + F32 resistance = ( refResistance * ( avgADC - tempEquationResistorCalc ) ) / ( gain * tempEquationResistorCalc ); // T = (-A + √( A^2 - 4B * ( 1 - R_T / R_0 ) ) ) / 2B - F32 secondSqrtPart = 4 * TEMP_EQUATION_COEFF_B * (1 - ( resistance / zeroDegResistance ) ); - temperature = ( -TEMP_EQUATION_COEFF_A + sqrt( pow( TEMP_EQUATION_COEFF_A, 2 ) - secondSqrtPart ) ) / ( 2 * TEMP_EQUATION_COEFF_B ); + F32 secondSqrtPart = 4 * tempEquationCoeffB * (1 - ( resistance / zeroDegResistance ) ); + temperature = ( -tempEquationCoeffA + sqrt( pow( tempEquationCoeffA, 2 ) - secondSqrtPart ) ) / ( 2 * tempEquationCoeffB ); } else { @@ -385,9 +413,10 @@ /*********************************************************************//** * @brief - * The getHeaterInternalTemp function calculates the heaters' internal temperature. - * @details Inputs: temperatureValues - * @details Outputs: temperatureValues + * The getHeaterInternalTemp function calculates the heaters' internal + * temperature. + * @details Inputs: tempSensors + * @details Outputs: tempSensors * @param TCIndex thermocouple index * @param CJIndex cold junction index * @return none @@ -423,10 +452,11 @@ } else { - // TODO Alarm temperature = -1.0; + SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DG_HEATERS_NEGATIVE_COLD_JUNCTION_TEMPERATURE, CJTemp ) } + // Check which heater's internal temperature is being calculated if ( TCIndex == TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE ) { tempSensors[ TEMPSENSORS_PRIMARY_HEATER_INTERNAL ].temperatureValues.data = temperature; @@ -444,7 +474,7 @@ * to check if the read ADC is valid or not and if it is, it calls another * function to process the ADC value and covert it to temperature. * @details Inputs: none - * @details Outputs: Processed valid ADC reading + * @details Outputs: none * @param sensorIndex ID of temperature sensor to process * @param adc ADC value for the temperature sensor * @param fpgaError reported FPGA error status @@ -469,7 +499,7 @@ * check if the read ADC is valid and if it is, the function calls another function * process the ADC and convert it to temperature. * @details Inputs: none - * @details Outputs: Processed heater ADC reading + * @detailsOutputs: none * @param sensorIndex ID of temperature sensor to process * @param adc reported ADC value for temperature sensor * @param fpgaError reported error status by FPGA @@ -489,7 +519,7 @@ // so if the sign bit is 1, the sign bit is extended convertedADC = ( (S16)adcConv ) >> SHIFT_BITS_BY_2; } - else if ( ( sensorIndex == TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ) || (sensorIndex == TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ) ) + else if ( ( sensorIndex == TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ) || ( sensorIndex == TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ) ) { // Cast the adc from U32 to U16 and shift it by 4 adcConv = ( (U16)adc ) << SHIFT_BITS_BY_4; @@ -510,20 +540,18 @@ * count. If there is any FPGA, it raises an alarm. If the count has changed * 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 - * @details Outputs: readCount, internalErrorCount + * @details Inputs: tempSensors + * @details Outputs: tempSensors * @param sensorIndex Temperature sensor index * @param fpgaError FPGA error count * @param fpgaCount FPGA read count - * @return isADCValid (BOOL) + * @return returns TRUE if ADC was valid otherwise FALSE *************************************************************************/ static BOOL isADCReadValid( U32 sensorIndex, U32 fpgaError, U32 fpgaCount ) { BOOL isADCValid = FALSE; #ifndef _VECTORCAST_ - // TODO remove these two lines. Temporary set to true until FPGA error count is fixed - isADCValid = TRUE; - fpgaError = 0; + isADCValid = TRUE; // TODO remove this line. Temporary set to true until FPGA error count is fixed #endif if ( fpgaError == 0 ) { @@ -538,8 +566,7 @@ ++tempSensors[ sensorIndex ].internalErrorCount; if ( tempSensors[ sensorIndex ].internalErrorCount > MAX_ALLOWED_UNCHANGED_ADC_READS ) { - // TODO: Add back alarm when temperature sensor read count is stable - // SET_ALARM_WITH_1_U32_DATA( ALARM_ID_TEMPERATURE_SENSORS_FAULT, sensorIndex ); + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_TEMPERATURE_SENSORS_FAULT, sensorIndex ); } } } @@ -559,14 +586,16 @@ * The processADCRead function receives the ADC value and the sensor * index and calculates the running sum and the moving average of the ADCs * The temperatureSensorsADCRead and tempSensorsAvgADCValues are updated. - * @details Inputs: adcNextIndex, rawADCReads, adcRunningSum - * @details Outputs: adcNextIndex, rawADCReads, adcRunningSum, temperatureValues + * @details Inputs: tempSensors + * @details Outputs: tempSensors * @param sensorIndex Temperature sensor index - * @param adc adc reading from fpga + * @param adc adc reading from FPGA * @return none *************************************************************************/ static void processADCRead( U32 sensorIndex, S32 adc ) { + F32 temperature; + U32 const index = tempSensors[ sensorIndex ].adcNextIndex; S32 const indexValue = tempSensors[ sensorIndex ].rawADCReads [ index ]; @@ -577,21 +606,57 @@ // Calculate the average F32 const avgADCReads = tempSensors[ sensorIndex ].adcRunningSum >> SHIFT_BITS_BY_5_FOR_AVERAGING; - F32 const temperature = getADC2TempConversion( avgADCReads, - (U32)tempSensors [ sensorIndex ].gain, - (U32)tempSensors [ sensorIndex ].refResistance, - (U32)tempSensors [ sensorIndex ].zeroDegreeResistance, - tempSensors [ sensorIndex ].conversionCoef ); + // Different sensors have different ADC to temperature conversion methods + switch( sensorIndex ) + { + case TEMPSENSORS_INLET_PRIMARY_HEATER: + case TEMPSENSORS_OUTLET_PRIMARY_HEATER: + case TEMPSENSORS_CONDUCTIVITY_SENSOR_1: + case TEMPSENSORS_CONDUCTIVITY_SENSOR_2: + case TEMPSENSORS_OUTLET_REDUNDANT: + case TEMPSENSORS_INLET_DIALYSATE: + case TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE: + case TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE: + case TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION: + case TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION: + temperature = getADC2TempConversion( avgADCReads, (U32)tempSensors [ sensorIndex ].gain,(U32)tempSensors [ sensorIndex ].refResistance, + (U32)tempSensors [ sensorIndex ].zeroDegreeResistance, tempSensors [ sensorIndex ].conversionCoef ); + break; + case TEMPSENSORS_FPGA_BOARD_SENSOR: + // Temperature(C) = ((ADC x 503.975) / 4096) - 273.15 + // The value of 503.975/4096 has been calculated and stored in the conversion coefficient variable of the structure + temperature = ( avgADCReads * tempSensors[ sensorIndex ].conversionCoef ) - CELSIUS_TO_KELVIN_CONVERSION; + break; + + case TEMPSENSORS_LOAD_CELL_A1_B1: + case TEMPSENSORS_LOAD_CELL_A2_B2: + case TEMPSENSORS_INTERNAL_THDO_RTD: + case TEMPSENSORS_INTERNAL_TDI_RTD: + case TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR: + // Temperature(C) = ((ADC - 0x800000)/13584) - 272.5 + // The value 1/13584 has been calculated and stored in the conversion coefficient variable of the structure + temperature = ( ( avgADCReads - ADC_BOARD_TEMP_SENSORS_CONST ) * tempSensors[ sensorIndex ].conversionCoef ) - + ADC_BOARD_TEMP_SENSORS_CONVERSION_CONST; + break; + + default: + // Wrong sensor was called, raise an alarm + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_TEMPERATURE_SENSOR_SELECTED, sensorIndex ); + break; + } + + // Update the temperature tempSensors[ sensorIndex ].temperatureValues.data = temperature; } /*********************************************************************//** * @brief - * The handleSelfTestStart function transitions the self-test state to check ADC. + * The handleSelfTestStart function transitions the self-test state to + * check ADC. * @details Inputs: tempSensorsSelfTestResult * @details Outputs: none - * @return state (TEMPSENSORS_SELF_TEST_STATES_T) + * @return the next state of state machine *************************************************************************/ static TEMPSENSORS_SELF_TEST_STATES_T handleSelfTestStart( void ) { @@ -604,16 +669,17 @@ * The handleSelfTestADCCheck function checks whether the ADC reads. If the * 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 - * @details Outputs: none - * @return TEMPSENSORS_SELF_TEST_CONSISTENCY_CHECK (TEMPSENSORS_SELF_TEST_STATES_T) + * @details Inputs: tempSensorsSelfTestResult + * @details Outputs: tempSensorsSelfTestResult + * @return the next state of the state machine *************************************************************************/ static TEMPSENSORS_SELF_TEST_STATES_T handleSelfTestADCCheck( void ) { S32 const tpiADC = (S32)getFPGATPiTemp(); BOOL const isLessThanZero = tpiADC <= 0; - BOOL const isGreaterThanFullScale = tpiADC >= TEMP_SENSORS_ADC_MAX_COUNT; + BOOL const isGreaterThanFullScale = tpiADC >= tempSensorsADCMaxCount; + if ( isLessThanZero || isGreaterThanFullScale ) { tempSensorsSelfTestResult = SELF_TEST_STATUS_FAILED; @@ -627,9 +693,9 @@ * @brief * 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 - * @details Outputs: none - * @return TEMPSENSORS_SELF_TEST_COMPLETE (TEMPSENSORS_SELF_TEST_STATES_T) + * @details Inputs: tempSensors, tempSensorsSelfTestResult + * @details Outputs: tempSensorsSelfTestResult + * @return the next state of the state machine *************************************************************************/ static TEMPSENSORS_SELF_TEST_STATES_T handleSelfTestConsistencyCheck( void ) { @@ -648,6 +714,7 @@ tempSensors[ TEMPSENSORS_OUTLET_PRIMARY_HEATER ].conversionCoef ); F32 const tempDiff = fabs( tpiTemperature - tpoTemperature ); + if ( tempDiff > MAX_ALLOWED_TEMP_DELTA_BETWEEN_SENSORS ) { tempSensorsSelfTestResult = SELF_TEST_STATUS_FAILED; @@ -665,9 +732,9 @@ * @brief * The handleExecStart function waits for a period of time and switches to * the state that reads the ADC values from FPGA. - * @details Inputs: none + * @details Inputs: elapsedTime * @details Outputs: elapsedTime - * @return state (TEMPSENSORS_EXEC_STATES_T) + * @return the next state of the state machine *************************************************************************/ static TEMPSENSORS_EXEC_STATES_T handleExecStart( void ) { @@ -677,6 +744,7 @@ { elapsedTime = getMSTimerCount(); } + // A delay to let FPGA to boot up else if ( didTimeout( elapsedTime, ADC_FPGA_READ_DELAY ) ) { elapsedTime = 0; @@ -691,26 +759,34 @@ * The handleExecGetADCValues function reads the ADC values from FPGA and * at the specified time intervals and calls other functions to calculate * the internal temperature of the heaters. - * @details Inputs: none - * @details Outputs: internalHeatersConversionTimer, elapsedTime, temperatureValues - * @return state (TEMPSENSORS_EXEC_STATES_T) + * @details Inputs: internalHeatersConversionTimer + * @details Outputs: internalHeatersConversionTimer + * @return the next state of the state machine *************************************************************************/ static TEMPSENSORS_EXEC_STATES_T handleExecGetADCValues( void ) { - // Look at the error counter and the specific error flag to make sure the error is a temp sensor + // Look at the error counter and the specific error flag to make sure the error is a temperature sensor // Add a byte array to have bits for each sensor to find out exactly what sensor failed processTempSnsrsADCRead( TEMPSENSORS_INLET_PRIMARY_HEATER, getFPGATPiTemp(), getFPGARTDErrorCount(), getFPGARTDReadCount() ); processTempSnsrsADCRead( TEMPSENSORS_OUTLET_PRIMARY_HEATER, getFPGATPoTemp(), getFPGARTDErrorCount(), getFPGARTDReadCount() ); processTempSnsrsADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_1, getFPGACD1Temp(), getFPGARTDErrorCount(), getFPGARTDReadCount() ); processTempSnsrsADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_2, getFPGACD2Temp(), getFPGARTDErrorCount(), getFPGARTDReadCount() ); - processTempSnsrsADCRead( TEMPSENSORS_OUTLET_REDUNDANCY, getFPGATHDoTemp(), getFPGATHDoErrorCount(), getFPGATHDoReadCount() ); + processTempSnsrsADCRead( TEMPSENSORS_OUTLET_REDUNDANT, getFPGATHDoTemp(), getFPGATHDoErrorCount(), getFPGATHDoReadCount() ); processTempSnsrsADCRead( TEMPSENSORS_INLET_DIALYSATE, getFPGATDiTemp(), getFPGATDiErrorCount(), getFPGATDiReadCount() ); processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, getFPGAPrimaryHeaterTemp(), getFPGAPrimaryHeaterFlags(), getFPGAPrimaryHeaterReadCount() ); processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, getFPGATrimmerHeaterTemp(), getFPGATrimmerHeaterFlags(), getFPGATrimmerHeaterReadCount() ); processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION, getFPGAPrimaryColdJunctionTemp(), getFPGATrimmerHeaterFlags(), getFPGAPrimaryHeaterReadCount() ); processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION, getFPGATrimmerColdJunctionTemp(), getFPGATrimmerHeaterFlags(), getFPGATrimmerHeaterReadCount() ); + // TODO check the error and count functions for each FPGA read + processTempSnsrsADCRead( TEMPSENSORS_FPGA_BOARD_SENSOR, getFPGABoardTemp(), 0, 0 ); + processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A1_B1, getFPGALoadCellsA1B1Temp(), 0, 0 ); + processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A2_B2, getFPGALoadCellsA2B2Temp(), 0, 0 ); + processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_THDO_RTD, getFPGATHDoInternalTemp(), getFPGATHDoErrorCount(), getFPGATHDoReadCount() ); + processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_TDI_RTD, getFPGATDiInternalTemp(), getFPGATDiErrorCount(), getFPGATDiReadCount() ); + processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR, getFPGACondSnsrInternalTemp(), getFPGARTDErrorCount(), getFPGARTDReadCount() ); + // Check if time has elapsed to calculate the internal temperature of the heaters if ( ++internalHeatersConversionTimer >= HEATERS_INTERNAL_TEMPERTURE_CALCULATION_INTERVAL ) { @@ -730,7 +806,7 @@ * publication interval either from the data or from the override. * @details Inputs: tempSensorsPublishInterval * @details Outputs: none - * @return result + * @return data publish interval *************************************************************************/ static U32 getPublishTemperatureSensorsDataInterval( void ) { @@ -747,8 +823,8 @@ /*********************************************************************//** * @brief * The publishTemperatureSensorsData function broadcasts the temperature - * sensors data at the publication interval - * @details Inputs: dataPublicationTimerCounter, tempValuesForPublication + * sensors data at the publication interval. + * @detailsInputs: dataPublicationTimerCounter, tempValuesForPublication * @details Outputs: dataPublicationTimerCounter, tempValuesForPublication * @return none *************************************************************************/ @@ -758,10 +834,12 @@ { U32 i; + // Populate all the temperature values for ( i = 0; i < NUM_OF_TEMPERATURE_SENSORS; i++ ) { tempValuesForPublication[ i ] = getTemperatureValue ( i ); } + broadcastTemperatureSensorsData( (U08*)(&tempValuesForPublication), NUM_OF_TEMPERATURE_SENSORS * sizeof(F32) ); dataPublicationTimerCounter = 0; } @@ -777,11 +855,11 @@ * @brief * The testSetMeasuredTemperatureOverride function sets the override value * for a specific temperature sensor. - * @details Inputs: temperatureValues - * @details Outputs: temperatureValues + * @details Inputs: tempSensors + * @details Outputs: tempSensors * @param sensorIndex temperature sensor index - * @param temperature temperature value to override if testing activated - * @return result + * @param temperature temperature value to override if testing is activated + * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetMeasuredTemperatureOverride( U32 sensorIndex, F32 temperature ) { @@ -804,10 +882,10 @@ * @brief * The testSetMeasuredTemperatureOverride function resets the override value * of a specified temperature sensor. - * @details Inputs: temperatureValues - * @details Outputs: temperatureValues + * @details Inputs: tempSensors + * @details Outputs: tempSensors * @param sensorIndex temperature sensor index - * @return result + * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testResetMeasuredTemperatureOverride( U32 sensorIndex ) { @@ -832,8 +910,8 @@ * the temperature sensors publish data interval. * @details Inputs: tempSensorsPublishInterval * @details Outputs: tempSensorsPublishInterval - * @param value temperature sensor data broadcast interval (in ms) to override to - * @return result + * @param value sensors data broadcast interval (in ms) to override + * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetTemperatureSensorsPublishIntervalOverride( U32 value ) { @@ -857,7 +935,7 @@ * the override value of temperature sensors publish data interval. * @details Inputs: tempSensorsPublishInterval * @details Outputs: tempSensorsPublishInterval - * @return result + * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testResetTemperatureSensorsPublishIntervalOverride( void ) { Index: firmware/App/Controllers/TemperatureSensors.h =================================================================== diff -u -r54f45c387430e440ab4607451fc84dea61f273f1 -rf6016459473bdb85aebe393c07cd580b973d7247 --- firmware/App/Controllers/TemperatureSensors.h (.../TemperatureSensors.h) (revision 54f45c387430e440ab4607451fc84dea61f273f1) +++ firmware/App/Controllers/TemperatureSensors.h (.../TemperatureSensors.h) (revision f6016459473bdb85aebe393c07cd580b973d7247) @@ -23,6 +23,7 @@ /** * @defgroup TemperatureSensors TemperatureSensors * @brief Temperature Sensors driver module. Reads and processes the temperature sensors. + * TODO add the sensors hardware * * @addtogroup TemperatureSensors * @{ @@ -37,14 +38,20 @@ TEMPSENSORS_OUTLET_PRIMARY_HEATER, ///< Outlet primary heaters temperature sensor TEMPSENSORS_CONDUCTIVITY_SENSOR_1, ///< Conductivity sensor 1 temperature sensor TEMPSENSORS_CONDUCTIVITY_SENSOR_2, ///< Conductivity sensor 2 temperature sensor - TEMPSENSORS_OUTLET_REDUNDANCY, ///< Outlet redundancy temperature sensor + TEMPSENSORS_OUTLET_REDUNDANT, ///< Outlet redundant temperature sensor TEMPSENSORS_INLET_DIALYSATE, ///< Inlet dialysate temperature sensor TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, ///< Primary heaters internal temperature sensor TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, ///< Trimmer heater internal temperature sensor TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION, ///< Primary heaters cold junction temperature sensor TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION, ///< Trimmer heater cold junction temperature sensor TEMPSENSORS_PRIMARY_HEATER_INTERNAL, ///< Primary heaters internal temperature TEMPSENSORS_TRIMMER_HEATER_INTERNAL, ///< Trimmer heater internal temperature + TEMPSENSORS_FPGA_BOARD_SENSOR, ///< FPGA board temperature sensor + TEMPSENSORS_LOAD_CELL_A1_B1, ///< Load cell A1/B1 temperature sensor + TEMPSENSORS_LOAD_CELL_A2_B2, ///< Load cell A2/B2 temperature sensor + TEMPSENSORS_INTERNAL_THDO_RTD, ///< THDo RTD internal temperature sensor + TEMPSENSORS_INTERNAL_TDI_RTD, ///< TDi RTD internal temperature sensor + TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR, ///< Conductivity sensor temperature sensor NUM_OF_TEMPERATURE_SENSORS ///< Number of temperature sensors } TEMPERATURE_SENSORS_T; 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; Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -r27d91d88b73aa4194cef1d3b08decc12ccdecc33 -rf6016459473bdb85aebe393c07cd580b973d7247 --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 27d91d88b73aa4194cef1d3b08decc12ccdecc33) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision f6016459473bdb85aebe393c07cd580b973d7247) @@ -19,14 +19,16 @@ #include "lin.h" #include "ConcentratePumps.h" -#include "DrainPump.h" +#include "DrainPump.h" +#include "Fans.h" #include "Heaters.h" #include "OperationModes.h" #include "Reservoirs.h" #include "ROPump.h" #include "SystemComm.h" #include "SystemCommMessages.h" -#include "TaskGeneral.h" +#include "TaskGeneral.h" +#include "Thermistors.h" #include "WatchdogMgmt.h" /** Index: firmware/source/sys_main.c =================================================================== diff -u -ra726311564521affd46cbbaf129bdffb22e1d58f -rf6016459473bdb85aebe393c07cd580b973d7247 --- firmware/source/sys_main.c (.../sys_main.c) (revision a726311564521affd46cbbaf129bdffb22e1d58f) +++ firmware/source/sys_main.c (.../sys_main.c) (revision f6016459473bdb85aebe393c07cd580b973d7247) @@ -68,6 +68,7 @@ #include "ConcentratePumps.h" #include "CPLD.h" #include "DrainPump.h" +#include "Fans.h" #include "FPGA.h" #include "Heaters.h" #include "InternalADC.h" @@ -83,6 +84,7 @@ #include "SystemComm.h" #include "TaskBG.h" #include "TemperatureSensors.h" +#include "Thermistors.h" #include "Timers.h" #include "Valves.h" #include "WatchdogMgmt.h" @@ -183,6 +185,8 @@ initSystemComm(); initReservoirs(); initOperationModes(); + initFans(); + initThermistors(); } /*************************************************************************