Index: firmware/App/Controllers/Fans.c =================================================================== diff -u -r22f1a58ac8e419353ec004b04e7c765c1d59df2b -r2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c --- firmware/App/Controllers/Fans.c (.../Fans.c) (revision 22f1a58ac8e419353ec004b04e7c765c1d59df2b) +++ firmware/App/Controllers/Fans.c (.../Fans.c) (revision 2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c) @@ -6,9 +6,7 @@ #include "PersistentAlarm.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" -#include "TemperatureSensors.h" #include "Thermistors.h" -#include "Timers.h" /** * @addtogroup Fans @@ -17,60 +15,67 @@ // ********** private definitions ********** -#define FANS_MIN_DUTY_CYCLE 0.1 ///< Fans min PWM. -#define FANS_MAX_DUTY_CYCLE 0.95 ///< Fans max PWM. -#define MIN_ALLOWED_AMBIENT_TEMPERATURE 20 ///< Min allowed ambient temperature. -#define MAX_ALLOWED_AMBINET_TEMPERATURE 70 ///< Max allowed ambient temperature. -#define FANS_MAX_ALLOWED_RAMP_UP_DELTA_DUTY_CYCLE 0.3 ///< Fans max allowed ramp up PWM change. -#define FANS_MAX_ALLOWED_RAMP_DOWN_DELTA_DUTY_CYCLE 0.005 ///< Fans min allowed ramp down PWM change. +#define FANS_MIN_DUTY_CYCLE 0.1 ///< Fans min PWM. +#define FANS_MAX_DUTY_CYCLE 0.95 ///< Fans max PWM. +#define MIN_ALLOWED_AMBIENT_TEMPERATURE 20 ///< Min allowed ambient temperature. +#define MAX_ALLOWED_AMBINET_TEMPERATURE 70 ///< Max allowed ambient temperature. +#define FANS_MAX_ALLOWED_RAMP_UP_DELTA_DUTY_CYCLE 0.3 ///< Fans max allowed ramp up PWM change. +#define FANS_MAX_ALLOWED_RAMP_DOWN_DELTA_DUTY_CYCLE 0.005 ///< Fans min allowed ramp down PWM change. -#define TOGGLE_PERIOD_RESOLUTION_SECONDS 0.0000025 ///< FPGA fans toggle period resolution in micro seconds. -#define ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION 4 ///< FPGA rotational to toggle period conversion coefficient. +#define TOGGLE_PERIOD_RESOLUTION_SECONDS 0.0000025 ///< FPGA fans toggle period resolution in micro seconds. +#define ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION 4 ///< FPGA rotational to toggle period conversion coefficient. -#define FANS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans publish data time interval in counts. -#define FANS_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans control time interval in counts. -#define FANS_ZERO_RPM_TOGGLE_PERIOD_VALUE 0xFFFF ///< Fans zero RPM toggle period value. -#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_INTERVAL ( 3 * MS_PER_SECOND ) ///< Fans max allowed RPM out of range time interval. -#define FANS_MAX_ALLOWED_RPM 5500 ///< Fans max allowed RPM value. -#define FANS_MIN_ALLOWED_RPM 150 ///< Fans max allowed RPM value. -#define FANS_MONITOR_INTERVAL_COUNT ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans monitor time interval in counts. -#define FANS_MIN_RPM_OUT_OF_RANGE_TOL 0.25 ///< Fans min RPM out of range tolerance. -#define FANS_MAX_RPM_OUT_OF_RANGE_TOL 0.5 ///< Fans max RPM out of range tolerance. +#define FANS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans publish data time interval in counts. +#define FANS_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans control time interval in counts. +#define FANS_ZERO_RPM_TOGGLE_PERIOD_VALUE 0xFFFF ///< Fans zero RPM toggle period value. +#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_INTERVAL ( 3 * MS_PER_SECOND ) ///< Fans max allowed RPM out of range time interval. +#define FANS_MAX_ALLOWED_RPM 5500 ///< Fans max allowed RPM value. +#define FANS_MIN_ALLOWED_RPM 150 ///< Fans max allowed RPM value. +#define FANS_MONITOR_INTERVAL_COUNT ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Fans monitor time interval in counts. +#define FANS_MIN_RPM_OUT_OF_RANGE_TOL 0.25 ///< Fans min RPM out of range tolerance. +#define FANS_MAX_RPM_OUT_OF_RANGE_TOL 0.5 ///< Fans max RPM out of range tolerance. +/// Fans self test states +typedef enum 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_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_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 typedef struct { - F32 targetDutyCycle; ///< Fan's target duty cycle that was fed to the fans. - OVERRIDE_F32_T rpm[ NUM_OF_FANS_NAMES ]; ///< Fan's current tachometers reading in RPM. + F32 targetDutyCycle; ///< Fan's target duty cycle that was fed to the fans + U32 rpm[ NUM_OF_FANS_NAMES ]; ///< Fan's current tachometers reading in RPM } FAN_STATUS_T; -static FAN_STATUS_T fansStatus; ///< Fans status. -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. -static U32 fansMonitorCounter = 0; ///< Fans monitor interval counter. -static BOOL isPOSTComplete = FALSE; ///< Flag that indicates whether POST is complete or not. -static BOOL hasAlarmBeenRaised = FALSE; ///< Flag that indicates whether the RPM out of range alarm been raise. -static U32 rpmAlarmStartTimer = 0; ///< RPM out of range alarm start timer when the alarm is raised. +static FAN_STATUS_T fansStatus; ///< Fans status. +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. +static U32 fansMonitorCounter = 0; ///< Fans monitor interval counter. +static BOOL isPOSTComplete = FALSE; ///< Flag that indicates whether POST is complete or not. /// 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 ); /// FGPA Toggle to RPM conversion coefficient 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. +static OVERRIDE_U32_T fansPublishInterval = { FANS_DATA_PUBLISH_INTERVAL, FANS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Fans publish time interval override static FANS_EXEC_STATES_T handleExecStateWaitForPOST( void ); static FANS_EXEC_STATES_T handleExecStateRun( void ); @@ -86,34 +91,21 @@ /*********************************************************************//** * @brief * The initFans function initializes the fans module. - * @details Inputs: none + * @details Inputs: fansExecState, fansStatus, fansControlCounter, + * fansPublishCounter * @details Outputs: fansExecState, fansStatus, fansControlCounter, - * fansPublishCounter, fansMonitorCounter, isPOSTComplete, hasAlarmBeenRaised, - * rpmAlarmStartTimer + * fansPublishCounter * @return none *************************************************************************/ void initFans( void ) { - FAN_NAMES_T fan; - // Initialize the variables fansExecState = FANS_EXEC_STATE_WAIT_FOR_POST_STATE; fansControlCounter = 0; fansPublishCounter = 0; fansMonitorCounter = 0; isPOSTComplete = FALSE; - hasAlarmBeenRaised = FALSE; - rpmAlarmStartTimer = 0; - // Initialize the fans - for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) - { - fansStatus.rpm[ fan ].data = 0.0; - fansStatus.rpm[ fan ].ovData = 0.0; - fansStatus.rpm[ fan ].ovInitData = 0.0; - fansStatus.rpm[ fan ].override = OVERRIDE_RESET; - } - // Initialize a persistent alarm for fans RPM out of range initPersistentAlarm( ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE, FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_INTERVAL, FANS_MAX_ALLOWED_RPM_OUT_OF_RANGE_INTERVAL ); } @@ -147,6 +139,9 @@ *************************************************************************/ void execFans( void ) { + // Monitor the fans + //monitorFans(); TODO uncomment. this is to investigate why the fans RPM are out of range + switch ( fansExecState ) { case FANS_EXEC_STATE_WAIT_FOR_POST_STATE: @@ -163,12 +158,6 @@ break; } - // Convert the counts to RPM - convertTogglePeriod2RPM(); - - // Monitor the RPM of the fans - monitorFans(); - publishFansData(); } @@ -182,18 +171,12 @@ *************************************************************************/ F32 getMeasuredFanRPM( FAN_NAMES_T fan ) { - F32 rpm; + F32 rpm = 0.0; // Check if the called fan is in range if ( fan < NUM_OF_FANS_NAMES ) { - // Assume there is no override - rpm = fansStatus.rpm[ fan ].data; - - if ( OVERRIDE_KEY == fansStatus.rpm[ fan ].override ) - { - rpm = fansStatus.rpm[ fan ].ovData; - } + rpm = fansStatus.rpm[ fan ]; } else { @@ -342,40 +325,30 @@ { F32 temperature; THERMISTORS_TEMP_SENSORS_T thermistor; - F32 maxTemperature; + F32 maxTemperature = 0.0; // Loop through the sensors and thermistors for ( thermistor = THERMISTOR_ONBOARD_NTC; thermistor < NUM_OF_THERMISTORS; thermistor++ ) { + // Get the value temperature = getThermistorTemperatureValue( thermistor ); - maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); + + // If the latest temperature read is greater than the max temperature, + // set the maximum temperature there + if ( temperature > maxTemperature ) + { + maxTemperature = temperature; + } } - // The temperature sensors that are on the hardware and are not on the fluid path are used to - // decide the maximum temperature - temperature = getTemperatureValue( TEMPSENSORS_FPGA_BOARD_SENSOR ); - maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); - - temperature = getTemperatureValue( TEMPSENSORS_LOAD_CELL_A1_B1 ); - maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); - - temperature = getTemperatureValue( TEMPSENSORS_LOAD_CELL_A2_B2 ); - maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); - - temperature = getTemperatureValue( TEMPSENSORS_INTERNAL_THDO_RTD ); - maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); - - temperature = getTemperatureValue( TEMPSENSORS_INTERNAL_TDI_RTD ); - maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); - return maxTemperature; } /*********************************************************************//** * @brief * The convertTogglePeriod2RPM function runs through the list of the fans * to get the FPGA pulse from them and converts them to RPM. - * @details Inputs: none + * @details Inputs: fansStatus, toggle2RPMCoefficient * @details Outputs: fansStatus * @return none ************************************************************************/ @@ -397,21 +370,21 @@ // Otherwise, convert the pulse to RPM if ( togglePeriods[ fan ] == FANS_ZERO_RPM_TOGGLE_PERIOD_VALUE ) { - fansStatus.rpm[ fan ].data = 0; + fansStatus.rpm[ fan ] = 0; } else { // Convert toggle period to RPM - fansStatus.rpm[ fan ].data = TOGGLE_PERIOD_2_RPM_COEFFICIENT / togglePeriods[ fan ]; + fansStatus.rpm[ fan ] = TOGGLE_PERIOD_2_RPM_COEFFICIENT / togglePeriods[ fan ]; } } } /*********************************************************************//** * @brief * The monitorFans function monitors the fans for RPM. - * @details Inputs: fansMonitorCounter, fansStatus - * @details Outputs: fansMonitorCounter + * @details Inputs: fansStatus + * @details Outputs: none * @return none *************************************************************************/ static void monitorFans( void ) @@ -420,36 +393,19 @@ if ( ++fansMonitorCounter >= FANS_MONITOR_INTERVAL_COUNT ) { - // If the fans alarm has been raise already, do not raise again - if ( FALSE == hasAlarmBeenRaised ) - { - BOOL isFanRPMOutOfRange; + // The RPM is expected to be 5500 @ 100% duty cycle + // The nominal RPM = duty cycle * 5500 / 1.0 + // The RPM tolerance is -25% to +50% of the nominal RPM + F32 fansNominalRPM = fansStatus.targetDutyCycle * FANS_MAX_ALLOWED_RPM; + F32 fansMinAllowedRPM = fansNominalRPM - ( fansNominalRPM * FANS_MIN_RPM_OUT_OF_RANGE_TOL ); + F32 fansMaxAllowedRPM = fansNominalRPM - ( fansNominalRPM * FANS_MAX_RPM_OUT_OF_RANGE_TOL ); - // The RPM is expected to be 5500 @ 100% duty cycle - // The nominal RPM = duty cycle * 5500 / 1.0 - // The RPM tolerance is -25% to +50% of the nominal RPM - F32 fansNominalRPM = fansStatus.targetDutyCycle * FANS_MAX_ALLOWED_RPM; - F32 fansMinAllowedRPM = fansNominalRPM - ( fansNominalRPM * FANS_MIN_RPM_OUT_OF_RANGE_TOL ); - F32 fansMaxAllowedRPM = fansNominalRPM + ( fansNominalRPM * FANS_MAX_RPM_OUT_OF_RANGE_TOL ); + convertTogglePeriod2RPM(); - for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) - { - isFanRPMOutOfRange = ( getMeasuredFanRPM( fan ) < fansMinAllowedRPM ) || ( getMeasuredFanRPM( fan ) > fansMaxAllowedRPM ); - checkPersistentAlarm( ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE, isFanRPMOutOfRange, getMeasuredFanRPM( fan ), FANS_MAX_ALLOWED_RPM ); - - // If the RPM out of range alarm has been raised, do not raise it again, until its alarm silence time has been elapsed - hasAlarmBeenRaised = ( TRUE == isAlarmActive( ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE ) ? TRUE : FALSE ); - - if ( ( TRUE == hasAlarmBeenRaised ) && ( 0 == rpmAlarmStartTimer ) ) - { - rpmAlarmStartTimer = getMSTimerCount(); - } - } - } - else if ( ( TRUE == hasAlarmBeenRaised ) && ( TRUE == didTimeout( rpmAlarmStartTimer, SECONDS_IN_A_DAY ) ) ) + for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) { - hasAlarmBeenRaised = FALSE; - rpmAlarmStartTimer = 0; + BOOL const fanRpmOutOfRange = ( fansStatus.rpm[ fan ] < fansMinAllowedRPM ) || ( fansStatus.rpm[ fan ] > fansMaxAllowedRPM ); + checkPersistentAlarm( ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE, fanRpmOutOfRange, fansStatus.rpm[ fan ], FANS_MAX_ALLOWED_RPM ); } fansMonitorCounter = 0; @@ -490,12 +446,12 @@ FANS_DATA_T fansData; fansData.fansTargetDutyCycle = fansStatus.targetDutyCycle * FRACTION_TO_PERCENT_FACTOR; - fansData.fanInlet1RPM = getMeasuredFanRPM( FAN_INLET_1 ); - fansData.fanInlet2RPM = getMeasuredFanRPM( FAN_INLET_2 ); - fansData.fanInlet3RPM = getMeasuredFanRPM( FAN_INLET_3 ); - fansData.fanOutlet1RPM = getMeasuredFanRPM( FAN_OUTLET_1 ); - fansData.fanOutlet2RPM = getMeasuredFanRPM( FAN_OUTLET_2 ); - fansData.fanOutlet3RPM = getMeasuredFanRPM( FAN_OUTLET_3 ); + fansData.fanInlet1RPM = fansStatus.rpm[ FAN_INLET_1 ]; + fansData.fanInlet2RPM = fansStatus.rpm[ FAN_INLET_2 ]; + fansData.fanInlet3RPM = fansStatus.rpm[ FAN_INLET_3 ]; + fansData.fanOutlet1RPM = fansStatus.rpm[ FAN_OUTLET_1 ]; + fansData.fanOutlet2RPM = fansStatus.rpm[ FAN_OUTLET_2 ]; + fansData.fanOutlet3RPM = fansStatus.rpm[ FAN_OUTLET_3 ]; broadcastFansData( &fansData ); @@ -556,55 +512,4 @@ return result; } -/*********************************************************************//** - * @brief - * The testSetFanRPMOverride function overrides the RPM of a fan. - * @details Inputs: none - * @details Outputs: fansStatus - * @param fanId fan ID - * @param rpm the RPM override value - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testSetFanRPMOverride( U32 fanId, F32 rpm ) -{ - BOOL result = FALSE; - - if ( fanId < NUM_OF_FANS_NAMES ) - { - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - fansStatus.rpm[ fanId ].ovData = rpm; - fansStatus.rpm[ fanId ].override = OVERRIDE_KEY; - } - } - - return result; -} - -/*********************************************************************//** - * @brief - * The testResetFanRPMOverride function resets the override value of a fan. - * @details Inputs: none - * @details Outputs: fansStatus - * @param fanId fan index - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testResetFanRPMOverride( U32 fanId ) -{ - BOOL result = FALSE; - - if ( fanId < NUM_OF_FANS_NAMES ) - { - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - fansStatus.rpm[ fanId ].ovData = fansStatus.rpm[ fanId ].ovInitData; - fansStatus.rpm[ fanId ].override = OVERRIDE_RESET; - } - } - - return result; -} - /**@}*/ Index: firmware/App/Controllers/Fans.h =================================================================== diff -u -r22f1a58ac8e419353ec004b04e7c765c1d59df2b -r2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c --- firmware/App/Controllers/Fans.h (.../Fans.h) (revision 22f1a58ac8e419353ec004b04e7c765c1d59df2b) +++ firmware/App/Controllers/Fans.h (.../Fans.h) (revision 2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c) @@ -47,9 +47,6 @@ BOOL testSetFanPublishIntervalOverride( U32 value ); BOOL testResetFanPublishIntervalOverride( void ); -BOOL testSetFanRPMOverride( U32 fanId, F32 rpm ); -BOOL testResetFanRPMOverride( U32 fanId ); - /**@}*/ #endif Index: firmware/App/Controllers/LoadCell.c =================================================================== diff -u -r22f1a58ac8e419353ec004b04e7c765c1d59df2b -r2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c --- firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision 22f1a58ac8e419353ec004b04e7c765c1d59df2b) +++ firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision 2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c) @@ -34,19 +34,17 @@ // TODO check the maximum weight on the load cells in tare. There was 1500 grams limit // but it has been removed. Check the load cells data sheet. -#define LOAD_CELL_REPORT_PERIOD (100 / TASK_PRIORITY_INTERVAL) ///< Broadcast load cell values message every 100 ms. +#define LOAD_CELL_REPORT_PERIOD (100 / TASK_PRIORITY_INTERVAL) ///< Broadcast load cell values message every 100 ms. /// Conversion factor from ADC counts to grams. -static const F32 ADC2GRAM = (0.0894 * 1.1338); -#define LOAD_CELL_FILTER_ALPHA 0.05 ///< Alpha factor for the alpha filter used on load cell readings. +static const F32 ADC2GRAM = (0.0894 * 1.1338); +#define LOAD_CELL_FILTER_ALPHA 0.05 ///< Alpha factor for the alpha filter used on load cell readings. -#define SIZE_OF_SMALL_LOAD_CELL_AVG 100 ///< Small load cell moving average has 100 raw samples @ 10ms intervals (1-second). -#define SIZE_OF_LARGE_LOAD_CELL_AVG 40 ///< Large load cell moving average has 40 samples from small filter @ 100ms intervals (4-second). +#define SIZE_OF_SMALL_LOAD_CELL_AVG 100 ///< Small load cell moving average has 100 raw samples @ 10ms intervals (1-second). +#define SIZE_OF_LARGE_LOAD_CELL_AVG 40 ///< Large load cell moving average has 40 samples from small filter @ 100ms intervals (4-second). -#define LOAD_CELL_ADC_ERROR_PERSISTENCE 500 ///< Alarm persistence period (in ms) for load cell ADC errors. -#define LOAD_CELL_MIN_ALLOWED_WEIGHT_GRAMS 1600 ///< Load cell minimum allowed weight in grams. -#define LOAD_CELL_MAX_ALLOWED_WEIGHT_GRAMS 4500 ///< Load cell maximum allowed weight in grams. -#define MAX_ALLOWED_EXTRA_WEIGHT_BEFORE_TARE_GRAMS 300 ///< Max allowed extra weight before tare in grams. -#define LOAD_CELL_WEIGHT_OUT_RANGE_PERSISTENT_PERIOD_MS (5 * MS_PER_SECOND) ///< Load cell weight out of range persistent period in milliseconds. +#define LOAD_CELL_ADC_ERROR_PERSISTENCE 500 ///< Alarm persistence period (in ms) for load cell ADC errors. +#define EMPTY_RESERVOIR_WEIGHT_GRAMS 1600 ///< Reservoirs empty weight in grams. +#define MAX_ALLOWED_EXTRA_WEIGHT_BEFORE_TARE_GRAMS 300 ///< Max allowed extra weight before tare in grams. /// Load cell data structure. typedef struct @@ -81,7 +79,6 @@ static U32 getLoadCellDataPublishInterval( void ); static BOOL processCalibrationData( void ); -static void monitorLoadCellsWeightOutOfRange( void ); /*********************************************************************//** * @brief @@ -90,7 +87,7 @@ * @details Outputs: LoadCell module initialized. * @return none *************************************************************************/ - void initLoadCell( void ) +void initLoadCell( void ) { U32 cell; U32 i; @@ -129,11 +126,18 @@ loadcells[ i ].loadCellVelocity_g_min = 0.0; } + for ( cell = CAL_DATA_LOAD_CELL_A1; cell < NUM_OF_CAL_DATA_LOAD_CELLS; cell++ ) + { + // Reset the calibration variables + loadCellsCalRecord.loadCells[ cell ].fourthOrderCoeff = 0.0; + loadCellsCalRecord.loadCells[ cell ].thirdOrderCoeff = 0.0; + loadCellsCalRecord.loadCells[ cell ].secondOrderCoeff = 0.0; + loadCellsCalRecord.loadCells[ cell ].gain = 1.0; + loadCellsCalRecord.loadCells[ cell ].offset = 0.0; + } + // Initialize persistent alarm(s) initPersistentAlarm( ALARM_ID_DG_LOAD_CELL_ADC_ERROR, 0, LOAD_CELL_ADC_ERROR_PERSISTENCE ); - - initPersistentAlarm( ALARM_ID_DG_LOAD_CELL_WEIGHT_OUT_OF_RANGE, LOAD_CELL_WEIGHT_OUT_RANGE_PERSISTENT_PERIOD_MS, - LOAD_CELL_WEIGHT_OUT_RANGE_PERSISTENT_PERIOD_MS ); } /*********************************************************************//** @@ -240,9 +244,6 @@ loadCellDataPublicationTimerCounter = 0; } - - // Monitor the weight of the load cells - monitorLoadCellsWeightOutOfRange(); } /*********************************************************************//** @@ -291,7 +292,7 @@ { // For the first tare, the weight of the reservoir should be considered // The current weight of the load cell should not be greater than the weight of the reservoir + the extra weight - F32 deltaWeight = fabs( weight - LOAD_CELL_MIN_ALLOWED_WEIGHT_GRAMS ); + F32 deltaWeight = fabs( weight - EMPTY_RESERVOIR_WEIGHT_GRAMS ); isWeightOutOfRange = ( deltaWeight > MAX_ALLOWED_EXTRA_WEIGHT_BEFORE_TARE_GRAMS ? TRUE : FALSE ); } else @@ -492,34 +493,7 @@ return status; } -/*********************************************************************//** - * @brief - * The monitorLoadCellsWeightOutOfRange function monitors the weight of the - * load cells and if they are not in range, it raises an alarm. - * @details Inputs: loadcells - * @details Outputs: none - * @return none - *************************************************************************/ -static void monitorLoadCellsWeightOutOfRange( void ) -{ - LOAD_CELL_ID_T loadCell; - BOOL isWeightOutOfRange; - F32 weight; - for ( loadCell = LOAD_CELL_RESERVOIR_1_PRIMARY; loadCell < NUM_OF_LOAD_CELLS; loadCell++ ) - { - // The load cells must have been tared before checking for the weight range - if ( loadcells[ loadCell ].autoCalOffset != 0 ) - { - weight = getLoadCellSmallFilteredWeight( loadCell ); - isWeightOutOfRange = ( weight < LOAD_CELL_MIN_ALLOWED_WEIGHT_GRAMS ) || ( weight > LOAD_CELL_MAX_ALLOWED_WEIGHT_GRAMS ); - - checkPersistentAlarm( ALARM_ID_DG_LOAD_CELL_WEIGHT_OUT_OF_RANGE, isWeightOutOfRange, weight, LOAD_CELL_MAX_ALLOWED_WEIGHT_GRAMS ); - } - } -} - - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ Index: firmware/App/Controllers/Switches.c =================================================================== diff -u -rddb9707d9e6e46c4b384782aeec20d41f3822996 -r2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c --- firmware/App/Controllers/Switches.c (.../Switches.c) (revision ddb9707d9e6e46c4b384782aeec20d41f3822996) +++ firmware/App/Controllers/Switches.c (.../Switches.c) (revision 2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c) @@ -78,15 +78,15 @@ switch ( i ) { case CONCENTRATE_CAP: - currentSwitchStatus = ( getFPGAConcentrateCapStatus() != 0 ? STATE_OPEN : STATE_CLOSED ); + currentSwitchStatus = getFPGAConcentrateCapStatus(); break; case DIALYSATE_CAP: - currentSwitchStatus = ( getFPGADialysateCapStatus() != 0 ? STATE_OPEN : STATE_CLOSED ); + currentSwitchStatus = getFPGADialysateCapStatus(); break; case FLUID_DOOR: - currentSwitchStatus = ( getFPGAGFluidDoorStatus() != 0 ? STATE_OPEN : STATE_CLOSED ); + currentSwitchStatus = getFPGAGFluidDoorStatus(); break; default: Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -rddb9707d9e6e46c4b384782aeec20d41f3822996 -r2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision ddb9707d9e6e46c4b384782aeec20d41f3822996) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c) @@ -163,7 +163,7 @@ static void processADCRead( U32 sensorIndex, S32 adc ); static U32 getPublishTemperatureSensorsDataInterval( void ); static void publishTemperatureSensorsData( void ); -static void monitorTemperatureSnsrs( U32 sensorIndex ); +static void monitorTemperatureSnsrs( U32 sensorIndex, F32 temperature ); /*********************************************************************//** * @brief @@ -372,7 +372,7 @@ if ( sensorIndex < NUM_OF_TEMPERATURE_SENSORS ) { - if ( OVERRIDE_KEY == tempSensors[ sensorIndex ].temperatureValues.override ) + if ( tempSensors[ sensorIndex ].temperatureValues.override == OVERRIDE_KEY ) { temperature = tempSensors[ sensorIndex ].temperatureValues.ovData; } @@ -712,7 +712,7 @@ tempSensors[ sensorIndex ].temperatureValues.data = temperature; // Monitor the temperature value - monitorTemperatureSnsrs( sensorIndex ); + monitorTemperatureSnsrs( sensorIndex, temperature ); } /*********************************************************************//** @@ -837,7 +837,7 @@ { U32 result = tempSensorsPublishInterval.data; - if ( OVERRIDE_KEY == tempSensorsPublishInterval.override ) + if ( tempSensorsPublishInterval.override == OVERRIDE_KEY ) { result = tempSensorsPublishInterval.ovData; } @@ -859,30 +859,30 @@ { TEMPERATURE_SENSORS_DATA_T data; - data.inletPrimaryHeater = getTemperatureValue( TEMPSENSORS_INLET_PRIMARY_HEATER ); - data.outletPrimaryHeater = getTemperatureValue( TEMPSENSORS_OUTLET_PRIMARY_HEATER ); - data.conductivitySensor1 = getTemperatureValue( TEMPSENSORS_CONDUCTIVITY_SENSOR_1 ); - data.conductivitySensor2 = getTemperatureValue( TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ); - data.outletRedundant = getTemperatureValue( TEMPSENSORS_OUTLET_REDUNDANT ); - data.inletDialysate = getTemperatureValue( TEMPSENSORS_INLET_DIALYSATE ); - data.primaryHeaterThermocouple = getTemperatureValue( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE ); - data.trimmerHeaterThermocouple = getTemperatureValue( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE ); - data.priamyHeaterColdjunction = getTemperatureValue( TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ); - data.trimmerHeaterColdjunction = getTemperatureValue( TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ); - data.primaryHeaterInternal = getTemperatureValue( TEMPSENSORS_PRIMARY_HEATER_INTERNAL ); - data.trimmerHeaterInternal = getTemperatureValue( TEMPSENSORS_TRIMMER_HEATER_INTERNAL ); - data.fpgaBoard = getTemperatureValue( TEMPSENSORS_FPGA_BOARD_SENSOR ); - data.loadCellA1B1 = getTemperatureValue( TEMPSENSORS_LOAD_CELL_A1_B1 ); - data.loadCellA2B2 = getTemperatureValue( TEMPSENSORS_LOAD_CELL_A2_B2 ); - data.internalTHDORTD = getTemperatureValue( TEMPSENSORS_INTERNAL_THDO_RTD ); - data.internalTDIRTD = getTemperatureValue( TEMPSENSORS_INTERNAL_TDI_RTD ); - data.internalCondSnsrTemp = getTemperatureValue( TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR ); - data.primaryThermoCoupleRaw = getFPGAPrimaryHeaterTemp(); - data.primaryColdjuncRaw = getFPGAPrimaryColdJunctionTemp(); - data.trimmerThermoCoupleRaw = getFPGATrimmerHeaterTemp(); - data.trimmerColdjuncRaw = getFPGATrimmerColdJunctionTemp(); - data.cond1Raw = tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_1 ].rawADCReads[ MAX_NUM_OF_RAW_ADC_SAMPLES - 1 ]; - data.cond2Raw = tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ].rawADCReads[ MAX_NUM_OF_RAW_ADC_SAMPLES - 1 ]; + data.inletPrimaryHeater = getTemperatureValue( TEMPSENSORS_INLET_PRIMARY_HEATER ); + data.outletPrimaryHeater = getTemperatureValue( TEMPSENSORS_OUTLET_PRIMARY_HEATER ); + data.conductivitySensor1 = getTemperatureValue( TEMPSENSORS_CONDUCTIVITY_SENSOR_1 ); + data.conductivitySensor2 = getTemperatureValue( TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ); + data.outletRedundant = getTemperatureValue( TEMPSENSORS_OUTLET_REDUNDANT ); + data.inletDialysate = getTemperatureValue( TEMPSENSORS_INLET_DIALYSATE ); + data.primaryHeaterThermocouple = getTemperatureValue( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE ); + data.trimmerHeaterThermocouple = getTemperatureValue( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE ); + data.priamyHeaterColdjunction = getTemperatureValue( TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ); + data.trimmerHeaterColdjunction = getTemperatureValue( TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ); + data.primaryHeaterInternal = getTemperatureValue( TEMPSENSORS_PRIMARY_HEATER_INTERNAL ); + data.trimmerHeaterInternal = getTemperatureValue( TEMPSENSORS_TRIMMER_HEATER_INTERNAL ); + data.fpgaBoard = getTemperatureValue( TEMPSENSORS_FPGA_BOARD_SENSOR ); + data.loadCellA1B1 = getTemperatureValue( TEMPSENSORS_LOAD_CELL_A1_B1 ); + data.loadCellA2B2 = getTemperatureValue( TEMPSENSORS_LOAD_CELL_A2_B2 ); + data.internalTHDORTD = getTemperatureValue( TEMPSENSORS_INTERNAL_THDO_RTD ); + data.internalTDIRTD = getTemperatureValue( TEMPSENSORS_INTERNAL_TDI_RTD ); + data.internalCondSnsrTemp = getTemperatureValue( TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR ); + data.primaryThermoCoupleRaw = getFPGAPrimaryHeaterTemp(); + data.primaryColdjuncRaw = getFPGAPrimaryColdJunctionTemp(); + data.trimmerThermoCoupleRaw = getFPGATrimmerHeaterTemp(); + data.trimmerColdjuncRaw = getFPGATrimmerColdJunctionTemp(); + data.cond1Raw = tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_1 ].rawADCReads[ MAX_NUM_OF_RAW_ADC_SAMPLES - 1 ]; + data.cond2Raw = tempSensors[ TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ].rawADCReads[ MAX_NUM_OF_RAW_ADC_SAMPLES - 1 ]; broadcastTemperatureSensorsData( &data ); @@ -898,14 +898,17 @@ * @details Inputs: tempSensors * @details Outputs: tempSensors * @param sensorIndex the index of the temperature sensor + * @param temperature the temperature value to be checked * @return none *************************************************************************/ -static void monitorTemperatureSnsrs( U32 sensorIndex ) +static void monitorTemperatureSnsrs( U32 sensorIndex, F32 temperature ) { - F32 temperature = getTemperatureValue( sensorIndex ); + // The maximum allowed temperature is different for the sensors that are in the fluid path + // with the ones that are not in the fluid path + F32 maxLimit = tempSensors[ sensorIndex ].maxAllowedTemperature; // Check both temperature and to be in range - if ( ( temperature < TEMP_SENSORS_MIN_ALLOWED_DEGREE_C ) || ( temperature > tempSensors[ sensorIndex ].maxAllowedTemperature ) ) + if ( ( temperature < TEMP_SENSORS_MIN_ALLOWED_DEGREE_C ) || ( temperature > maxLimit ) ) { // TODO investigate //checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_OUT_OF_RANGE, TRUE, sensorIndex, temperature ); @@ -934,7 +937,7 @@ if ( sensorIndex < NUM_OF_TEMPERATURE_SENSORS ) { - if ( TRUE == isTestingActivated() ) + if ( isTestingActivated() ) { result = TRUE; tempSensors[ sensorIndex ].temperatureValues.ovData = temperature; @@ -960,7 +963,7 @@ if ( sensorIndex < NUM_OF_TEMPERATURE_SENSORS ) { - if ( TRUE == isTestingActivated() ) + if ( isTestingActivated() ) { result = TRUE; tempSensors[ sensorIndex ].temperatureValues.override = OVERRIDE_RESET; @@ -984,7 +987,7 @@ { BOOL result = FALSE; - if ( TRUE == isTestingActivated() ) + if ( isTestingActivated() ) { U32 interval = value / TASK_PRIORITY_INTERVAL; @@ -1008,7 +1011,7 @@ { BOOL result = FALSE; - if ( TRUE == isTestingActivated() ) + if ( isTestingActivated() ) { result = TRUE; tempSensorsPublishInterval.override = OVERRIDE_RESET; Index: firmware/App/Controllers/Thermistors.c =================================================================== diff -u -r22f1a58ac8e419353ec004b04e7c765c1d59df2b -r2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c --- firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision 22f1a58ac8e419353ec004b04e7c765c1d59df2b) +++ firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision 2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c) @@ -22,7 +22,8 @@ #define THERMISTOR_REFERENCE_VOLTAGE 3.0 ///< Thermistors source voltage. #define THERMISTOR_REFERENCE_RESISTOR_AT_25 10000.0 ///< Thermistors reference resistor in ohms. #define THERMISTOR_REFERENCE_TEMPERATURE 298.0 ///< Thermistors reference temperature in kelvin. -#define THERMISTOR_BETA_VALUE 3380.0 ///< Thermistors beta value. +#define ONBOARD_THERMISTOR_BETA_VALUE 3380.0 ///< Onboard thermistor beta value. +#define POWER_SUPPLY_THERMISTOR_BETA_VALUE 3345.0 ///< Power supply beta value. #define CELSIUS_TO_KELVIN_CONVERSION 273.15 ///< Celsius to Kelvin temperature conversion. #define MIN_ALLOWED_TEMPERATURE 0.0 ///< Thermistors/sensors minimum allowed temperature reading. #define MAX_ALLOWED_TEMPERATURE 80.0 ///< Thermistors/sensors maximum allowed temperature reading. @@ -31,16 +32,17 @@ /// Thermistors exec states typedef enum thermistors_Exec_States { - THERMISTORS_EXEC_STATE_START_STATE = 0, ///< Thermistors exec state start state. - THERMISTORS_EXEC_STATE_GET_ADC_VALUES_STATE, ///< Thermistors exec state get ADC values state. - NUM_OF_THERMISTORS_EXEC_STATES, ///< Number of thermistors exec state. + THERMISTORS_EXEC_STATE_START_STATE = 0, ///< Thermistors exec state start state + THERMISTORS_EXEC_STATE_GET_ADC_VALUES_STATE, ///< Thermistors exec state get ADC values state + NUM_OF_THERMISTORS_EXEC_STATES, ///< Number of thermistors exec state } THERMISTORS_EXEC_STATES_T; /// Thermistor struct typedef struct { - S32 rawADCRead; ///< Thermistor raw ADC read. - OVERRIDE_F32_T temperatureValue; ///< Thermistor temperature value. + S32 rawADCRead; ///< Thermistor raw ADC read + OVERRIDE_F32_T temperatureValue; ///< Thermistor temperature value + F32 betaValue; ///< Thermistor beta value used to calculate temperature } THERMISTOR_T; static THERMISTORS_EXEC_STATES_T thermistorsExecState = THERMISTORS_EXEC_STATE_START_STATE; ///< Thermistors exec state. @@ -51,8 +53,8 @@ static U32 adcReadCounter; ///< Thermistors ADC read counter. static const F32 THERMISTOR_VOLTAGE_CONV_COEFF = THERMISTOR_REFERENCE_VOLTAGE / - (F32)TWELVE_BIT_RESOLUTION; ///< Thermistors ADC to voltage conversion coefficient. -static const F32 THERMISTOR_REF_TEMP_INV = 1 / THERMISTOR_REFERENCE_TEMPERATURE; ///< Thermistors reference inverse. + (F32)TWELVE_BIT_RESOLUTION; ///< On board thermistor ADC to voltage conversion coefficient. +static const F32 ON_BOARD_THERMISTOR_REF_TEMP_INV = 1 / THERMISTOR_REFERENCE_TEMPERATURE; ///< On board thermistor reference inverse. // ********** private function prototypes ********** @@ -61,7 +63,7 @@ static void monitorThermistors( void ); static void convertADC2Temperature( void ); -static F32 calculateThemristorTemperature( U32 adcValue ); +static F32 calculateOnBoardThemristorTemperature( U32 adcValue, F32 betaValue ); static void publishThermistorsData( void ); static U32 getPublishThermistorsDataInterval( void ); @@ -78,6 +80,11 @@ thermistorsExecState = THERMISTORS_EXEC_STATE_START_STATE; dataPublishCounter = 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( ALARM_ID_DG_THERMISTORS_TEMPERATURE_OUT_OF_RANGE, MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD, MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD ); } @@ -126,15 +133,6 @@ break; } - // First convert the values - convertADC2Temperature(); - - // Monitor the values for a gross range check - // Monitor is called in this function because this driver is constantly reading - // the thermistor values. Also the internal ADC values are processed with moving average in the internalADC driver - // So the thermistors drivers just gets the latest ADC value and converts it to temperature - monitorThermistors(); - // Check if it is time to publish any data publishThermistorsData(); } @@ -155,7 +153,7 @@ // Check if the thermistor of sensor is in range if ( thermistor < NUM_OF_THERMISTORS ) { - if ( OVERRIDE_KEY == thermistorsStatus[ thermistor ].temperatureValue.override ) + if ( thermistorsStatus[ thermistor ].temperatureValue.override == OVERRIDE_KEY ) { temperature = thermistorsStatus[ thermistor ].temperatureValue.ovData; } @@ -214,6 +212,12 @@ 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 ); + // Monitor the values for a gross range check + // Monitor is called in this function because this driver is constantly reading + // the thermistor values. Also the internal ADC values are processed with moving average in the internalADC driver + // So the thermistors drivers just gets the latest ADC value and converts it to temperature + monitorThermistors(); + // Zero the counter for the next round of reading adcReadCounter = 0; } @@ -234,10 +238,13 @@ 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 ); - BOOL isTempOutOfRange = ( temperature > MAX_ALLOWED_TEMPERATURE ) || ( temperature < MIN_ALLOWED_TEMPERATURE ); + BOOL const isTempOutOfRange = ( temperature > MAX_ALLOWED_TEMPERATURE ) || ( temperature < MIN_ALLOWED_TEMPERATURE ); checkPersistentAlarm( ALARM_ID_DG_THERMISTORS_TEMPERATURE_OUT_OF_RANGE, isTempOutOfRange, temperature, MAX_ALLOWED_TEMPERATURE ); } @@ -247,55 +254,59 @@ * @brief * The convertADCtoTemperature function converts the ADC values of different * thermistors and temperature sensors to temperature value. - * @details Inputs: none + * @details Inputs: thermistorsStatus, fpgaBoardTempSensorConvCoeff, + * adcTempSensorsConversionCoeff1, adcTempSensorsConversionCoeff2 * @details Outputs: thermistorsStatus * @return none *************************************************************************/ static void convertADC2Temperature( void ) { THERMISTORS_TEMP_SENSORS_T thermistor; F32 temperature; - S32 rawADC; + U32 rawADC; // Loop through the list and update the temperature values for ( thermistor = THERMISTOR_ONBOARD_NTC; thermistor < NUM_OF_THERMISTORS; thermistor++ ) { - rawADC = (S32)thermistorsStatus[ thermistor ].rawADCRead; + rawADC = thermistorsStatus[ thermistor ].rawADCRead; - temperature = calculateThemristorTemperature( rawADC ); + temperature = calculateOnBoardThemristorTemperature( rawADC, thermistorsStatus[ thermistor ].betaValue ); thermistorsStatus[ thermistor ].temperatureValue.data = temperature; } } /*********************************************************************//** * @brief - * The calculateThemristorTemperature function converts the ADC value - * of thermistors into temperature in C. Below are the calculation + * The calculateOnBoardThemristorTemperature function converts the ADC value + * of the onboard thermistor into temperature in C. Below are the calculation * steps: * voltage = ADC x 3 / 2^12 * 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: none + * @details Inputs: onBoardThermistorVoltageConvCoeff, + * onBoardThermistorBetaValueInv * @details Outputs: none * @param ADC value to be converted into temperature in C + * @param beta value which is used to calculate temperature from ADC * @return calculated temperature in C *************************************************************************/ -static F32 calculateThemristorTemperature( U32 adcValue ) +static F32 calculateOnBoardThemristorTemperature( U32 adcValue, F32 betaValue ) { // Voltage = ADC x 3 / 2^12 for 12 bits resolution and a 3V ADC // The value of 3 / 2^12 has been calculated in a const to prevent the division again - F32 thermistorVoltage = adcValue * THERMISTOR_VOLTAGE_CONV_COEFF; + F32 const thermistorVoltage = adcValue * THERMISTOR_VOLTAGE_CONV_COEFF; // Calculate the thermistor resistor by solving: thermistorVoltage = (3 x 10) / (10 + R(T)) - F32 thermistorResistor = ( ( THERMISTOR_REFERENCE_RESISTOR_AT_25 * THERMISTOR_REFERENCE_VOLTAGE ) - - ( THERMISTOR_REFERENCE_RESISTOR_AT_25 * thermistorVoltage ) ) / thermistorVoltage; + 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 invTemperature = ( logf( thermistorResistor / THERMISTOR_REFERENCE_RESISTOR_AT_25 ) / THERMISTOR_BETA_VALUE ) + THERMISTOR_REF_TEMP_INV; + F32 const invTemperature = ( logf( thermistorResistor / THERMISTOR_REFERENCE_RESISTOR_AT_25 ) / betaValue ) + + ON_BOARD_THERMISTOR_REF_TEMP_INV; // Inverse the value to get the temperature in Kelvin and then convert it to Celsius - F32 temperature = ( 1 / invTemperature ) - CELSIUS_TO_KELVIN_CONVERSION; + F32 const temperature = ( 1 / invTemperature ) - CELSIUS_TO_KELVIN_CONVERSION; return temperature; } @@ -414,11 +425,11 @@ { BOOL result = FALSE; - if ( ( thermistor < NUM_OF_THERMISTORS ) && ( TRUE == isTestingActivated() ) ) + if ( thermistor < NUM_OF_THERMISTORS && isTestingActivated() ) { // There is a temperature range that the thermistors can be set to, otherwise, the driver // will throw an alarm. Also, the fans driver depends on these values to continuously control the fans - if ( ( temperature >= MIN_ALLOWED_TEMPERATURE ) && ( temperature < MAX_ALLOWED_TEMPERATURE ) ) + if ( temperature >= MIN_ALLOWED_TEMPERATURE && temperature < MAX_ALLOWED_TEMPERATURE ) { result = TRUE; thermistorsStatus[ thermistor ].temperatureValue.ovData = temperature; @@ -442,7 +453,7 @@ { BOOL result = FALSE; - if ( TRUE == isTestingActivated() ) + if ( isTestingActivated() ) { if ( thermistor < NUM_OF_THERMISTORS ) { Index: firmware/App/Modes/ModeInitPOST.c =================================================================== diff -u -rc0375e039dd42ecf7b7d68ce7f2407e52dfe83eb -r2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c --- firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision c0375e039dd42ecf7b7d68ce7f2407e52dfe83eb) +++ firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c) @@ -282,15 +282,15 @@ { DG_POST_STATE_T result = postState; - if ( ( SELF_TEST_STATUS_PASSED == testStatus ) || ( SELF_TEST_STATUS_FAILED == testStatus ) ) + if ( ( testStatus == SELF_TEST_STATUS_PASSED ) || ( testStatus == SELF_TEST_STATUS_FAILED ) ) { - BOOL passed = ( SELF_TEST_STATUS_PASSED == testStatus ? TRUE : FALSE ); + BOOL passed = ( testStatus == SELF_TEST_STATUS_PASSED ? TRUE : FALSE ); // Broadcast passed POST result sendPOSTTestResult( (DG_POST_STATE_T)((int)postState), passed ); // Move on to next POST test result = (DG_POST_STATE_T)((int)postState + 1); - if ( SELF_TEST_STATUS_FAILED == testStatus ) + if ( testStatus == SELF_TEST_STATUS_FAILED ) { tempPOSTPassed = FALSE; } Index: firmware/App/Services/FPGA.c =================================================================== diff -u -rddb9707d9e6e46c4b384782aeec20d41f3822996 -r2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision ddb9707d9e6e46c4b384782aeec20d41f3822996) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision 2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c) @@ -82,8 +82,8 @@ #define FPGA_FLUIDLEAK_STATE_MASK 0x0004 ///< Bit mask for fluid leak detector. #define FLUID_DOOR_SWITCH_MASK 0x08 ///< Fluid door switch bit mask. -#define CONCENTRATE_CAP_SWITCH_MASK 0x10 ///< Concentrate cap switch bit mask -#define DIALYSATE_CAP_SWITCH_MASK 0x20 ///< Dialysate cap switch bit mask.. +#define DIALYSATE_CAP_SWITCH_MASK 0x10 ///< Dialysate cap switch bit mask. +#define CONCENTRATE_CAP_SWITCH_MASK 0x1A ///< Concentrate cap switch bit mask. #define FPGA_POWER_OUT_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< FPGA power out timeout in milliseconds. #define FPGA_GPIO_POWER_STATUS_PIN 7 ///< FPGA GPIO power status pin Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -rc0375e039dd42ecf7b7d68ce7f2407e52dfe83eb -r2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision c0375e039dd42ecf7b7d68ce7f2407e52dfe83eb) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c) @@ -1269,13 +1269,9 @@ break; case MSG_ID_FILTER_FLUSH_TIME_PERIOD_OVERRIDE: - handleFilterFlushTimePeriodOverride( message ); + handleFilterFlushTimePeriodOverride(message); break; - case MSG_ID_DG_FANS_RPM_OVERRIDE: - handleFansRPMOverride( message ); - break; - case MSG_ID_DG_OP_MODE_PUBLISH_INTERVAL_OVERRIDE: handleSetDGOpModeBroadcastIntervalOverrideRequest( message ); break; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -rc0375e039dd42ecf7b7d68ce7f2407e52dfe83eb -r2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision c0375e039dd42ecf7b7d68ce7f2407e52dfe83eb) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c) @@ -22,7 +22,6 @@ #include "Accel.h" #include "ConcentratePumps.h" #include "ConductivitySensors.h" -#include "Fans.h" #include "FPGA.h" #include "Heaters.h" #include "ModeFlush.h" @@ -3604,37 +3603,6 @@ } /*********************************************************************//** - * @brief - * The handleFansRPMOverride function handles a request to override a fans RPM value. - * @details Inputs: none - * @details Outputs: message handled - * @param message a pointer to the message to handle - * @return none - *************************************************************************/ -void handleFansRPMOverride( MESSAGE_T *message ) -{ - TEST_OVERRIDE_ARRAY_PAYLOAD_T payload; - BOOL result = FALSE; - - // verify payload length - if ( sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) == message->hdr.payloadLen ) - { - memcpy( &payload, message->payload, sizeof(TEST_OVERRIDE_ARRAY_PAYLOAD_T) ); - if ( FALSE == payload.reset ) - { - result = testSetFanRPMOverride( payload.index, payload.state.f32 ); - } - else - { - result = testResetFanRPMOverride( payload.index ); - } - } - - // respond to request - sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); -} - -/*********************************************************************//** * @brief * The handleStartStopDGChemicalDisinfect function handles a request to start * or stop DG chemical disinfect mode. Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -rc0375e039dd42ecf7b7d68ce7f2407e52dfe83eb -r2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision c0375e039dd42ecf7b7d68ce7f2407e52dfe83eb) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 2d8f95eaae3bcb7027f5e96809ddc6e9c0efbc4c) @@ -390,9 +390,6 @@ // MSG_ID_DG_OP_MODE_PUBLISH_INTERVAL_OVERRIDE BOOL handleSetDGOpModeBroadcastIntervalOverrideRequest( MESSAGE_T *message ); -// MSG_ID_DG_FANS_RPM_OVERRIDE -void handleFansRPMOverride( MESSAGE_T *message ); - /**@}*/ #endif