Index: firmware/App/Controllers/Fans.c =================================================================== diff -u -r67021fbc633259e8e1bce76749dbef7d0cb51998 -rddb9707d9e6e46c4b384782aeec20d41f3822996 --- firmware/App/Controllers/Fans.c (.../Fans.c) (revision 67021fbc633259e8e1bce76749dbef7d0cb51998) +++ firmware/App/Controllers/Fans.c (.../Fans.c) (revision ddb9707d9e6e46c4b384782aeec20d41f3822996) @@ -6,7 +6,9 @@ #include "PersistentAlarm.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" +#include "TemperatureSensors.h" #include "Thermistors.h" +#include "Timers.h" /** * @addtogroup Fans @@ -15,67 +17,60 @@ // ********** 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 - U32 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 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. /// 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 ); @@ -105,6 +100,8 @@ fansPublishCounter = 0; fansMonitorCounter = 0; isPOSTComplete = FALSE; + hasAlarmBeenRaised = FALSE; + rpmAlarmStartTimer = 0; // 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 ); @@ -139,9 +136,6 @@ *************************************************************************/ 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: @@ -158,6 +152,12 @@ break; } + // Convert the counts to RPM + convertTogglePeriod2RPM(); + + // Monitor the RPM of the fans + monitorFans(); + publishFansData(); } @@ -325,30 +325,40 @@ { F32 temperature; THERMISTORS_TEMP_SENSORS_T thermistor; - F32 maxTemperature = 0.0; + F32 maxTemperature; // Loop through the sensors and thermistors for ( thermistor = THERMISTOR_ONBOARD_NTC; thermistor < NUM_OF_THERMISTORS; thermistor++ ) { - // Get the value temperature = getThermistorTemperatureValue( thermistor ); - - // If the latest temperature read is greater than the max temperature, - // set the maximum temperature there - if ( temperature > maxTemperature ) - { - maxTemperature = temperature; - } + maxTemperature = ( temperature > maxTemperature ? temperature : maxTemperature ); } + // 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: fansStatus, toggle2RPMCoefficient + * @details Inputs: none * @details Outputs: fansStatus * @return none ************************************************************************/ @@ -383,8 +393,8 @@ /*********************************************************************//** * @brief * The monitorFans function monitors the fans for RPM. - * @details Inputs: fansStatus - * @details Outputs: none + * @details Inputs: fansMonitorCounter, fansStatus + * @details Outputs: fansMonitorCounter * @return none *************************************************************************/ static void monitorFans( void ) @@ -393,19 +403,36 @@ if ( ++fansMonitorCounter >= FANS_MONITOR_INTERVAL_COUNT ) { - // 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 ); + // If the fans alarm has been raise already, do not raise again + if ( FALSE == hasAlarmBeenRaised ) + { + BOOL isFanRPMOutOfRange; - convertTogglePeriod2RPM(); + // 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 ); - for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) + for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) + { + isFanRPMOutOfRange = ( fansStatus.rpm[ fan ] < fansMinAllowedRPM ) || ( fansStatus.rpm[ fan ] > fansMaxAllowedRPM ); + checkPersistentAlarm( ALARM_ID_DG_FAN_RPM_OUT_OF_RANGE, isFanRPMOutOfRange, fansStatus.rpm[ 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 ) ) ) { - 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 ); + hasAlarmBeenRaised = FALSE; + rpmAlarmStartTimer = 0; } fansMonitorCounter = 0; Index: firmware/App/Controllers/Switches.c =================================================================== diff -u -r8ee6a4ee6ae356143104f93551d10d7a875eaad1 -rddb9707d9e6e46c4b384782aeec20d41f3822996 --- firmware/App/Controllers/Switches.c (.../Switches.c) (revision 8ee6a4ee6ae356143104f93551d10d7a875eaad1) +++ firmware/App/Controllers/Switches.c (.../Switches.c) (revision ddb9707d9e6e46c4b384782aeec20d41f3822996) @@ -78,15 +78,15 @@ switch ( i ) { case CONCENTRATE_CAP: - currentSwitchStatus = getFPGAConcentrateCapStatus(); + currentSwitchStatus = ( getFPGAConcentrateCapStatus() != 0 ? STATE_OPEN : STATE_CLOSED ); break; case DIALYSATE_CAP: - currentSwitchStatus = getFPGADialysateCapStatus(); + currentSwitchStatus = ( getFPGADialysateCapStatus() != 0 ? STATE_OPEN : STATE_CLOSED ); break; case FLUID_DOOR: - currentSwitchStatus = getFPGAGFluidDoorStatus(); + currentSwitchStatus = ( getFPGAGFluidDoorStatus() != 0 ? STATE_OPEN : STATE_CLOSED ); break; default: Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -rc55d371408bdf962de525a47bc8541d5b43414a3 -rddb9707d9e6e46c4b384782aeec20d41f3822996 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision c55d371408bdf962de525a47bc8541d5b43414a3) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision ddb9707d9e6e46c4b384782aeec20d41f3822996) @@ -163,7 +163,7 @@ static void processADCRead( U32 sensorIndex, S32 adc ); static U32 getPublishTemperatureSensorsDataInterval( void ); static void publishTemperatureSensorsData( void ); -static void monitorTemperatureSnsrs( U32 sensorIndex, F32 temperature ); +static void monitorTemperatureSnsrs( U32 sensorIndex ); /*********************************************************************//** * @brief @@ -372,7 +372,7 @@ if ( sensorIndex < NUM_OF_TEMPERATURE_SENSORS ) { - if ( tempSensors[ sensorIndex ].temperatureValues.override == OVERRIDE_KEY ) + if ( OVERRIDE_KEY == tempSensors[ sensorIndex ].temperatureValues.override ) { temperature = tempSensors[ sensorIndex ].temperatureValues.ovData; } @@ -712,7 +712,7 @@ tempSensors[ sensorIndex ].temperatureValues.data = temperature; // Monitor the temperature value - monitorTemperatureSnsrs( sensorIndex, temperature ); + monitorTemperatureSnsrs( sensorIndex ); } /*********************************************************************//** @@ -837,7 +837,7 @@ { U32 result = tempSensorsPublishInterval.data; - if ( tempSensorsPublishInterval.override == OVERRIDE_KEY ) + if ( OVERRIDE_KEY == tempSensorsPublishInterval.override ) { 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,17 +898,14 @@ * @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, F32 temperature ) +static void monitorTemperatureSnsrs( U32 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; + F32 temperature = getTemperatureValue( sensorIndex ); // Check both temperature and to be in range - if ( ( temperature < TEMP_SENSORS_MIN_ALLOWED_DEGREE_C ) || ( temperature > maxLimit ) ) + if ( ( temperature < TEMP_SENSORS_MIN_ALLOWED_DEGREE_C ) || ( temperature > tempSensors[ sensorIndex ].maxAllowedTemperature ) ) { // TODO investigate //checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_OUT_OF_RANGE, TRUE, sensorIndex, temperature ); @@ -937,7 +934,7 @@ if ( sensorIndex < NUM_OF_TEMPERATURE_SENSORS ) { - if ( isTestingActivated() ) + if ( TRUE == isTestingActivated() ) { result = TRUE; tempSensors[ sensorIndex ].temperatureValues.ovData = temperature; @@ -963,7 +960,7 @@ if ( sensorIndex < NUM_OF_TEMPERATURE_SENSORS ) { - if ( isTestingActivated() ) + if ( TRUE == isTestingActivated() ) { result = TRUE; tempSensors[ sensorIndex ].temperatureValues.override = OVERRIDE_RESET; @@ -987,7 +984,7 @@ { BOOL result = FALSE; - if ( isTestingActivated() ) + if ( TRUE == isTestingActivated() ) { U32 interval = value / TASK_PRIORITY_INTERVAL; @@ -1011,7 +1008,7 @@ { BOOL result = FALSE; - if ( isTestingActivated() ) + if ( TRUE == isTestingActivated() ) { result = TRUE; tempSensorsPublishInterval.override = OVERRIDE_RESET; Index: firmware/App/Controllers/Thermistors.c =================================================================== diff -u -re3705410a6e4df70c2a4f2d590e977326e11d7b3 -rddb9707d9e6e46c4b384782aeec20d41f3822996 --- firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision e3705410a6e4df70c2a4f2d590e977326e11d7b3) +++ firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision ddb9707d9e6e46c4b384782aeec20d41f3822996) @@ -22,8 +22,7 @@ #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 ONBOARD_THERMISTOR_BETA_VALUE 3380.0 ///< Onboard thermistor beta value. -#define POWER_SUPPLY_THERMISTOR_BETA_VALUE 3345.0 ///< Power supply beta value. +#define THERMISTOR_BETA_VALUE 3380.0 ///< Thermistors 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. @@ -32,17 +31,16 @@ /// 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 - F32 betaValue; ///< Thermistor beta value used to calculate temperature + S32 rawADCRead; ///< Thermistor raw ADC read. + OVERRIDE_F32_T temperatureValue; ///< Thermistor temperature value. } THERMISTOR_T; static THERMISTORS_EXEC_STATES_T thermistorsExecState = THERMISTORS_EXEC_STATE_START_STATE; ///< Thermistors exec state. @@ -53,8 +51,8 @@ static U32 adcReadCounter; ///< Thermistors ADC read counter. 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. + (F32)TWELVE_BIT_RESOLUTION; ///< Thermistors ADC to voltage conversion coefficient. +static const F32 THERMISTOR_REF_TEMP_INV = 1 / THERMISTOR_REFERENCE_TEMPERATURE; ///< Thermistors reference inverse. // ********** private function prototypes ********** @@ -63,7 +61,7 @@ static void monitorThermistors( void ); static void convertADC2Temperature( void ); -static F32 calculateOnBoardThemristorTemperature( U32 adcValue, F32 betaValue ); +static F32 calculateThemristorTemperature( U32 adcValue ); static void publishThermistorsData( void ); static U32 getPublishThermistorsDataInterval( void ); @@ -80,11 +78,6 @@ 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 ); } @@ -153,7 +146,7 @@ // Check if the thermistor of sensor is in range if ( thermistor < NUM_OF_THERMISTORS ) { - if ( thermistorsStatus[ thermistor ].temperatureValue.override == OVERRIDE_KEY ) + if ( OVERRIDE_KEY == thermistorsStatus[ thermistor ].temperatureValue.override ) { temperature = thermistorsStatus[ thermistor ].temperatureValue.ovData; } @@ -254,59 +247,55 @@ * @brief * The convertADCtoTemperature function converts the ADC values of different * thermistors and temperature sensors to temperature value. - * @details Inputs: thermistorsStatus, fpgaBoardTempSensorConvCoeff, - * adcTempSensorsConversionCoeff1, adcTempSensorsConversionCoeff2 + * @details Inputs: none * @details Outputs: thermistorsStatus * @return none *************************************************************************/ static void convertADC2Temperature( void ) { THERMISTORS_TEMP_SENSORS_T thermistor; F32 temperature; - U32 rawADC; + S32 rawADC; // Loop through the list and update the temperature values for ( thermistor = THERMISTOR_ONBOARD_NTC; thermistor < NUM_OF_THERMISTORS; thermistor++ ) { - rawADC = thermistorsStatus[ thermistor ].rawADCRead; + rawADC = (S32)thermistorsStatus[ thermistor ].rawADCRead; - temperature = calculateOnBoardThemristorTemperature( rawADC, thermistorsStatus[ thermistor ].betaValue ); + temperature = calculateThemristorTemperature( rawADC ); thermistorsStatus[ thermistor ].temperatureValue.data = temperature; } } /*********************************************************************//** * @brief - * The calculateOnBoardThemristorTemperature function converts the ADC value - * of the onboard thermistor into temperature in C. Below are the calculation + * The calculateThemristorTemperature function converts the ADC value + * of thermistors 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 Inputs: none * @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 calculateOnBoardThemristorTemperature( U32 adcValue, F32 betaValue ) +static F32 calculateThemristorTemperature( U32 adcValue ) { // 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 * THERMISTOR_VOLTAGE_CONV_COEFF; + F32 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; + F32 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 ) + - ON_BOARD_THERMISTOR_REF_TEMP_INV; + F32 invTemperature = ( logf( thermistorResistor / THERMISTOR_REFERENCE_RESISTOR_AT_25 ) / THERMISTOR_BETA_VALUE ) + 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; + F32 temperature = ( 1 / invTemperature ) - CELSIUS_TO_KELVIN_CONVERSION; return temperature; } @@ -425,11 +414,11 @@ { BOOL result = FALSE; - if ( thermistor < NUM_OF_THERMISTORS && isTestingActivated() ) + if ( ( thermistor < NUM_OF_THERMISTORS ) && ( TRUE == 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; @@ -453,7 +442,7 @@ { BOOL result = FALSE; - if ( isTestingActivated() ) + if ( TRUE == isTestingActivated() ) { if ( thermistor < NUM_OF_THERMISTORS ) { Index: firmware/App/Modes/ModeInitPOST.c =================================================================== diff -u -r67021fbc633259e8e1bce76749dbef7d0cb51998 -rddb9707d9e6e46c4b384782aeec20d41f3822996 --- firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision 67021fbc633259e8e1bce76749dbef7d0cb51998) +++ firmware/App/Modes/ModeInitPOST.c (.../ModeInitPOST.c) (revision ddb9707d9e6e46c4b384782aeec20d41f3822996) @@ -196,6 +196,11 @@ postState = handlePOSTStatus( testStatus ); break; + case DG_POST_STATE_SAFETY_SHUTDOWN: + testStatus = SELF_TEST_STATUS_PASSED; + postState = handlePOSTStatus( testStatus ); + break; + // Should be last POST (and last POST test must be a test that completes in a single call) case DG_POST_STATE_LOAD_CELL: testStatus = execLoadCellsSelfTest(); @@ -276,15 +281,15 @@ { DG_POST_STATE_T result = postState; - if ( ( testStatus == SELF_TEST_STATUS_PASSED ) || ( testStatus == SELF_TEST_STATUS_FAILED ) ) + if ( ( SELF_TEST_STATUS_PASSED == testStatus ) || ( SELF_TEST_STATUS_FAILED == testStatus ) ) { - BOOL passed = ( testStatus == SELF_TEST_STATUS_PASSED ? TRUE : FALSE ); + BOOL passed = ( SELF_TEST_STATUS_PASSED == testStatus ? 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 ( testStatus == SELF_TEST_STATUS_FAILED ) + if ( SELF_TEST_STATUS_FAILED == testStatus ) { tempPOSTPassed = FALSE; } Index: firmware/App/Services/FPGA.c =================================================================== diff -u -r67021fbc633259e8e1bce76749dbef7d0cb51998 -rddb9707d9e6e46c4b384782aeec20d41f3822996 --- firmware/App/Services/FPGA.c (.../FPGA.c) (revision 67021fbc633259e8e1bce76749dbef7d0cb51998) +++ firmware/App/Services/FPGA.c (.../FPGA.c) (revision ddb9707d9e6e46c4b384782aeec20d41f3822996) @@ -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 DIALYSATE_CAP_SWITCH_MASK 0x10 ///< Dialysate cap switch bit mask. -#define CONCENTRATE_CAP_SWITCH_MASK 0x1A ///< Concentrate cap 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 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