Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -rd7926685f2fe3086bab183166119f0965a192a69 -r34ed52c598042fdcfa5526e3b1d46fa09b040199 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision d7926685f2fe3086bab183166119f0965a192a69) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 34ed52c598042fdcfa5526e3b1d46fa09b040199) @@ -344,6 +344,7 @@ *************************************************************************/ void execHeatersMonitor( void ) { + // TODO check for the heaters' fault flags and fault if any of them are at fault it should alarm #ifndef IGNORE_HEATERS_MONITOR F32 primaryHeatersInternalTemp = getTemperatureValue( TEMPSENSORS_PRIMARY_HEATER_INTERNAL ); F32 trimmerHeaterInternalTemp = getTemperatureValue( TEMPSENSORS_TRIMMER_HEATER_INTERNAL ); @@ -390,23 +391,29 @@ #endif /* - * If any of the heaters are on, check if the flow is below than the minimum value + * If any of the heaters are on or any of the heaters' PWMs are not zero, check if the flow is below than the minimum value * If the flow is below minimum for the first time, set the variables * If the flow is below minimum for more than the defined time, stop the heaters and raise the alarm * If the flow is in range, reset the variables + * This is to make sure that any of the heaters do not stay on while there is no flow */ - if ( ( TRUE == isPrimaryHeaterOn ) || ( TRUE == isTrimmerHeaterOn ) ) + BOOL isHeaterOn = ( TRUE == isPrimaryHeaterOn ) || ( TRUE == isTrimmerHeaterOn ); + BOOL isPWMNonZero = ( mainPrimaryHeaterDutyCycle > HEATERS_MIN_DUTY_CYCLE ) || ( smallPrimaryHeaterDutyCycle > HEATERS_MIN_DUTY_CYCLE ) || + ( trimmerHeaterDutyCycle > HEATERS_MIN_DUTY_CYCLE ); + + if ( ( TRUE == isHeaterOn ) || ( TRUE == isPWMNonZero ) ) { - //TODO add a check for the pwm to not be 0 F32 measuredFlow = getMeasuredROFlowRate(); if ( measuredFlow < MIN_RO_FLOWRATE_LPM ) { + // Flow is below minimum for the first time if ( FALSE == isFlowBelowMin ) { isFlowBelowMin = TRUE; heatersOnWithNoFlowTimer = getMSTimerCount(); } + // Flow is below minimum for a long time so raise the alarm else if ( TRUE == didTimeout( heatersOnWithNoFlowTimer, HEATERS_ON_NO_FLOW_TIMEOUT_MS ) ) { stopPrimaryHeater(); @@ -835,12 +842,12 @@ *************************************************************************/ static void resetHeaterState( NAME_OF_HEATER_T heater ) { - if ( heater == PRIMARY_HEATER ) + if ( PRIMARY_HEATER == heater ) { mainPrimaryHeaterDutyCycle = MAIN_PRIMARY_HEATER_MAX_DUTY_CYCLE; resetPIController( PI_CONTROLLER_ID_PRIMARY_HEATER, MAIN_PRIMARY_HEATER_MAX_DUTY_CYCLE ); } - else if ( heater == TRIMMER_HEATER ) + else if ( TRIMMER_HEATER == heater ) { trimmerHeaterDutyCycle = TRIMMER_HEATER_MAX_DUTY_CYCLE; resetPIController( PI_CONTROLLER_ID_TRIMMER_HEATER, TRIMMER_HEATER_MAX_DUTY_CYCLE ); Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -rbbf67569fc5f34815c0e0855dd452de2be5a7976 -r34ed52c598042fdcfa5526e3b1d46fa09b040199 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision bbf67569fc5f34815c0e0855dd452de2be5a7976) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 34ed52c598042fdcfa5526e3b1d46fa09b040199) @@ -713,29 +713,54 @@ *************************************************************************/ static TEMPSENSORS_EXEC_STATES_T handleExecGetADCValues( void ) { + U32 rawADC = 0; + U32 errorCount = 0; + U32 readCount = 0; + // 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 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() ); + rawADC = getFPGATPiTemp(); + errorCount = (U32)getFPGARTDErrorCount(); + readCount = (U32)getFPGARTDReadCount(); + processTempSnsrsADCRead( TEMPSENSORS_INLET_PRIMARY_HEATER, rawADC, errorCount, readCount ); - processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, getFPGAPrimaryHeaterTemp(), getFPGAPrimaryHeaterFlags(), - getFPGAPrimaryHeaterReadCount() ); + rawADC = getFPGATPoTemp(); + processTempSnsrsADCRead( TEMPSENSORS_OUTLET_PRIMARY_HEATER, rawADC, errorCount, readCount ); - processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, getFPGATrimmerHeaterTemp(), getFPGATrimmerHeaterFlags(), - getFPGATrimmerHeaterReadCount() ); + rawADC = getFPGACD1Temp(); + processTempSnsrsADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_1, rawADC, errorCount, readCount ); - processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION, getFPGAPrimaryColdJunctionTemp(), getFPGATrimmerHeaterFlags(), - getFPGAPrimaryHeaterReadCount() ); + rawADC = getFPGACD2Temp(); + processTempSnsrsADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_2, rawADC, errorCount, readCount ); - processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION, getFPGATrimmerColdJunctionTemp(), getFPGATrimmerHeaterFlags(), - getFPGATrimmerHeaterReadCount() ); + rawADC = getFPGATHDoTemp(); + errorCount = (U32)getFPGATHDoErrorCount(); + readCount = (U32)getFPGATHDoReadCount(); + processTempSnsrsADCRead( TEMPSENSORS_OUTLET_REDUNDANT, rawADC, errorCount, readCount ); + rawADC = getFPGATDiTemp(); + errorCount = (U32)getFPGATDiErrorCount(); + readCount = (U32)getFPGATDiReadCount(); + processTempSnsrsADCRead( TEMPSENSORS_INLET_DIALYSATE, rawADC, errorCount, readCount ); + + rawADC = getFPGAPrimaryHeaterTemp(); + errorCount = (U32)getFPGAPrimaryHeaterFlags(); + readCount = (U32)getFPGAPrimaryHeaterReadCount(); + processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, rawADC, errorCount, readCount ); + + rawADC = getFPGAPrimaryColdJunctionTemp(); + processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION, rawADC, errorCount, readCount ); + + rawADC = getFPGATrimmerHeaterTemp(); + errorCount = (U32)getFPGATrimmerHeaterFlags(); + readCount = (U32)getFPGATrimmerHeaterReadCount(); + processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, rawADC, errorCount, readCount ); + + rawADC = getFPGATrimmerHeaterTemp(); + processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION, rawADC, errorCount, readCount ); + // 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 internally so there will not be any errors. Index: firmware/App/Controllers/TemperatureSensors.h =================================================================== diff -u -rbbf67569fc5f34815c0e0855dd452de2be5a7976 -r34ed52c598042fdcfa5526e3b1d46fa09b040199 --- firmware/App/Controllers/TemperatureSensors.h (.../TemperatureSensors.h) (revision bbf67569fc5f34815c0e0855dd452de2be5a7976) +++ firmware/App/Controllers/TemperatureSensors.h (.../TemperatureSensors.h) (revision 34ed52c598042fdcfa5526e3b1d46fa09b040199) @@ -58,30 +58,30 @@ /// Temperature sensors data. typedef struct { - F32 inletPrimaryHeater; - F32 outletPrimaryHeater; - F32 conductivitySensor1; - F32 conductivitySensor2; - F32 outletRedundant; - F32 inletDialysate; - F32 primaryHeaterThermocouple; - F32 trimmerHeaterThermocouple; - F32 priamyHeaterColdjunction; - F32 trimmerHeaterColdjunction; - F32 primaryHeaterInternal; - F32 trimmerHeaterInternal; - F32 fpgaBoard; - F32 loadCellA1B1; - F32 loadCellA2B2; - F32 internalTHDORTD; - F32 internalTDIRTD; - F32 internalCondSnsrTemp; - U32 primaryThermoCoupleRaw; - U32 primaryColdjuncRaw; - U32 trimmerThermoCoupleRaw; - U32 trimmerColdjuncRaw; - S32 cond1Raw; - S32 cond2Raw; + F32 inletPrimaryHeater; ///< Inlet primary heater temperature sensor + F32 outletPrimaryHeater; ///< Outlet primary heater temperature sensor + F32 conductivitySensor1; ///< Conductivity sensor 1 temperature sensor + F32 conductivitySensor2; ///< Conductivity sensor 2 temperature sensor + F32 outletRedundant; ///< Outlet redundant temperature sensor + F32 inletDialysate; ///< Inlet dialysate temperature sensor + F32 primaryHeaterThermocouple; ///< Primary heaters thermocouple sensor + F32 trimmerHeaterThermocouple; ///< Trimmer heater thermocouple sensor + F32 priamyHeaterColdjunction; ///< Primary heaters cold junction temperature sensor + F32 trimmerHeaterColdjunction; ///< Trimmer heater cold junction temperature sensor + F32 primaryHeaterInternal; ///< Primary heaters internal temperature (calculated from thermocouple and cold junction) + F32 trimmerHeaterInternal; ///< Trimmer heater internal temperature (calculated from thermocouple and cold junction) + F32 fpgaBoard; ///< FPGA board temperature sensor + F32 loadCellA1B1; ///< Load cell A1/B1 temperature sensor + F32 loadCellA2B2; ///< Load cell A2/B2 temperature sensor + F32 internalTHDORTD; ///< THDo RTD channel temperature sensor + F32 internalTDIRTD; ///< TDI RTD channel temperature sensor + F32 internalCondSnsrTemp; ///< Conductivity Sensor internal temperature sensor + U32 primaryThermoCoupleRaw; ///< Primary heaters thermocouple raw ADC value + U32 primaryColdjuncRaw; ///< Primary heaters cold junction raw ADC value + U32 trimmerThermoCoupleRaw; ///< Trimmer heater thermocouple raw ADC value + U32 trimmerColdjuncRaw; ///< Trimmer heater cold junction raw ADC value + S32 cond1Raw; ///< Conductivity sensor 1 raw temperature ADC value + S32 cond2Raw; ///< Conductivity sensor 2 raw temperature ADC value } TEMPERATURE_SENSORS_DATA_T; // ********** public function prototypes ********** Index: firmware/App/Modes/ModeFlush.c =================================================================== diff -u -r1a7b3fdc8c9b47ae713a7ec37670a96df7d73818 -r34ed52c598042fdcfa5526e3b1d46fa09b040199 --- firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 1a7b3fdc8c9b47ae713a7ec37670a96df7d73818) +++ firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 34ed52c598042fdcfa5526e3b1d46fa09b040199) @@ -278,8 +278,8 @@ * The handleFlushModeStartState function handles the flush start state. * If the sensors are in range, it transitions to the next state otherwise, * it transitions to basic cancellation state. - * @details Inputs: stateTimer, rsrvr1Status - * @details Outputs: stateTimer, rsrvr1Status + * @details Inputs: stateTimerStart, rsrvr1Status + * @details Outputs: stateTimerStart, rsrvr1Status * @return next state of the flush state machine *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeStartState( void ) @@ -311,8 +311,8 @@ * The handleFlushModeDrainR1State function handles the drain reservoir 1. * If the drain is completed within the defined time, it transitions to the * next state, otherwise, it transitions to basic cancellation state. - * @details Inputs: stateTimer, rsrvr1Status,rsrvr2Status, isThisInitialDrain - * @details Outputs: stateTimer, rsrvr1Status, rsrvr2Status + * @details Inputs: stateTimerStart, rsrvr1Status,rsrvr2Status, isThisInitialDrain + * @details Outputs: stateTimerStart, rsrvr1Status, rsrvr2Status * @return next state of the flush state machine *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeDrainR1State( void ) @@ -352,8 +352,8 @@ * The handleFlushModeDrainR2State function handles the drain reservoir 2. * If the drain is completed within the defined time, it transitions to the * next state, otherwise, it transitions to basic cancellation state. - * @details Inputs: stateTimer, rsrvr1Status, rsrvr2Status, isThisInitialDrain - * @details Outputs: stateTimer, rsrvr1Status, rsrvr2Status + * @details Inputs: stateTimerStart, rsrvr1Status, rsrvr2Status, isThisInitialDrain + * @details Outputs: stateTimerStart, rsrvr1Status, rsrvr2Status * @return next state of the flush state machine *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeDrainR2State( void ) @@ -403,8 +403,8 @@ * @brief * The handleFlushModeFlushDrainState function handles the flush drain state. * Once the flush drain time has elapsed, it transitions to the next state. - * @details Inputs: stateTimer - * @details Outputs: stateTimer + * @details Inputs: stateTimerStart + * @details Outputs: stateTimerStart * @return next state of the flush state machine *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeFlushDrainState( void ) @@ -433,8 +433,8 @@ * The handleFlushModeFlushDialysateState function handles the flush * dialysate state. Once the flush dialysate time has elapsed, it * transitions to the next state. - * @details Inputs: stateTimer - * @details Outputs: stateTimer + * @details Inputs: stateTimerStart + * @details Outputs: stateTimerStart * @return next state of the flush state machine *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeFlushDialysateState( void ) @@ -457,8 +457,8 @@ * The handleFlushModeFlushDialysateState function handles the flush * dialysate state. Once the flush dialysate time has elapsed, it * transitions to the next state. - * @details Inputs: rsrvr1Status, rsrvr2Status, stateTimer - * @details Outputs: rsrvr1Status, rsrvr2Status, stateTimer + * @details Inputs: rsrvr1Status, rsrvr2Status, stateTimerStart + * @details Outputs: rsrvr1Status, rsrvr2Status, stateTimerStart * @return next state of the flush state machine *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeFlushConcentrateStrawsState( void ) @@ -489,9 +489,9 @@ * it transitions to water cancellation state. If reservoir 2 is filled to * 500 mL before reservoir 1 is filled, it transitions to water cancellation * state. - * @details Inputs: rsrvr1Status, rsrvr2Status, stateTimer - * @details Outputs: rsrvr1Status, rsrvr2Status, stateTimer, prevFlushState, - * alarmDetectedPendingTrigger + * @details Inputs: rsrvr1Status, rsrvr2Status, stateTimerStart + * @details Outputs: rsrvr1Status, rsrvr2Status, stateTimerStart, + * prevFlushState, alarmDetectedPendingTrigger * @return next state of the flush state machine *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeFlushR1ToR2State( void ) @@ -558,9 +558,9 @@ * out the function transitions to basic cancellation state. If reservoir 1 * is filled to 500 mL before reservoir 2 is filled, it transitions to * water cancellation state. - * @details Inputs: rsrvr1Status, rsrvr2Status, stateTimer - * @details Outputs: rsrvr1Status, rsrvr2Status, stateTimer, prevFlushState, - * alarmDetectedPendingTrigger, isThisInitialDrain + * @details Inputs: rsrvr1Status, rsrvr2Status, stateTimerStart + * @details Outputs: rsrvr1Status, rsrvr2Status, stateTimerStart, + * prevFlushState, alarmDetectedPendingTrigger, isThisInitialDrain * @return next state of the flush state machine *************************************************************************/ static DG_FLUSH_STATE_T handleFlushModeFlushR2AndDrainR1State( void ) @@ -814,6 +814,10 @@ if ( DG_RESERVOIR_REACHED_TARGET == rsrvr1Status ) { + // Done with draining + signalDrainPumpHardStop(); + + // Raise the alarm failFlushMode(); } }