Index: firmware/App/Controllers/Fans.c =================================================================== diff -u -rf6016459473bdb85aebe393c07cd580b973d7247 -r0b17c6271cdc3c55697a74ecaadb477d9c8f5687 --- firmware/App/Controllers/Fans.c (.../Fans.c) (revision f6016459473bdb85aebe393c07cd580b973d7247) +++ firmware/App/Controllers/Fans.c (.../Fans.c) (revision 0b17c6271cdc3c55697a74ecaadb477d9c8f5687) @@ -1,11 +1,12 @@ #include "etpwm.h" + #include "Fans.h" -#include "TaskGeneral.h" -#include "Thermistors.h" -#include "SystemCommMessages.h" #include "FPGA.h" #include "PersistentAlarm.h" +#include "SystemCommMessages.h" +#include "TaskGeneral.h" +#include "Thermistors.h" /** * @addtogroup Fans @@ -36,18 +37,18 @@ /// Fans self test states typedef enum fans_Self_Test { - FANS_SELF_TEST_START = 0, ///< Fans self test start state - FANS_SELF_TEST_CHECK_RPM, ///< Fans self test check RPM - FAN_SELF_TEST_COMPLETE, ///< Fans self test complete state - NUM_OF_SELF_TEST_STATES, ///< Number of fans self test + FANS_SELF_TEST_START_STATE = 0, ///< Fans self test start state + FANS_SELF_TEST_CHECK_RPM_STATE, ///< Fans self test check RPM state + FAN_SELF_TEST_COMPLETE_STATE, ///< Fans self test complete state + NUM_OF_SELF_TEST_STATES, ///< Number of fans self test } FANS_SELF_TEST_STATES_T; /// Fans exec states typedef enum fans_Exec_States { - FANS_EXEC_STATE_WAIT_FOR_POST = 0, ///< Fans exec state start - FANS_EXEC_STATE_RUN, ///< Fans exec state run - NUM_OF_FANS_EXEC_STATES, ///< Number of fans exec states + FANS_EXEC_STATE_WAIT_FOR_POST_STATE = 0, ///< Fans exec state start state + FANS_EXEC_STATE_RUN_STATE, ///< Fans exec state run state + NUM_OF_FANS_EXEC_STATES, ///< Number of fans exec states } FANS_EXEC_STATES_T; /// Fans status struct @@ -58,17 +59,17 @@ } FAN_STATUS_T; static FAN_STATUS_T fansStatus; ///< Fans status -static SELF_TEST_STATUS_T fansSelfTestReslt = SELF_TEST_STATUS_IN_PROGRESS; ///< Fans self test result -static FANS_SELF_TEST_STATES_T fansSelfTestState = FANS_SELF_TEST_START; ///< Fans self test state -static FANS_EXEC_STATES_T fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST; ///< Fans exec state +static SELF_TEST_STATUS_T fansSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; ///< Fans self test result +static FANS_SELF_TEST_STATES_T fansSelfTestState = FANS_SELF_TEST_START_STATE; ///< Fans self test state +static FANS_EXEC_STATES_T fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST_STATE; ///< Fans exec state static U32 fansControlCounter = 0; ///< Fans control interval counter static U32 fansPublishCounter = 0; ///< Fans data publish interval counter /// Temperature to duty cycle conversion slope (duty cycle not in percent) -static const F32 slope = ( FANS_MAX_DUTY_CYCLE - FANS_MIN_DUTY_CYCLE ) / ( MAX_ALLOWED_AMBINET_TEMPERATURE - MIN_ALLOWED_AMBIENT_TEMPERATURE ); +static const F32 SLOPE = ( FANS_MAX_DUTY_CYCLE - FANS_MIN_DUTY_CYCLE ) / ( MAX_ALLOWED_AMBINET_TEMPERATURE - MIN_ALLOWED_AMBIENT_TEMPERATURE ); /// FGPA Toggle to RPM conversion coefficient -static const F32 toggle2RPMCoefficient = SEC_PER_MIN / ( TOGGLE_PERIOD_RESOLUTION_SECONDS * ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION ); +static const F32 TOGGLE_PERIOD_2_RPM_COEFFICIENT = SEC_PER_MIN / ( TOGGLE_PERIOD_RESOLUTION_SECONDS * ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION ); static OVERRIDE_U32_T fansPublishInterval = { FANS_DATA_PUBLISH_INTERVAL, FANS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Fans publish time interval override @@ -98,14 +99,13 @@ 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; + fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST_STATE; + fansSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; + fansSelfTestState = FANS_SELF_TEST_START_STATE; + fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST_STATE; 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 ); @@ -122,26 +122,26 @@ { switch ( fansSelfTestState ) { - case FANS_SELF_TEST_START: + case FANS_SELF_TEST_START_STATE: fansSelfTestState = handleSelfTestStart(); break; - case FANS_SELF_TEST_CHECK_RPM: + case FANS_SELF_TEST_CHECK_RPM_STATE: fansSelfTestState = handleSelfTestCheckRPM(); break; - case FAN_SELF_TEST_COMPLETE: + case FAN_SELF_TEST_COMPLETE_STATE: // Done with POST. Do nothing break; default: // Wrong state called SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_FAN_INVALID_SELF_TEST_STATE, fansSelfTestState ); - fansSelfTestState = FAN_SELF_TEST_COMPLETE; + fansSelfTestState = FAN_SELF_TEST_COMPLETE_STATE; break; } - return fansSelfTestReslt; + return fansSelfTestResult; } /*********************************************************************//** @@ -155,17 +155,17 @@ { switch ( fansExecState ) { - case FANS_EXEC_STATE_WAIT_FOR_POST: + case FANS_EXEC_STATE_WAIT_FOR_POST_STATE: fansExecState = handleExecStateWaitForPOST(); break; - case FANS_EXEC_STATE_RUN: + case FANS_EXEC_STATE_RUN_STATE: fansExecState = handleExecStateRun(); break; default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_FAN_INVALID_EXEC_STATE, fansExecState ); - fansExecState = FANS_EXEC_STATE_RUN; + fansExecState = FANS_EXEC_STATE_RUN_STATE; break; } @@ -180,7 +180,7 @@ * @param selected fan to read its RPM * @return RPM of the selected fan *************************************************************************/ -F32 getFanRPM( FANS_NAMES_T fan ) +F32 getMeasuredFanRPM( FAN_NAMES_T fan ) { F32 rpm = 0.0; @@ -207,9 +207,9 @@ *************************************************************************/ static FANS_SELF_TEST_STATES_T handleSelfTestStart( void ) { - FANS_SELF_TEST_STATES_T state = FANS_SELF_TEST_START; + FANS_SELF_TEST_STATES_T state; U32 failureCount = 0; - FANS_NAMES_T fan; + FAN_NAMES_T fan; // Get the raw toggle periods from FPGA and convert them to RPM. They all should be 0 upon staring // the device @@ -229,15 +229,15 @@ // If there was a failure, go to complete if ( failureCount > 0 ) { - fansSelfTestReslt = SELF_TEST_STATUS_FAILED; - state = FAN_SELF_TEST_COMPLETE; + fansSelfTestResult = SELF_TEST_STATUS_FAILED; + state = FAN_SELF_TEST_COMPLETE_STATE; } 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; + state = FANS_SELF_TEST_CHECK_RPM_STATE; } return state; @@ -253,13 +253,16 @@ *************************************************************************/ 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; + FANS_SELF_TEST_STATES_T state = FANS_SELF_TEST_CHECK_RPM_STATE; + FAN_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 ) { + // Assuming the test will pass + fansSelfTestResult = SELF_TEST_STATUS_PASSED; + convertTogglePeriod2RPM(); // Loop through all the fans to check their RPM. They should above the specified RPM @@ -268,25 +271,16 @@ 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++; + + fansSelfTestResult = SELF_TEST_STATUS_FAILED; } } // Turn off the fans, done with self test 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; + state = FAN_SELF_TEST_COMPLETE_STATE; } return state; @@ -302,20 +296,20 @@ *************************************************************************/ static FANS_EXEC_STATES_T handleExecStateWaitForPOST( void ) { - FANS_EXEC_STATES_T state = FANS_EXEC_STATE_WAIT_FOR_POST; + FANS_EXEC_STATES_T state = FANS_EXEC_STATE_WAIT_FOR_POST_STATE; // Wait for the self test to finish before starting the fans - if ( fansSelfTestState == FAN_SELF_TEST_COMPLETE ) + if ( fansSelfTestState == FAN_SELF_TEST_COMPLETE_STATE ) { // Start the fans with minimum PWM. The control will decide the next PWM automatically. setInletFansDutyCycle( FANS_MIN_DUTY_CYCLE ); setOutletFansDutyCycle( FANS_MIN_DUTY_CYCLE ); - state = FANS_EXEC_STATE_RUN; + state = FANS_EXEC_STATE_RUN_STATE; } #ifndef _VECTORCAST_ // To skip the wait for POST and start running. // TODO REMOVE - state = FANS_EXEC_STATE_RUN; + state = FANS_EXEC_STATE_RUN_STATE; // TODO REMOVE #endif return state; @@ -331,11 +325,14 @@ *************************************************************************/ static FANS_EXEC_STATES_T handleExecStateRun( void ) { - FANS_EXEC_STATES_T state = FANS_EXEC_STATE_RUN; + FANS_EXEC_STATES_T state = FANS_EXEC_STATE_RUN_STATE; // Check if it is time to check for the control if( ++fansControlCounter > FANS_CONTROL_INTERVAL ) { + // Monitor is called here to use the counter of the control + monitorFans(); + // Get the maximum temperature among all the thermistors and temperature sensors to run fan from the hottest temperature F32 temperature = getMaximumTemperature(); @@ -344,10 +341,9 @@ //TODO REMOVE FOR TESTING only // Solve the linear equation to calculate the duty cycle from temperature - F32 dutyCycle = slope * ( temperature - MIN_ALLOWED_AMBIENT_TEMPERATURE ) + FANS_MIN_DUTY_CYCLE; + F32 dutyCycle = SLOPE * ( temperature - MIN_ALLOWED_AMBIENT_TEMPERATURE ) + FANS_MIN_DUTY_CYCLE; - // Check whether the duty cycle is not outside of the range - // and cap it if needed + // Check whether the duty cycle is not outside of the range and cap it if needed if ( dutyCycle < FANS_MIN_DUTY_CYCLE ) { dutyCycle = FANS_MIN_DUTY_CYCLE; @@ -382,13 +378,6 @@ 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; } @@ -463,7 +452,7 @@ ************************************************************************/ static void convertTogglePeriod2RPM( void ) { - FANS_NAMES_T fan; + FAN_NAMES_T fan; U32 togglePeriods[ NUM_OF_FANS_NAMES ]; togglePeriods[ FAN_INLET_1 ] = getFPGAInletFan1TogglePeriod(); @@ -484,7 +473,7 @@ else { // Convert toggle period to RPM - fansStatus.rpm[ fan ] = toggle2RPMCoefficient / togglePeriods[ fan ]; + fansStatus.rpm[ fan ] = TOGGLE_PERIOD_2_RPM_COEFFICIENT / togglePeriods[ fan ]; } } } @@ -498,12 +487,14 @@ *************************************************************************/ static void monitorFans( void ) { - FANS_NAMES_T fan; + FAN_NAMES_T fan; + convertTogglePeriod2RPM(); + 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 ) + if ( fansStatus.rpm[ fan ] >= FANS_MAX_ALLOWED_RPM || fansStatus.rpm[ fan ] <= NEARLY_ZERO ) { checkPersistentAlarm( PERSISTENT_ALARM_FANS_RPM_OUT_RANGE, TRUE, fansStatus.rpm[ fan ] ); } @@ -543,7 +534,7 @@ { FANS_DATA_T fansData; - fansData.fansTargetPWM = fansStatus.targetDutyCycle * 100; + fansData.fansTargetDutyCycle = fansStatus.targetDutyCycle * FRACTION_TO_PERCENT_FACTOR; fansData.fanInlet1RPM = fansStatus.rpm[ FAN_INLET_1 ]; fansData.fanInlet2RPM = fansStatus.rpm[ FAN_INLET_2 ]; fansData.fanInlet3RPM = fansStatus.rpm[ FAN_INLET_3 ]; Index: firmware/App/Controllers/Fans.h =================================================================== diff -u -r27d91d88b73aa4194cef1d3b08decc12ccdecc33 -r0b17c6271cdc3c55697a74ecaadb477d9c8f5687 --- firmware/App/Controllers/Fans.h (.../Fans.h) (revision 27d91d88b73aa4194cef1d3b08decc12ccdecc33) +++ firmware/App/Controllers/Fans.h (.../Fans.h) (revision 0b17c6271cdc3c55697a74ecaadb477d9c8f5687) @@ -13,7 +13,7 @@ */ /// Fans names -typedef enum fans_Name +typedef enum DG_fans { FAN_INLET_1 = 0, ///< Fan inlet 1 FAN_INLET_2, ///< Fan inlet 2 @@ -22,12 +22,12 @@ FAN_OUTLET_2, ///< Fan outlet 2 FAN_OUTLET_3, ///< Fan outlet 3 NUM_OF_FANS_NAMES ///< Number of fans names -} FANS_NAMES_T; +} FAN_NAMES_T; /// Fans data publish typedef struct { - F32 fansTargetPWM; ///< Fans target PWM + F32 fansTargetDutyCycle; ///< Fans target duty cycle F32 fanInlet1RPM; ///< Fan inlet 1 RPM F32 fanInlet2RPM; ///< Fan inlet 2 RPM F32 fanInlet3RPM; ///< Fan inlet 3 RPM @@ -42,7 +42,7 @@ void execFans( void ); -F32 getFanRPM( FANS_NAMES_T fan ); +F32 getMeasuredFanRPM( FAN_NAMES_T fan ); BOOL testSetFanPublishIntervalOverride( U32 value ); BOOL testResetFanPublishIntervalOverride( void ); Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -rf6016459473bdb85aebe393c07cd580b973d7247 -r0b17c6271cdc3c55697a74ecaadb477d9c8f5687 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision f6016459473bdb85aebe393c07cd580b973d7247) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 0b17c6271cdc3c55697a74ecaadb477d9c8f5687) @@ -47,12 +47,19 @@ #define TEMP_SENSORS_ADC_BITS 24U ///< External temperature sensors ADC bits. #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. +// TODO remove after testing +//#define MAX_NUM_OF_RAW_ADC_SAMPLES 32U ///< Number of ADC reads for moving average calculations. +// TODO remove after testing +#define MAX_NUM_OF_RAW_ADC_SAMPLES 4U ///< 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_COUNT (5 * MS_PER_SECOND / TASK_GENERAL_INTERVAL) ///< Number of persistence count for temperature sensors out of range error. +// TODO remove after testing +//#define SHIFT_BITS_BY_5_FOR_AVERAGING 5U ///< Shift the ADCs of the temperature sensors by 5 to average them. +// TODO remove after testing +#define SHIFT_BITS_BY_2_FOR_AVERAGING 2U ///< Shift the ADCs of the temperature sensors by 2 to average them. +#define INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD ( ( 5 * MS_PER_SECOND ) / \ + TASK_GENERAL_INTERVAL ) ///< Persistence period 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. @@ -66,15 +73,20 @@ #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 TWELVE_BIT_RESOLUTION 4096U ///< 12 bit resolution conversion. +#define ADC_BOARD_TEMP_SENSORS_CONST 0x800000 ///< ADC board temperature sensors constant. #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 (500 / TASK_PRIORITY_INTERVAL) ///< Temperature sensors publish data time interval. +#define TEMP_SENSORS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Temperature sensors publish data time interval. +// TODo Remove after testing #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. +#define MAX_TEMPERATURE_SENSOR_FAILURE_WINDOW_MS ( 10 * MS_PER_SECOND ) ///< Temperature sensor error window. +// TODO remove after testing. Persistent alarm was placed instead +#define TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_COUNT ( ( 5 * MS_PER_SECOND ) / \ + TASK_PRIORITY_INTERVAL ) ///< Temperature sensors FPGA error persistent count. +#define FPGA_RAW_ADC_READ_INTERVAL_COUNT 8U ///< Time interval in counts to read the raw ADC reads from FPGA. /// Temperature sensor self-test states. typedef enum tempSensors_Self_Test_States @@ -118,23 +130,25 @@ static TEMPSENSORS_SELF_TEST_STATES_T tempSensorsSelfTestState; ///< TemperatureSensor self-test state. static TEMPSENSORS_EXEC_STATES_T tempSensorsExecState; ///< TemperatureSensor exec state. static TEMP_SENSOR_T tempSensors [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors' data structure. +static U32 fpgaRawADCReadInterval = 0; ///< FPGA raw ADC read interval count. +static U32 fpgaBoardTempReadCount = 0; ///< FPGA board temperature read count. -// From master +// From master TODO check these static U32 elapsedTime; ///< Elapsed time variable. static U32 internalHeatersConversionTimer; ///< Conversion timer variable to calculate the heaters internal temperature. -// From master +// From master TODO check these 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, TEMP_SENSORS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Temperature sensors publish time interval override. -static const F32 positiveTCExpA0 = 0.118597600000E0; ///< K TC positive temperature exponent coefficient A0. -static const F32 positiveTCExpA1 = -0.118343200000E-3; ///< K TC positive temperature exponent coefficient A1. -static const F32 positiveTCExpA2 = 0.126968600000E3; ///< K TC positive temperature exponent coefficient A2. +static const F32 POSITIVE_TC_EXP_A0 = 0.118597600000E0; ///< K TC positive temperature exponent coefficient A0. +static const F32 POSITIVE_TC_EXP_A1 = -0.118343200000E-3; ///< K TC positive temperature exponent coefficient A1. +static const F32 POSITIVE_TC_EXP_A2 = 0.126968600000E3; ///< K TC positive temperature exponent coefficient A2. ///< Thermocouple correction coefficients for positive cold junction temperature. -static const F32 positiveTCCoeffs [ SIZE_OF_THERMOCOUPLE_COEFFICIENTS ] = +static const F32 POSITIVE_TC_COEFFS [ SIZE_OF_THERMOCOUPLE_COEFFICIENTS ] = { -0.176004136860E-1, 0.389212049750E-1, 0.185587700320E-4, -0.994575928740E-7, @@ -144,16 +158,16 @@ }; ///< Thermocouple inverse coefficient for positive cold junction temperature. -static const F32 positiveTCInverserCoeffs [ SIZE_OF_THERMOCOUPLE_COEFFICIENTS ] = +static const F32 POSITIVE_TC_INVERSER_COEFFS [ 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. +static const U32 TEMP_SENSORS_ADC_MAX_COUNT = ( 1 << TEMP_SENSORS_ADC_BITS ) - 1; ///< ADC 24 bit max count which is (2^24 - 1). +static const U32 TEMP_EQUATION_RESISTOR_CALC = 1 << ( TEMP_SENSORS_ADC_BITS - 1 ); ///< Temperature sensors resistor calculation (2^(24 - 1)). +static const F32 TEMP_EQUATION_COEFF_A = 3.9083E-3; ///< ADC to temperature conversion coefficient A. +static const F32 TEMP_EQUATION_COEFF_b = -5.775E-7; ///< ADC to temperature conversion coefficient B. // ********** private function prototypes ********** @@ -179,20 +193,24 @@ * The initTemperatureSensors function initializes the module.* * @details Inputs: tempSensorsSelfTestState, tempSensorsExecState, * elapsedTime, internalHeatersConversionTimer, dataPublicationTimerCounter, - * tempSensors + * tempSensors, fpgaRawADCReadInterval * @details Outputs: tempSensorsSelfTestState, tempSensorsExecState, * elapsedTime, internalHeatersConversionTimer, dataPublicationTimerCounter, - * tempSensors + * tempSensors, fpgaRawADCReadInterval * @return none *************************************************************************/ void initTemperatureSensors( void ) { U08 i; + + // Initialize the variables tempSensorsSelfTestState = TEMPSENSORS_SELF_TEST_START; tempSensorsExecState = TEMPSENSORS_EXEC_STATE_START; elapsedTime = 0; internalHeatersConversionTimer = 0; dataPublicationTimerCounter = 0; + fpgaRawADCReadInterval = 0; + fpgaBoardTempReadCount = 0; /* NOTE: The temperature sensors do not have conversion coefficient. * The conversion coefficients are used for the heaters internal temperature sensors and @@ -208,31 +226,31 @@ } // Initialize TPi and TPo constants - tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].gain = PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN; - tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].refResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; - tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].zeroDegreeResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; + tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].gain = PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN; + tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].refResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; + tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].zeroDegreeResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; - tempSensors[ TEMPSENSORS_OUTLET_PRIMARY_HEATER ].gain = PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN; - tempSensors[ TEMPSENSORS_OUTLET_PRIMARY_HEATER ].refResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; - tempSensors[ TEMPSENSORS_OUTLET_PRIMARY_HEATER ].zeroDegreeResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; + tempSensors[ TEMPSENSORS_OUTLET_PRIMARY_HEATER ].gain = PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN; + tempSensors[ TEMPSENSORS_OUTLET_PRIMARY_HEATER ].refResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; + tempSensors[ TEMPSENSORS_OUTLET_PRIMARY_HEATER ].zeroDegreeResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; // Initialize TD1 and TD2 constants - tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_1 ].gain = COND_SENSORS_TEMP_SENSOR_GAIN; - tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_1 ].refResistance = COND_SENSORS_TEMP_SENSOR_REF_RESISTANCE; - tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_1 ].zeroDegreeResistance = COND_SENSORS_TEMP_SENSOR_0_DEGREE_RESISTANCE; + tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_1 ].gain = COND_SENSORS_TEMP_SENSOR_GAIN; + tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_1 ].refResistance = COND_SENSORS_TEMP_SENSOR_REF_RESISTANCE; + tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_1 ].zeroDegreeResistance = COND_SENSORS_TEMP_SENSOR_0_DEGREE_RESISTANCE; - tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ].gain = COND_SENSORS_TEMP_SENSOR_GAIN; - tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ].refResistance = COND_SENSORS_TEMP_SENSOR_REF_RESISTANCE; - tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ].zeroDegreeResistance = COND_SENSORS_TEMP_SENSOR_0_DEGREE_RESISTANCE; + tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ].gain = COND_SENSORS_TEMP_SENSOR_GAIN; + tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ].refResistance = COND_SENSORS_TEMP_SENSOR_REF_RESISTANCE; + tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ].zeroDegreeResistance = COND_SENSORS_TEMP_SENSOR_0_DEGREE_RESISTANCE; // Initialize TRo and TDi constants - 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_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; - tempSensors[ TEMPSENSORS_INLET_DIALYSATE ].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; + tempSensors[ TEMPSENSORS_INLET_DIALYSATE ].zeroDegreeResistance = TRIMMER_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; // Initialize the heaters internal thermocouples constants tempSensors[ TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE ].conversionCoef = HEATERS_INTERNAL_TC_ADC_TO_TEMP_CONVERSION_COEFF; @@ -243,24 +261,39 @@ tempSensors[ TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ].conversionCoef = HEATERS_COLD_JUNCTION_ADC_TO_TEMP_CONVERSION_COEFF; // FPGA board temperature conversion coefficient - tempSensors[ TEMPSENSORS_FPGA_BOARD_SENSOR ].conversionCoef = 503.975 / TWELVE_BIT_RESOLUTION; + tempSensors[ TEMPSENSORS_FPGA_BOARD_SENSOR ].conversionCoef = 503.975 / (F32)TWELVE_BIT_RESOLUTION; + F32 const conversionCoeff = 1.0 / 13584.0; + // 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; + tempSensors[ TEMPSENSORS_LOAD_CELL_A1_B1 ].conversionCoef = conversionCoeff; + tempSensors[ TEMPSENSORS_LOAD_CELL_A2_B2 ].conversionCoef = conversionCoeff; + tempSensors[ TEMPSENSORS_INTERNAL_THDO_RTD ].conversionCoef = conversionCoeff; + tempSensors[ TEMPSENSORS_INTERNAL_TDI_RTD ].conversionCoef = conversionCoeff; + tempSensors[ TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR ].conversionCoef = conversionCoeff; + // TODO Test the persistent alarm and remove this // 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 ); + // TODO test the persistent alarm and remove this // Persistent alarms for inlet water high/low temperature initPersistentAlarm( PERSISTENT_ALARM_INLET_WATER_HIGH_TEMPERATURE, ALARM_ID_INLET_WATER_HIGH_TEMPERATURE, - TRUE, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT ); + TRUE, INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD, INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD ); initPersistentAlarm( PERSISTENT_ALARM_INLET_WATER_LOW_TEMPERATURE, ALARM_ID_INLET_WATER_LOW_TEMPERATURE, - TRUE, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT, INLET_WATER_TEMPERATURE_PERSISTENCE_COUNT ); + TRUE, INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD, INLET_WATER_TEMPERATURE_PERSISTENCE_PERIOD ); + + // Persistent alarm for temperature sensors internal error + // When the FPGA read count does not increment for a period of time, it is considered as an internal error of the temperature sensors + // driver. This is internal because FPGA does not error out if the FPGA read count does not increment. + initPersistentAlarm( PERSISTENT_ALARM_TEMP_SENSORS_INTERNAL_ERROR, ALARM_ID_TEMPERATURE_SENSORS_FAULT, + TRUE, MAX_ALLOWED_UNCHANGED_ADC_READS, MAX_ALLOWED_UNCHANGED_ADC_READS ); + + // Persistent alarm for temperature sensors FPGA error + // This is FPGA error which is read from FPGA and it should be 0. If it is not 0 for a period of time, an alarm is raised. + initPersistentAlarm( PERSISTENT_ALARM_TEMP_SENSORS_FPGA_ERROR, ALARM_ID_TEMPERATURE_SENSORS_FAULT, TRUE, + TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_COUNT, TEMPERATURE_SENSORS_FPGA_ERROR_PERSISTENT_COUNT ); } /*********************************************************************//** @@ -292,7 +325,8 @@ break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_TEMPERATURE_SENSORS_INVALID_SELF_TEST_STATE, tempSensorsSelfTestState ); + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_TEMPERATURE_SENSORS_INVALID_SELF_TEST_STATE, + tempSensorsSelfTestState ); tempSensorsSelfTestState = TEMPSENSORS_SELF_TEST_COMPLETE; break; } @@ -325,6 +359,9 @@ tempSensorsExecState = TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES; break; } + + // Publish the data + publishTemperatureSensorsData(); } /*********************************************************************//** @@ -398,10 +435,10 @@ if ( fabs( adcConversionCoeff ) < NEARLY_ZERO ) { // R(RTD) = R(ref) * ( adc – 2^(N - 1) ) / ( G * 2^(N - 1) ); - F32 resistance = ( refResistance * ( avgADC - tempEquationResistorCalc ) ) / ( gain * tempEquationResistorCalc ); + F32 resistance = ( refResistance * ( avgADC - TEMP_EQUATION_RESISTOR_CALC ) ) / ( gain * TEMP_EQUATION_RESISTOR_CALC ); // T = (-A + √( A^2 - 4B * ( 1 - R_T / R_0 ) ) ) / 2B - F32 secondSqrtPart = 4 * tempEquationCoeffB * (1 - ( resistance / zeroDegResistance ) ); - temperature = ( -tempEquationCoeffA + sqrt( pow( tempEquationCoeffA, 2 ) - secondSqrtPart ) ) / ( 2 * tempEquationCoeffB ); + 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 ); } else { @@ -423,6 +460,18 @@ *************************************************************************/ static void getHeaterInternalTemp( U32 TCIndex, U32 CJIndex ) { + /* voltage = 0.041276 * ( cold junction temp - thermo-couple temp ) + * E = Ci * T^i + a0 * exp( a1 * ( T - a2 ) ^ 2 ) + * i is the positive thermo-couple coefficients + * a0 is the positive thermo-couple coefficient + * a1 is the positive thermo-couple coefficient + * a2 is the positive thermo-couple coefficient + * E = voltage + E (E is the corrected voltage) + * Temperature = di * E^i + * d is positive inverse thermo-couple coefficient + * E is corrected voltage + */ + F32 temperature = 0.0; F32 equiVoltage = 0.0; F32 correctedVoltage = 0.0; @@ -438,16 +487,16 @@ { for ( i = 0; i < SIZE_OF_THERMOCOUPLE_COEFFICIENTS; i++ ) { - equiVoltage = equiVoltage + ( positiveTCCoeffs[ i ] * pow( CJTemp, i ) ); + equiVoltage = equiVoltage + ( POSITIVE_TC_COEFFS[ i ] * pow( CJTemp, i ) ); } - equiVoltage = equiVoltage + ( positiveTCExpA0 * ( exp( positiveTCExpA1 * pow( ( CJTemp - positiveTCExpA2 ), 2 ) ) ) ); + equiVoltage = equiVoltage + ( POSITIVE_TC_EXP_A0 * ( exp( POSITIVE_TC_EXP_A1 * pow( ( CJTemp - POSITIVE_TC_EXP_A2 ), 2 ) ) ) ); correctedVoltage = rawVoltage + equiVoltage; for ( i = 0; i < SIZE_OF_THERMOCOUPLE_COEFFICIENTS; i++ ) { - temperature = temperature + ( positiveTCInverserCoeffs[ i ] * pow( correctedVoltage, i ) ); + temperature = temperature + ( POSITIVE_TC_INVERSER_COEFFS[ i ] * pow( correctedVoltage, i ) ); } } else @@ -550,32 +599,39 @@ static BOOL isADCReadValid( U32 sensorIndex, U32 fpgaError, U32 fpgaCount ) { BOOL isADCValid = FALSE; -#ifndef _VECTORCAST_ - isADCValid = TRUE; // TODO remove this line. Temporary set to true until FPGA error count is fixed -#endif +//#ifndef _VECTORCAST_ +// isADCValid = TRUE; // TODO remove this line. Temporary set to true until FPGA error count is fixed + //THIS ISSUE HAS BEEN FIXED. TRY IT. +//#endif if ( fpgaError == 0 ) { if ( tempSensors[ sensorIndex ].readCount != fpgaCount ) { tempSensors[ sensorIndex ].readCount = fpgaCount; - tempSensors[ sensorIndex ].internalErrorCount = 0; + //tempSensors[ sensorIndex ].internalErrorCount = 0; TODO do we need this any more? isADCValid = TRUE; } else { + checkPersistentAlarm( PERSISTENT_ALARM_TEMP_SENSORS_INTERNAL_ERROR, TRUE, sensorIndex ); + /* TODO test and figure out if this is right ++tempSensors[ sensorIndex ].internalErrorCount; if ( tempSensors[ sensorIndex ].internalErrorCount > MAX_ALLOWED_UNCHANGED_ADC_READS ) { SET_ALARM_WITH_1_U32_DATA( ALARM_ID_TEMPERATURE_SENSORS_FAULT, sensorIndex ); } + */ } } else { + checkPersistentAlarm( PERSISTENT_ALARM_TEMP_SENSORS_FPGA_ERROR, TRUE, fpgaError ); + /* TODO test and remove these lines. if ( TRUE == incTimeWindowedCount( TIME_WINDOWED_COUNT_FPGA_TEMPERATURE_SENSOR_ERROR ) ) { SET_ALARM_WITH_1_U32_DATA( ALARM_ID_TEMPERATURE_SENSORS_FAULT, sensorIndex ); } + */ } return isADCValid; @@ -600,11 +656,11 @@ S32 const indexValue = tempSensors[ sensorIndex ].rawADCReads [ index ]; tempSensors[ sensorIndex ].rawADCReads[ index ] = adc; - tempSensors[ sensorIndex ].adcNextIndex = INC_WRAP( index, 0, MAX_NUM_OF_RAW_ADC_SAMPLES - 1 ); - tempSensors[ sensorIndex ].adcRunningSum = tempSensors[ sensorIndex ].adcRunningSum - indexValue + adc; + tempSensors[ sensorIndex ].adcNextIndex = INC_WRAP( index, 0, MAX_NUM_OF_RAW_ADC_SAMPLES - 1 ); + tempSensors[ sensorIndex ].adcRunningSum = tempSensors[ sensorIndex ].adcRunningSum - indexValue + adc; // Calculate the average - F32 const avgADCReads = tempSensors[ sensorIndex ].adcRunningSum >> SHIFT_BITS_BY_5_FOR_AVERAGING; + F32 const avgADCReads = tempSensors[ sensorIndex ].adcRunningSum >> SHIFT_BITS_BY_2_FOR_AVERAGING; // Different sensors have different ADC to temperature conversion methods switch( sensorIndex ) @@ -678,7 +734,7 @@ S32 const tpiADC = (S32)getFPGATPiTemp(); BOOL const isLessThanZero = tpiADC <= 0; - BOOL const isGreaterThanFullScale = tpiADC >= tempSensorsADCMaxCount; + BOOL const isGreaterThanFullScale = tpiADC >= TEMP_SENSORS_ADC_MAX_COUNT; if ( isLessThanZero || isGreaterThanFullScale ) { @@ -767,36 +823,58 @@ { // 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_REDUNDANT, getFPGATHDoTemp(), getFPGATHDoErrorCount(), getFPGATHDoReadCount() ); - processTempSnsrsADCRead( TEMPSENSORS_INLET_DIALYSATE, getFPGATDiTemp(), getFPGATDiErrorCount(), getFPGATDiReadCount() ); + if ( ++fpgaRawADCReadInterval >= FPGA_RAW_ADC_READ_INTERVAL_COUNT ) + { + 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_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() ); + processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, getFPGAPrimaryHeaterTemp(), getFPGAPrimaryHeaterFlags(), + getFPGAPrimaryHeaterReadCount() ); - // 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() ); + processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, getFPGATrimmerHeaterTemp(), getFPGATrimmerHeaterFlags(), + getFPGATrimmerHeaterReadCount() ); - // Check if time has elapsed to calculate the internal temperature of the heaters - if ( ++internalHeatersConversionTimer >= HEATERS_INTERNAL_TEMPERTURE_CALCULATION_INTERVAL ) - { - getHeaterInternalTemp( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ); - getHeaterInternalTemp( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ); - internalHeatersConversionTimer = 0; - } + processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION, getFPGAPrimaryColdJunctionTemp(), getFPGATrimmerHeaterFlags(), + getFPGAPrimaryHeaterReadCount() ); - publishTemperatureSensorsData(); + processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION, getFPGATrimmerColdJunctionTemp(), getFPGATrimmerHeaterFlags(), + getFPGATrimmerHeaterReadCount() ); + // NOTE: FPGA board temperature sensor is different from the rest of the sensors. This sensor does not have FPGA count and error + // coming from FPGA. It is kept here to do moving average on the values. The supporting functions need to see the FPGA read count + // incrementing so for that an artificial counter was created. + processTempSnsrsADCRead( TEMPSENSORS_FPGA_BOARD_SENSOR, getFPGABoardTemp(), 0, ++fpgaBoardTempReadCount ); + + processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A1_B1, getFPGALoadCellsA1B1Temp(), getFPGAADC1ErrorCount(), + getFPGAADC1ReadCount() ); + + processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A2_B2, getFPGALoadCellsA2B2Temp(), getFPGAADC2ErrorCount(), + getFPGAADC2ReadCount() ); + + 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 ) + { + getHeaterInternalTemp( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ); + getHeaterInternalTemp( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ); + internalHeatersConversionTimer = 0; + } + + fpgaRawADCReadInterval = 0; + } + return TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES; } Index: firmware/App/Controllers/Thermistors.c =================================================================== diff -u -rf6016459473bdb85aebe393c07cd580b973d7247 -r0b17c6271cdc3c55697a74ecaadb477d9c8f5687 --- firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision f6016459473bdb85aebe393c07cd580b973d7247) +++ firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision 0b17c6271cdc3c55697a74ecaadb477d9c8f5687) @@ -18,7 +18,7 @@ #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 4096.0 ///< 12 bit resolution conversion. +#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. @@ -27,22 +27,22 @@ #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_COUNT ( MS_PER_SECOND / ( 4 * TASK_GENERAL_INTERVAL ) ) ///< Thermistors/sensors maximum allowed temperature out of range count. +#define MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD ( MS_PER_SECOND / ( 4 * TASK_GENERAL_INTERVAL ) ) ///< Thermistors/sensors maximum allowed temperature out of range period. /// Thermistors self test states typedef enum thermistors_Self_Test_States { - THERMISTROS_SELF_TEST_CHECK_RANGE = 0, ///< Thermistors self test range check - THERMISTORS_SELF_TEST_COMPLETE, ///< Thermistors self test complete - NUM_OF_THERMISTORS_SELF_TEST_STATES, ///< Number of 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 = 0, ///< Thermistors exec state start - THERMISTORS_EXEC_STATE_GET_ADC_VALUES, ///< Thermistors exec state get ADC values - 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 @@ -54,17 +54,17 @@ } 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 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 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. -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. +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. // ********** private function prototypes ********** @@ -92,8 +92,8 @@ { // Reset the thermistors values for a run thermistorsSelfTestReslt = SELF_TEST_STATUS_IN_PROGRESS; - thermistorsExecState = THERMISTORS_EXEC_STATE_START; - thermistorsSelfTestState = THERMISTROS_SELF_TEST_CHECK_RANGE; + thermistorsExecState = THERMISTORS_EXEC_STATE_START_STATE; + thermistorsSelfTestState = THERMISTROS_SELF_TEST_CHECK_RANGE_STATE; dataPublishCounter = 0; // Initialize the beta values of each thermistor @@ -103,7 +103,7 @@ // 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 ); + TRUE, MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD, MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD ); } /*********************************************************************//** @@ -117,18 +117,18 @@ { switch ( thermistorsSelfTestState ) { - case THERMISTROS_SELF_TEST_CHECK_RANGE: + case THERMISTROS_SELF_TEST_CHECK_RANGE_STATE: thermistorsSelfTestState = handleSelfTestCheckRange(); break; - case THERMISTORS_SELF_TEST_COMPLETE: + case THERMISTORS_SELF_TEST_COMPLETE_STATE: // Done with POST. Do nothing. break; 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; + thermistorsSelfTestState = THERMISTORS_SELF_TEST_COMPLETE_STATE; break; } @@ -146,18 +146,18 @@ { switch ( thermistorsExecState ) { - case THERMISTORS_EXEC_STATE_START: + case THERMISTORS_EXEC_STATE_START_STATE: thermistorsExecState = handleExecStart(); break; - case THERMISTORS_EXEC_STATE_GET_ADC_VALUES: + case THERMISTORS_EXEC_STATE_GET_ADC_VALUES_STATE: thermistorsExecState = handleExecGetADCValues(); break; default: // Wrong state was called, raise an alarm SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_THERMISTORS_INVALID_EXEC_STATE, thermistorsExecState ); - thermistorsExecState = THERMISTORS_EXEC_STATE_GET_ADC_VALUES; + thermistorsExecState = THERMISTORS_EXEC_STATE_GET_ADC_VALUES_STATE; break; } @@ -171,7 +171,7 @@ * a requested thermistor or temperature sensor. * @details Inputs: thermistorsStatus * @details Outputs: none - * @param thermistor to get its temperature value + * @param thermistor index to get its temperature value * @return temperature of a thermistor or temperature sensor *************************************************************************/ F32 getThermistorTemperatureValue( THERMISTORS_TEMP_SENSORS_T thermistor ) @@ -208,7 +208,7 @@ *************************************************************************/ static THERMISTORS_SELF_TEST_STATES_T handleSelfTestCheckRange( void ) { - THERMISTORS_SELF_TEST_STATES_T state = THERMISTROS_SELF_TEST_CHECK_RANGE; + 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 ) @@ -240,7 +240,7 @@ } } // Done with POST - state = THERMISTORS_SELF_TEST_COMPLETE; + state = THERMISTORS_SELF_TEST_COMPLETE_STATE; adcReadCounter = 0; } @@ -257,12 +257,12 @@ *************************************************************************/ static THERMISTORS_EXEC_STATES_T handleExecStart( void ) { - THERMISTORS_EXEC_STATES_T state = THERMISTORS_EXEC_STATE_START; + THERMISTORS_EXEC_STATES_T state = THERMISTORS_EXEC_STATE_START_STATE; // Give a short time for FPGA to boot up and start sending the ADC reads if ( ++adcReadCounter > ADC_FPGA_READ_DELAY_COUNT ) { - state = THERMISTORS_EXEC_STATE_GET_ADC_VALUES; + state = THERMISTORS_EXEC_STATE_GET_ADC_VALUES_STATE; adcReadCounter = 0; } @@ -279,27 +279,21 @@ *************************************************************************/ static THERMISTORS_EXEC_STATES_T handleExecGetADCValues( void ) { - THERMISTORS_EXEC_STATES_T state = THERMISTORS_EXEC_STATE_GET_ADC_VALUES; + THERMISTORS_EXEC_STATES_T state = THERMISTORS_EXEC_STATE_GET_ADC_VALUES_STATE; // If time has elapsed to read the ADCs, read them all if ( ++adcReadCounter >= THERMISTORS_ADC_READ_INTERVAL ) { + // Monitor the values for a gross range check + monitorThermistors(); + // 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 ); // Zero the counter for the next round of reading adcReadCounter = 0; - - // 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(); } return state; @@ -318,6 +312,9 @@ THERMISTORS_TEMP_SENSORS_T thermistor; F32 temperature; + // First convert the values + convertADC2Temperature(); + for ( thermistor = THERMISTOR_ONBOARD_NTC; thermistor < NUM_OF_THERMISTORS; thermistor++ ) { temperature = getThermistorTemperatureValue( thermistor ); @@ -359,7 +356,12 @@ /*********************************************************************//** * @brief * The calcualteOnBoardThemristorTemperature function converts the ADC value - * of the onboard thermistor into temperature in C + * of the onboard thermistor into temperature in C. Below are the calculation + * steps: + * voltage = ADC x 3 / 2^12 + * voltage = 3 x 10 / ( 10 + R(T) ) + * R(T) = 10000 x e^(beta x (1/T - 1/298)) + * Solve for T which is temperature in Kelvin * @details Inputs: onBoardThermistorVoltageConvCoeff, * onBoardThermistorBetaValueInv * @details Outputs: none @@ -369,24 +371,19 @@ *************************************************************************/ static F32 calculateTemperature( U32 adcValue, F32 betaValue ) { - /* - * voltage = ADC x 3 / 2^12 - * voltage = 3 x 10 / ( 10 + R(T) ) - * R(T) = 10000 x e^(beta x (1/T - 1/298)) - * Solve for T which is temperature in Kelvin - */ + // 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 * thermistorVoltageConvCoeff; + F32 const thermistorVoltage = adcValue * THERMISTOR_VOLTAGE_CONV_COEFF; // Calculate the thermistor resistor by solving: thermistorVoltage = (3 x 10) / (10 + R(T)) F32 const thermistorResistor = ( ( THERMISTOR_REFERENCE_RESISTOR_AT_25 * THERMISTOR_REFERENCE_VOLTAGE ) - ( THERMISTOR_REFERENCE_RESISTOR_AT_25 * thermistorVoltage ) ) / thermistorVoltage; // 1/T = Ln(thermistorResistor/10000)/3380 + 1/298 F32 const invTemperature = ( logf( thermistorResistor / THERMISTOR_REFERENCE_RESISTOR_AT_25 ) / betaValue ) + - onBoardThermistorRefTempInv; + ON_BOARD_THERMISTOR_REF_TEMP_INV; // Inverse the value to get the temperature in Kelvin and then convert it to Celsius F32 const temperature = ( 1 / invTemperature ) - CELSIUS_TO_KELVIN_CONVERSION; @@ -444,6 +441,7 @@ * TEST SUPPORT FUNCTIONS *************************************************************************/ + /*********************************************************************//** * @brief * The testSetThermistorPublishIntervalOverride function overrides the Index: firmware/App/Controllers/Thermistors.h =================================================================== diff -u -r27d91d88b73aa4194cef1d3b08decc12ccdecc33 -r0b17c6271cdc3c55697a74ecaadb477d9c8f5687 --- firmware/App/Controllers/Thermistors.h (.../Thermistors.h) (revision 27d91d88b73aa4194cef1d3b08decc12ccdecc33) +++ firmware/App/Controllers/Thermistors.h (.../Thermistors.h) (revision 0b17c6271cdc3c55697a74ecaadb477d9c8f5687) @@ -16,11 +16,10 @@ * @{ */ - // ********** public definitions ********** /// Enumeration of thermistors -typedef enum thermistors_Name +typedef enum DG_thermistors { THERMISTOR_ONBOARD_NTC = 0, ///< Onboard thermistor THERMISTOR_POWER_SUPPLY_1, ///< DG power supply 1 thermistor Index: firmware/App/Drivers/InternalADC.c =================================================================== diff -u -r4d7d40a27130dc813d653f044cbb856b1b7d8481 -r0b17c6271cdc3c55697a74ecaadb477d9c8f5687 --- firmware/App/Drivers/InternalADC.c (.../InternalADC.c) (revision 4d7d40a27130dc813d653f044cbb856b1b7d8481) +++ firmware/App/Drivers/InternalADC.c (.../InternalADC.c) (revision 0b17c6271cdc3c55697a74ecaadb477d9c8f5687) @@ -55,8 +55,8 @@ INT_ADC_REF_IN1, // 19 INT_ADC_REF_IN2, // 20 INT_ADC_BOARD_THERMISTOR, // 21 - INT_ADC_NOT_USED, // 22 - INT_ADC_NOT_USED // 23 + INT_ADC_POWER_SUPPLY_1_THERMISTOR, // 22 + INT_ADC_POWER_SUPPLY_2_THERMISTOR, // 23 }; // ********** private data ********** Index: firmware/App/Modes/ModeInitPOST.c =================================================================== diff -u -r4d7d40a27130dc813d653f044cbb856b1b7d8481 -r0b17c6271cdc3c55697a74ecaadb477d9c8f5687 --- firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 4d7d40a27130dc813d653f044cbb856b1b7d8481) +++ firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 0b17c6271cdc3c55697a74ecaadb477d9c8f5687) @@ -17,13 +17,15 @@ #include "Accel.h" #include "CPLD.h" +#include "Fans.h" #include "FPGA.h" #include "Heaters.h" #include "ModeInitPOST.h" #include "OperationModes.h" #include "Pressures.h" #include "RTC.h" #include "TemperatureSensors.h" +#include "Thermistors.h" #include "WatchdogMgmt.h" /** @@ -126,6 +128,20 @@ postState = handlePOSTStatus( testStatus ); break; +// To be able to run integration test in VectorCAST. +// Not all the fans and thermistors have been implemented so POST might fail +#ifdef _VECTORCAST_ + case DG_POST_STATE_THERMISTORS: + testStatus = execThermistorsSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; + + case DG_POST_STATE_FANS: + testStatus = execFansSelfTest(); + postState = handlePOSTStatus( testStatus ); + break; +#endif + case DG_POST_STATE_WATCHDOG: testStatus = execWatchdogTest(); handlePOSTStatus( testStatus ); // ignoring return value because last test Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r27d91d88b73aa4194cef1d3b08decc12ccdecc33 -r0b17c6271cdc3c55697a74ecaadb477d9c8f5687 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 27d91d88b73aa4194cef1d3b08decc12ccdecc33) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 0b17c6271cdc3c55697a74ecaadb477d9c8f5687) @@ -1730,5 +1730,53 @@ return fpgaSensorReadings.fpgaRTDTemp; } +/*********************************************************************//** + * @brief + * The getFPGAADC1ReadCount function gets the FPGA ADC1 read count. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return FPGA ADC1 read count + *************************************************************************/ +U08 getFPGAADC1ReadCount( void ) +{ + return fpgaSensorReadings.fpgaADC1ReadCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGAADC1ErrorCount function gets the FPGA ADC1 error count. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return FPGA ADC1 error count + *************************************************************************/ +U08 getFPGAADC1ErrorCount( void ) +{ + return fpgaSensorReadings.fpgaADC1ErrorCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGAADC2ReadCount function gets the FPGA ADC2 read count. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return FPGA ADC2 read count + *************************************************************************/ +U08 getFPGAADC2ReadCount( void ) +{ + return fpgaSensorReadings.fpgaADC2ReadCnt; +} + +/*********************************************************************//** + * @brief + * The getFPGAADC2ErrorCount function gets the FPGA ADC2 error count. + * @details Inputs: fpgaSensorReadings + * @details Outputs: none + * @return FPGA ADC2 error count + *************************************************************************/ +U08 getFPGAADC2ErrorCount( void ) +{ + return fpgaSensorReadings.fpgaADC2ErrorCnt; +} + /**@}*/ Index: firmware/App/Services/FPGA.h =================================================================== diff -u -r27d91d88b73aa4194cef1d3b08decc12ccdecc33 -r0b17c6271cdc3c55697a74ecaadb477d9c8f5687 --- firmware/App/Services/FPGA.h (.../FPGA.h) (revision 27d91d88b73aa4194cef1d3b08decc12ccdecc33) +++ firmware/App/Services/FPGA.h (.../FPGA.h) (revision 0b17c6271cdc3c55697a74ecaadb477d9c8f5687) @@ -126,6 +126,12 @@ U32 getFPGATDiInternalTemp( void ); U32 getFPGACondSnsrInternalTemp( void ); +U08 getFPGAADC1ReadCount( void ); +U08 getFPGAADC1ErrorCount( void ); + +U08 getFPGAADC2ReadCount( void ); +U08 getFPGAADC2ErrorCount( void ); + /**@}*/ #endif Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -r27d91d88b73aa4194cef1d3b08decc12ccdecc33 -r0b17c6271cdc3c55697a74ecaadb477d9c8f5687 --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 27d91d88b73aa4194cef1d3b08decc12ccdecc33) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 0b17c6271cdc3c55697a74ecaadb477d9c8f5687) @@ -1072,10 +1072,6 @@ handleTestPressureSensorOverrideRequest( message ); break; - case MSG_ID_PRESSURE_SEND_INTERVAL_OVERRIDE: - handleTestPressureDataBroadcastIntervalOverrideRequest( message ); - break; - case MSG_ID_RO_MEASURED_FLOW_OVERRIDE: handleTestROMeasuredFlowOverrideRequest( message ); break; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r27d91d88b73aa4194cef1d3b08decc12ccdecc33 -r0b17c6271cdc3c55697a74ecaadb477d9c8f5687 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 27d91d88b73aa4194cef1d3b08decc12ccdecc33) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 0b17c6271cdc3c55697a74ecaadb477d9c8f5687) @@ -706,7 +706,7 @@ * @details * @details Inputs: none * @details Outputs: thermistors data msg constructed and queued - * @param thermistors msg constructed and queued + * @param thermistorsData which is constructed and queued * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ BOOL broadcastThermistorsData( THERMISTORS_DATA_T *thermistorsData ) @@ -733,7 +733,7 @@ * The broadcastFansData function sends out the fans data. * @details Inputs: none * @details Outputs: fans data msg constructed and queued - * @param fans msg constructed and queued + * @param fansData which is constructed and queued * @return TRUE if msg successfully queued for transmit, FALSE if not *************************************************************************/ BOOL broadcastFansData( FANS_DATA_T *fansData ) @@ -2157,5 +2157,4 @@ sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); } - /**@}*/ Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r27d91d88b73aa4194cef1d3b08decc12ccdecc33 -r0b17c6271cdc3c55697a74ecaadb477d9c8f5687 --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 27d91d88b73aa4194cef1d3b08decc12ccdecc33) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 0b17c6271cdc3c55697a74ecaadb477d9c8f5687) @@ -19,9 +19,9 @@ #define __SYSTEM_COMM_MESSAGES_H__ #include "DGCommon.h" +#include "Fans.h" #include "MsgQueues.h" #include "Thermistors.h" -#include "Fans.h" /** * @defgroup SystemCommMessages SystemCommMessages @@ -83,6 +83,12 @@ // MSG_ID_DG_CONDUCTIVITY_DATA BOOL broadcastConductivityData( void * conductivityDataPtr ); +// MSG_ID_DG_THERMISTORS_DATA +BOOL broadcastThermistorsData( THERMISTORS_DATA_T *thermistorsData ); + +// MSG_ID_DG_FANS_DATA +BOOL broadcastFansData( FANS_DATA_T * fansData ); + // MSG_ID_POWER_OFF_WARNING void handlePowerOffWarning( MESSAGE_T *message ); @@ -113,12 +119,6 @@ // MSG_ID_DG_START_STOP_TRIMMER_HEATER_CMD void handleStartStopTrimmerHeaterCmd( MESSAGE_T *message ); -// MSG_ID_DG_THERMISTORS_DATA -BOOL broadcastThermistorsData( THERMISTORS_DATA_T *thermistorsData ); - -// MSG_ID_DG_FANS_DATA -BOOL broadcastFansData( FANS_DATA_T * fansData ); - // *********** public test support message functions ********** #ifdef DEBUG_ENABLED Index: firmware/source/sys_main.c =================================================================== diff -u -rf6016459473bdb85aebe393c07cd580b973d7247 -r0b17c6271cdc3c55697a74ecaadb477d9c8f5687 --- firmware/source/sys_main.c (.../sys_main.c) (revision f6016459473bdb85aebe393c07cd580b973d7247) +++ firmware/source/sys_main.c (.../sys_main.c) (revision 0b17c6271cdc3c55697a74ecaadb477d9c8f5687) @@ -176,6 +176,8 @@ initTemperatureSensors(); initConductivitySensors(); initConcentratePump(); + initFans(); + initThermistors(); initROPump(); initDrainPump(); initAccel(); @@ -185,8 +187,6 @@ initSystemComm(); initReservoirs(); initOperationModes(); - initFans(); - initThermistors(); } /*************************************************************************