Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -ra414ca5b1458b0800e32672eeb7545a9dd575002 -r9e6e86f604c8cce7c1704ae55d1e026de3422782 --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision a414ca5b1458b0800e32672eeb7545a9dd575002) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 9e6e86f604c8cce7c1704ae55d1e026de3422782) @@ -20,6 +20,7 @@ #include "ConcentratePumps.h" #include "DialysatePumps.h" #include "FpgaDD.h" +#include "Heaters.h" #include "ModeStandby.h" #include "Messaging.h" #include "OperationModes.h" @@ -37,10 +38,7 @@ // ********** private definitions ********** -#define BAL_CHAMBER_FILL_VOLUME_ML 30.0F ///< Balancing chamber fill/drain volume per batch operation. #define BAL_CHAMBER_DATA_PUBLISH_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the balancing chamber data published. -#define TEST_ACID_VOLUME_ML 0.67F ///< Acid concentrate volume in ml. -#define TEST_BICARB_VOLUME_ML 1.15F ///< Bicarb concentrate volume in ml. /// Payload record structure for balancing chamber switch only request typedef struct @@ -58,10 +56,14 @@ static U32 currentBalChamberSwitchingCounter; ///< Counter (in task interval) to monitor the timing spent during balancing chamber fill/drain operation. static BOOL isBalChamberFillInProgress; ///< Flag indicating balancing chamber fill/drain is in progress. static BOOL isPressureStalbilizedDuringFill; ///< Flag indicating that the pressure is stablized due to fill complete. +static BOOL isPressureDroppedDuringFill; ///< Flag indicating that the pressure is dropped due to BC fill (state 1 or state 2) in progress condition. static BAL_CHAMBER_SW_STATE_T balChamberSWState; ///< Current balancing chamber switching state ( state 1 or state 2). static U32 balChamberDataPublicationTimerCounter; ///< Used to schedule balancing chamber data publication to CAN bus. static OVERRIDE_U32_T balChamberDataPublishInterval; ///< Balancing chamber data publish interval. static BOOL balanceChamberSwitchingOnly; ///< Balancing chamber switching without any pressure check and dosing delivery. +static OVERRIDE_F32_T acidDoseVolume; ///< Acid concentrate volume in ml ( overrideable). +static OVERRIDE_F32_T bicarbDoseVolume; ///< Bicarb concentrate volume in ml ( overrideable). +static F32 lastTdDialysateFlowrate; ///< Previous TD dialysate flow rate // ********** private function prototypes ********** @@ -92,12 +94,21 @@ balChamberDataPublishInterval.ovData = BAL_CHAMBER_DATA_PUBLISH_INTERVAL; balChamberDataPublishInterval.ovInitData = 0; balChamberDataPublishInterval.override = OVERRIDE_RESET; + acidDoseVolume.data = DEFAULT_ACID_VOLUME_ML; + acidDoseVolume.ovData = DEFAULT_ACID_VOLUME_ML; + acidDoseVolume.ovInitData = 0.0F; + acidDoseVolume.override = OVERRIDE_RESET; + bicarbDoseVolume.data = DEFAULT_BICARB_VOLUME_ML; + bicarbDoseVolume.ovData = DEFAULT_BICARB_VOLUME_ML; + bicarbDoseVolume.ovInitData = 0.0F; + bicarbDoseVolume.override = OVERRIDE_RESET; balanceChamberSwitchingOnly = FALSE; balChamberSwitchingPeriod = 0; balChamberValveClosePeriod = 0; isBalChamberFillInProgress = FALSE; currentBalChamberSwitchingCounter = 0; isPressureStalbilizedDuringFill = FALSE; + lastTdDialysateFlowrate = 0.0F; balChamberDataPublicationTimerCounter = 0; } @@ -125,18 +136,29 @@ *************************************************************************/ void updateBalChamberSwitchingPeriod( void ) { - // update the balancing chamber switching frequency - balChamberSwitchingFreq.data = getTDDialysateFlowrate() / BAL_CHAMBER_FILL_VOLUME_ML; + F32 tdDialysateFlowrate = getTDDialysateFlowrate(); - //update the switching period in task interval for balancing chamber fill timeout check - balChamberSwitchingPeriod = (U32)( (F32)SEC_PER_MIN / getBalChamberSwitchingFreq() * ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); + if ( lastTdDialysateFlowrate != tdDialysateFlowrate ) + { + // update the balancing chamber switching frequency + balChamberSwitchingFreq.data = tdDialysateFlowrate / BAL_CHAMBER_FILL_VOLUME_ML; - // finish the balancing chamber fill 50 ms prior completing the regular cycle time. - balChamberSwitchingPeriod -= 1; + //update the switching period in task interval for balancing chamber fill timeout check + balChamberSwitchingPeriod = (U32)( (F32)SEC_PER_MIN / getBalChamberSwitchingFreq() * ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); - //Testing - balChamberValveClosePeriod = balChamberSwitchingPeriod; - balChamberValveClosePeriod -= 1; // Close valves prior 50 msecond for testing + // finish the balancing chamber fill 50 ms prior completing the regular cycle time. + balChamberSwitchingPeriod -= 1; + + //Update last td dialysate flow rate + lastTdDialysateFlowrate = tdDialysateFlowrate; + + //Update heater control on dialysate flow change + signalHeaterControlOnQDUpdate( D5_HEAT ); + + //Testing + balChamberValveClosePeriod = balChamberSwitchingPeriod; + balChamberValveClosePeriod -= 1; // Close valves prior 50 msecond for testing + } } /*********************************************************************//** @@ -351,6 +373,8 @@ * state 1 fill and time to fill chamber counter being updated. * @details \b Inputs: Pressure * @details \b Outputs: valve states + * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_START_PRESSURE_OUT_OF_RANGE + * when pressure is not in range during balacing chamber fill start. * @return next balancing chamber state. *************************************************************************/ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillStart( void ) @@ -359,11 +383,13 @@ currentBalChamberSwitchingCounter = 0; isBalChamberFillInProgress = FALSE; isPressureStalbilizedDuringFill = FALSE; + isPressureDroppedDuringFill = FALSE; balChamberSWState = BAL_CHAMBER_SW_STATE1; F32 freshDialPressure = getFilteredPressure( D18_PRES ); F32 spentDialPressure = getFilteredPressure( D51_PRES ); - + F32 acidVolume = getF32OverrideValue( &acidDoseVolume ); + F32 bicarbVolume = getF32OverrideValue( &bicarbDoseVolume ); // Check fresh and spent dialysate pressure in range or BC switch only flag set //TODO : comment the pressure check if ( 1 ) @@ -378,11 +404,11 @@ isBalChamberFillInProgress = TRUE; // Deliver dosing during generate dialysate mode - if ( FALSE == getBalChamberSwitchingOnlyStatus() ) + if ( TRUE != getBalChamberSwitchingOnlyStatus() ) { // start acid and bicarb pump with the expected quantity - setConcentratePumpTargetSpeed( D11_PUMP, CONCENTRATE_PUMP_MAX_SPEED, TEST_ACID_VOLUME_ML ); - setConcentratePumpTargetSpeed( D10_PUMP, CONCENTRATE_PUMP_MAX_SPEED, TEST_BICARB_VOLUME_ML ); + setConcentratePumpTargetSpeed( D11_PUMP, CONCENTRATE_PUMP_MAX_SPEED, acidVolume ); + setConcentratePumpTargetSpeed( D10_PUMP, CONCENTRATE_PUMP_MAX_SPEED, bicarbVolume ); requestConcentratePumpOn( D11_PUMP ); requestConcentratePumpOn( D10_PUMP ); } @@ -391,8 +417,10 @@ } else { +#ifdef ENABLE_ALARM_2 //Alarm when pressure is not in range SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_START_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); +#endif } return state; @@ -403,16 +431,28 @@ * The handleBalChamberConcentrateControl function handles the Acid and Bicarb * concentrate doisng and checks the conductivity of the dialysate for the treatment. * @details \b Inputs: balChamberSWState , Concentrate volume - * @details \b Outputs: state + * @details \b Outputs: isPressureDroppedDuringFill, state * @return next balancing chamber state. *************************************************************************/ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberConcentrateControl( void ) { BAL_CHAMBER_EXEC_STATE_T state; - // On dosing completion, transition to next state based on the current switching state - if ( TRUE == IsConcentratePumpDosingCompleted() ) + F32 freshDialPressure = getFilteredPressure( D18_PRES ); + F32 spentDialPressure = getFilteredPressure( D51_PRES ); + + // Pressure drop check during fill process helps to find if there is any issue with valves opening + if ( ( freshDialPressure <= BC_FILL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= BC_FILL_PRESSURE_MIN_PSIG ) ) { + isPressureDroppedDuringFill = TRUE; + } + + // On dosing completion, transition to next state based on the current switching state + // TODO : Need an updated FPGA to perform this check. For now commenting this check. +// if ( ( ( TRUE == isConcentratePumpDosingCompleted( D11_PUMP ) ) && +// ( TRUE == isConcentratePumpDosingCompleted( D10_PUMP ) ) ) || +// ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) +// { if ( BAL_CHAMBER_SW_STATE1 == balChamberSWState ) { state = BAL_CHAMBER_STATE1_FILL_END; @@ -421,7 +461,7 @@ { state = BAL_CHAMBER_STATE2_FILL_END; } - } +// } return state; } @@ -432,6 +472,10 @@ * fill complete and close the currently opened valves. * @details \b Inputs: balChamberSWState, spent and fresh dialysate pressure * @details \b Outputs: isPressureStalbilizedDuringFill,isBalChamberFillInProgress + * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_PRESSURE_DROP_OUT_OF_RANGE + * when pressure drop is not in range during balacing chamber fill in progress. + * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_END_PRESSURE_OUT_OF_RANGE + * when pressure is not in range during balacing chamber fill complete. * @return next balancing chamber state. *************************************************************************/ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillEnd( void ) @@ -450,6 +494,7 @@ { // stabilized pressure indicating fill is complete isPressureStalbilizedDuringFill = TRUE; + isBalChamberFillInProgress = FALSE; // isPressureStalbilizedDuringFill = FALSE; } @@ -464,19 +509,33 @@ // On completion of cycle time, transition to next state if ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) { - if ( ( TRUE != isPressureStalbilizedDuringFill ) && - ( FALSE == getBalChamberSwitchingOnlyStatus() ) ) + if ( TRUE != getBalChamberSwitchingOnlyStatus() ) { - // Alarm when switching time expired, but still pressure not in range, - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + if ( TRUE != isPressureDroppedDuringFill ) + { +#ifdef ENABLE_ALARM_2 + // When fill initiated, pressure is not dropped to the expected range, possible valve failures. + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_PRESSURE_DROP_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); +#endif + } + else if ( TRUE != isPressureStalbilizedDuringFill ) + { +#ifdef ENABLE_ALARM_2 + // Alarm when switching time expired, but still pressure not in range which indicates fill is not yet completed. + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); +#endif + } + else + { + // Move to next state when pressure is in range. + state = BAL_CHAMBER_STATE2_FILL_START; + } //TODO : Temporarily allow to proceed next state even though pressure is not stabilized. - isBalChamberFillInProgress = FALSE; state = BAL_CHAMBER_STATE2_FILL_START; } else { - isBalChamberFillInProgress = FALSE; state = BAL_CHAMBER_STATE2_FILL_START; } } @@ -490,6 +549,8 @@ * state 2 fill and time to fill chamber counter being updated. * @details \b Inputs: fresh and spent dialysate pressure * @details \b Outputs: valve states + * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_START_PRESSURE_OUT_OF_RANGE + * when pressure is not in range during balacing chamber state 2 fill start. * @return next balancing chamber state. *************************************************************************/ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillStart( void ) @@ -498,10 +559,13 @@ currentBalChamberSwitchingCounter = 0; isBalChamberFillInProgress = FALSE; isPressureStalbilizedDuringFill = FALSE; + isPressureDroppedDuringFill = FALSE; balChamberSWState = BAL_CHAMBER_SW_STATE2; F32 freshDialPressure = getFilteredPressure( D18_PRES ); F32 spentDialPressure = getFilteredPressure( D51_PRES ); + F32 acidVolume = getF32OverrideValue( &acidDoseVolume ); + F32 bicarbVolume = getF32OverrideValue( &bicarbDoseVolume ); // Check fresh and spent dialysate pressure in range //TODO : comment the pressure check @@ -517,11 +581,11 @@ isBalChamberFillInProgress = TRUE; // Deliver dosing during generate dialysate mode - if ( FALSE == getBalChamberSwitchingOnlyStatus() ) + if ( TRUE != getBalChamberSwitchingOnlyStatus() ) { // start acid and bicarb pump with the expected quantity - setConcentratePumpTargetSpeed( D11_PUMP, CONCENTRATE_PUMP_MAX_SPEED, TEST_ACID_VOLUME_ML ); - setConcentratePumpTargetSpeed( D10_PUMP, CONCENTRATE_PUMP_MAX_SPEED, TEST_BICARB_VOLUME_ML ); + setConcentratePumpTargetSpeed( D11_PUMP, CONCENTRATE_PUMP_MAX_SPEED, acidVolume ); + setConcentratePumpTargetSpeed( D10_PUMP, CONCENTRATE_PUMP_MAX_SPEED, bicarbVolume ); requestConcentratePumpOn( D11_PUMP ); requestConcentratePumpOn( D10_PUMP ); } @@ -530,8 +594,10 @@ } else { +#ifdef ENABLE_ALARM_2 //Alarm when pressure is not in range SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_START_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); +#endif } return state; } @@ -542,6 +608,10 @@ * fill complete and close the currently opened valves. * @details \b Inputs: balChamberSWState, spent and fresh dialysate pressure * @details \b Outputs: isPressureStalbilizedDuringFill,isBalChamberFillInProgress + * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_PRESSURE_DROP_OUT_OF_RANGE + * when pressure is not in range during balacing chamber state 2 fill in progress. + * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_END_PRESSURE_OUT_OF_RANGE + * when pressure is not in range during balacing chamber state 2 fill complete. * @return next balancing chamber state. *************************************************************************/ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillEnd( void ) @@ -560,6 +630,7 @@ { // stabilized pressure indicating fill is complete isPressureStalbilizedDuringFill = TRUE; + isBalChamberFillInProgress = FALSE; //isPressureStalbilizedDuringFill = FALSE; } @@ -574,19 +645,34 @@ // On completion of cycle time, transition to next state if ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) { - if ( ( TRUE != isPressureStalbilizedDuringFill ) && - ( FALSE == getBalChamberSwitchingOnlyStatus() ) ) + // Pressure alarm check + if ( TRUE != getBalChamberSwitchingOnlyStatus() ) { - // Alarm when switching time expired, but still pressure not in range, - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + if ( TRUE != isPressureDroppedDuringFill ) + { +#ifdef ENABLE_ALARM_2 + // When fill initiated, pressure is not dropped to the expected range, possible valve failures. + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_PRESSURE_DROP_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); +#endif + } + else if ( TRUE != isPressureStalbilizedDuringFill ) + { +#ifdef ENABLE_ALARM_2 + // Alarm when switching time expired, but still pressure not in range which indicates fill is not completed. + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); +#endif + } + else + { + // Move to next state when pressure is in range. + state = BAL_CHAMBER_STATE1_FILL_START; + } //TODO : Temporarily allow to proceed next state even though pressure is not stabilized. - isBalChamberFillInProgress = FALSE; state = BAL_CHAMBER_STATE1_FILL_START; } else { - isBalChamberFillInProgress = FALSE; state = BAL_CHAMBER_STATE1_FILL_START; } } @@ -760,6 +846,40 @@ /*********************************************************************//** * @brief + * The testAcidDoseVolumeOverride function sets the override value + * of the acid concentrate dosing volume. + * @details Inputs: acidDoseVolume + * @details Outputs: acidDoseVolume + * @param message Override message from Dialin which includes the override + * value to override the acid concentrate dosing volume. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testAcidDoseVolumeOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &acidDoseVolume ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testBicarbDoseVolumeOverride function sets the override value + * of the bicarb concentrate dosing volume. + * @details Inputs: bicarbDoseVolume + * @details Outputs: bicarbDoseVolume + * @param message Override message from Dialin which includes the override + * value to override the bicarb concentrate dosing volume. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testBicarbDoseVolumeOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &bicarbDoseVolume ); + + return result; +} + +/*********************************************************************//** + * @brief * The testBCSwitchOnlyStartStopOverride function starts/stops balancing * chamber switching only without dosing delivery and pressure check condition. * @details \b Inputs: tester logged in