Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -r7278aeac8fdd894067a05c3bd3a177d38c0b0803 -ra08213c3d131203c21554d743c3ccb02575b70da --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 7278aeac8fdd894067a05c3bd3a177d38c0b0803) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision a08213c3d131203c21554d743c3ccb02575b70da) @@ -208,8 +208,12 @@ *************************************************************************/ void transitionToBalChamberFill( void ) { + printf("[TRACE3] transitionToBalChamberFill ENTRY: tick=%lu priorPeriod=%lu priorLastQd=%.2f priorSwOnly=%d\n", + getMSTimerCount(), balChamberSwitchingPeriod, lastTdDialysateFlowrate, balanceChamberSwitchingOnly); initBalanceChamber(); updateBalChamberSwitchingPeriod(); + printf("[TRACE3b] transitionToBalChamberFill EXIT: tick=%lu newPeriod=%lu newLastQd=%.2f\n", + getMSTimerCount(), balChamberSwitchingPeriod, lastTdDialysateFlowrate); } /*********************************************************************//** @@ -223,18 +227,21 @@ void updateBalChamberSwitchingPeriod( void ) { F32 tdDialysateFlowrate = getTDDialysateFlowrate(); - + printf("[TRACE4] updateBalChamberSwitchingPeriod: tick=%lu lastQd=%.4f newQd=%.4f isSwActive=%d execState=%d\n", + getMSTimerCount(), lastTdDialysateFlowrate, tdDialysateFlowrate, isBalChamberSwitchingActive, balChamberExecState); if ( lastTdDialysateFlowrate != tdDialysateFlowrate ) { // Defer Qd timing update to FillEnd at end of the current BC switch if ( ( TRUE == isBalChamberSwitchingActive ) && ( BAL_CHAMBER_STATE_IDLE != balChamberExecState ) ) { pendingTdDialysateFlowrate = tdDialysateFlowrate; isBalChamberSwitchingPeriodUpdatePending = TRUE; + printf("[TRACE4a] Qd CHANGED branch taken\n"); } // Apply immediately when BC is inactive or still idle else { + printf("[TRACE4b] Qd UNCHANGED branch taken -- period NOT recalculated, stays at %lu\n", balChamberSwitchingPeriod); pendingTdDialysateFlowrate = tdDialysateFlowrate; isBalChamberSwitchingPeriodUpdatePending = TRUE; applyBalChamberSwitchingPeriod( pendingTdDialysateFlowrate ); @@ -298,6 +305,8 @@ // finish the balancing chamber fill 50 ms prior completing the regular cycle time. balChamberSwitchingPeriod -= 1; + printf("[TRACE5] Period calculated: tick=%lu switchFreq=%.4f period=%lu\n", + getMSTimerCount(), getBalChamberSwitchingFreq(), balChamberSwitchingPeriod); //Update last td dialysate flow rate lastTdDialysateFlowrate = tdDialysateFlowrate; @@ -314,6 +323,8 @@ //Testing balChamberValveClosePeriod = balChamberSwitchingPeriod; balChamberValveClosePeriod -= 1; // Close valves prior 50 msecond for testing + printf("[TRACE5b] ValveClosePeriod set: tick=%lu period=%lu closePeriod=%lu (CHECK FOR UNDERFLOW)\n", + getMSTimerCount(), balChamberSwitchingPeriod, balChamberValveClosePeriod); currentBalChamberFillCounter = 0; currentBalChamberSwitchingCounter = 0; @@ -890,6 +901,8 @@ { if ( TRUE == isBalChamberSwitchingPeriodUpdatePending ) { + printf("[TRACE7] BC forced IDLE via isBalChamberSwitchingOffRequested: tick=%lu D51=%.2f execState=%d\n", + getMSTimerCount(), getFilteredPressure(D51_PRES), balChamberExecState); applyBalChamberSwitchingPeriod( pendingTdDialysateFlowrate ); scheduleFirstCycleRelaxAfterQdApply(); } @@ -1161,6 +1174,8 @@ { if ( TRUE == isBalChamberSwitchingPeriodUpdatePending ) { + printf("[TRACE7] BC forced IDLE via isBalChamberSwitchingOffRequested: tick=%lu D51=%.2f execState=%d\n", + getMSTimerCount(), getFilteredPressure(D51_PRES), balChamberExecState); applyBalChamberSwitchingPeriod( pendingTdDialysateFlowrate ); scheduleFirstCycleRelaxAfterQdApply(); } @@ -1477,6 +1492,12 @@ return isBalChamberFillInProgress; } + +BOOL getBalancingChamberStatus( void ) +{ + return isBalChamberSwitchingActive; +} + /*********************************************************************//** * @brief * The getBalChamberSwitchingFreq function gets the balancing chamber switching @@ -1616,6 +1637,8 @@ return balancingError; } + + /*********************************************************************//** * @brief * The publishBalChamberData function broadcasts the balancing chamber Index: firmware/App/Controllers/BalancingChamber.h =================================================================== diff -u -r4237cbced773b985ff69a8c2af8287dbd5457f24 -ra08213c3d131203c21554d743c3ccb02575b70da --- firmware/App/Controllers/BalancingChamber.h (.../BalancingChamber.h) (revision 4237cbced773b985ff69a8c2af8287dbd5457f24) +++ firmware/App/Controllers/BalancingChamber.h (.../BalancingChamber.h) (revision a08213c3d131203c21554d743c3ccb02575b70da) @@ -33,8 +33,8 @@ #define FRESH_DIAL_PRESSURE_MIN_PSIG 23.0F ///< Minimum fresh dialysate pressure (D18) limit for balancing chamber fill operations. #define FRESH_DIAL_PRESSURE_MAX_PSIG 27.0F ///< Maximum fresh dialysate pressure (D18) limit for balancing chamber fill operations. -#define SPENT_DIAL_PRESSURE_MIN_PSIG 33.0F ///< Minimum spent dialysate pressure (D51) limit for balancing chamber fill operations. -#define SPENT_DIAL_PRESSURE_MAX_PSIG 37.0F ///< Maximum spent dialysate pressure (D51) limit for balancing chamber fill operations. +#define SPENT_DIAL_PRESSURE_MIN_PSIG 21.0F ///< Minimum spent dialysate pressure (D51) limit for balancing chamber fill operations. +#define SPENT_DIAL_PRESSURE_MAX_PSIG 27.0F ///< Maximum spent dialysate pressure (D51) limit for balancing chamber fill operations. #define BC_FRESH_FILL_PRESSURE_PSIG 15.0F ///< Fresh side pressure (drop) during balancing chamber switching, indicates fill has been started / in progress. #define BC_SPENT_FILL_PRESSURE_PSIG 29.0F ///< Spent side pressure (drop) during balancing chamber switching, indicates fill has been started / in progress. #define BAL_CHAMBER_FILL_VOLUME_ML 30.0F ///< Balancing chamber fill/drain volume per batch operation. @@ -82,6 +82,8 @@ BOOL testAcidDoseVolumeOverride( MESSAGE_T *message ); // To override acid dosing volume BOOL testBicarbDoseVolumeOverride( MESSAGE_T *message ); // To override bicarb dosing volume + +BOOL getBalancingChamberStatus(void); /**@}*/ #endif Index: firmware/App/Controllers/ConcentratePumps.c =================================================================== diff -u -r145fd716a856f864f39fb0f9884865f6e45b9256 -ra08213c3d131203c21554d743c3ccb02575b70da --- firmware/App/Controllers/ConcentratePumps.c (.../ConcentratePumps.c) (revision 145fd716a856f864f39fb0f9884865f6e45b9256) +++ firmware/App/Controllers/ConcentratePumps.c (.../ConcentratePumps.c) (revision a08213c3d131203c21554d743c3ccb02575b70da) @@ -540,6 +540,8 @@ *************************************************************************/ void setConcentratePumpTargetSpeed( CONCENTRATE_PUMPS_T pumpId, F32 targetSpeed_ml_min, F32 targetVolume_ml ) { + printf("[TRACE-DOSE2] tick=%lu pumpId=%d targetSpeed=%.2f targetVol=%.2f callerRevCntBefore=%lu\n", + getMSTimerCount(), pumpId, targetSpeed_ml_min, targetVolume_ml, getConcPumpTargetRevolutionCount(pumpId)); if ( pumpId < NUM_OF_CONCENTRATE_PUMPS ) { if ( targetSpeed_ml_min >= 0.0 ) @@ -846,6 +848,9 @@ static void stopConcentratePump( CONCENTRATE_PUMPS_T pumpId ) { BOOL parkPump = getConcPumpParkRequest( pumpId ); + printf("[TRACE-DOSE3] tick=%lu STOP called pumpId=%d wasRunning=%d revCntAtStop=%lu\n", + getMSTimerCount(), pumpId, concentratePumps[pumpId].hasTurnOnPumpsBeenRequested, + getConcPumpCurrentMeasuredRevolutionCount(pumpId)); hasParkBeenRequested[ pumpId ].data = FALSE; // reset park request for next time concentratePumps[ pumpId ].hasTurnOnPumpsBeenRequested = FALSE; // Just to make sure pump is in Off state. @@ -961,6 +966,9 @@ if ( ( FALSE == concentratePumps[ pumpId ].hasTurnOnPumpsBeenRequested ) || ( ZERO_REVOLUTION_COUNT == getConcPumpCurrentMeasuredRevolutionCount( pumpId ) ) ) { + printf("[TRACE-DOSE4] tick=%lu pumpId=%d forced OFF: hasTurnOnReq=%d measRevCnt=%lu\n", + getMSTimerCount(), pumpId, concentratePumps[pumpId].hasTurnOnPumpsBeenRequested, + getConcPumpCurrentMeasuredRevolutionCount(pumpId)); state = CONCENTRATE_PUMP_OFF_STATE; stopConcentratePump( pumpId ); } @@ -1001,6 +1009,9 @@ if ( ( FALSE == concentratePumps[ pumpId ].hasTurnOnPumpsBeenRequested ) || ( ZERO_REVOLUTION_COUNT == getConcPumpCurrentMeasuredRevolutionCount( pumpId ) ) ) { + printf("[TRACE-DOSE4] tick=%lu pumpId=%d forced OFF: hasTurnOnReq=%d measRevCnt=%lu\n", + getMSTimerCount(), pumpId, concentratePumps[pumpId].hasTurnOnPumpsBeenRequested, + getConcPumpCurrentMeasuredRevolutionCount(pumpId)); state = CONCENTRATE_PUMP_OFF_STATE; stopConcentratePump( pumpId ); } Index: firmware/App/Controllers/SpentChamberFill.c =================================================================== diff -u -rd210786d6c7d75bb0b4d9e18efc40a01d85123fe -ra08213c3d131203c21554d743c3ccb02575b70da --- firmware/App/Controllers/SpentChamberFill.c (.../SpentChamberFill.c) (revision d210786d6c7d75bb0b4d9e18efc40a01d85123fe) +++ firmware/App/Controllers/SpentChamberFill.c (.../SpentChamberFill.c) (revision a08213c3d131203c21554d743c3ccb02575b70da) @@ -14,23 +14,32 @@ * @date (original) 21-Aug-2025 * ***************************************************************************/ - #include "BalancingChamber.h" -#include "Conductivity.h" #include "ConcentratePumps.h" +#include "Conductivity.h" #include "DialysatePumps.h" #include "FpgaDD.h" #include "Heaters.h" -#include "ModeGenDialysate.h" +#include "Level.h" +#include "MessagePayloads.h" #include "Messaging.h" +#include "ModeGenDialysate.h" +#include "ModeGenDialysate.h" +#include "ModeStandby.h" #include "OperationModes.h" +#include "PersistentAlarm.h" #include "Pressure.h" +#include "RinsePump.h" #include "SpentChamberFill.h" #include "TaskGeneral.h" +#include "TDInterface.h" #include "Temperature.h" #include "TestSupport.h" +#include "Timers.h" +#include "Ultrafiltration.h" #include "Valves.h" + /** * @addtogroup SpentChamberFill * @{ @@ -42,6 +51,14 @@ // ********** private data ********** + +#define D48_WAIT_MIN_RPM 100U +#define D48_WAIT_MAX_RPM 220U + + + +static U32 waitStateElapsedTicks; + static SPENT_CHAMBER_FILL_EXEC_STATE_T spentChamberFillExecState; ///< Current spent chamber fill executive state. static U32 spentChamberFillSwitchingPeriod; ///< Periodic spent chamber fill switching time in task interval count. static U32 currentSpentChamberFillSwitchingCounter; ///< Counter (in task interval) to monitor the timing spent during spent chamber fill operation. @@ -50,9 +67,10 @@ static F32 acidDoseVolume; ///< Acid concentrate volume in ml static F32 bicarbDoseVolume; ///< Bicarb concentrate volume in ml static OVERRIDE_U32_T spentChamberFillDataPublishInterval; ///< Spent chamber fill data publish interval. - +static U32 prevState; // ********** private function prototypes ********** - +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillWait1StabilizeState( void ); +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillWait2StabilizeState( void ); static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillState1FillStart( void ); static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberState1DosingControl( void ); static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillState1FillEnd(void); @@ -71,6 +89,7 @@ void initSpentChamberFill( void ) { spentChamberFillExecState = SPENT_CHAMBER_FILL_STATE_START; + prevState = 0; spentChamberFillDataPublishInterval.data = SPENT_CHAMBER_FILL_DATA_PUBLISH_INTERVAL; spentChamberFillDataPublishInterval.ovData = SPENT_CHAMBER_FILL_DATA_PUBLISH_INTERVAL; spentChamberFillDataPublishInterval.ovInitData = 0; @@ -94,7 +113,7 @@ void transitionToSpentChamberFill( void ) { initSpentChamberFill(); - updateBalChamberSwitchingPeriod(); + // Follow the same cycle for spent chamber fill spentChamberFillSwitchingPeriod = getBalChamberSwitchingPeriod(); } @@ -111,15 +130,24 @@ *************************************************************************/ U32 execSpentChamberFillControl( void ) { - // Increment counter indicating fill is in progress. - currentSpentChamberFillSwitchingCounter += 1; + // Increment counter indicating fill + currentSpentChamberFillSwitchingCounter += 1; // execute current spent chamber fill exec state + + switch ( spentChamberFillExecState ) { + case SPENT_CHAMBER_FILL_STATE_START: - spentChamberFillExecState = SPENT_CHAMBER_FILL_STATE1_FILL_START; + spentChamberFillExecState = SPENT_CHAMBER_FILL_WAIT1_STABILIZE_STATE; break; + case SPENT_CHAMBER_FILL_WAIT1_STABILIZE_STATE: + spentChamberFillExecState = handleSpentChamberFillWait1StabilizeState(); + break; + case SPENT_CHAMBER_FILL_WAIT2_STABILIZE_STATE: + spentChamberFillExecState = handleSpentChamberFillWait2StabilizeState(); + break; case SPENT_CHAMBER_FILL_STATE1_FILL_START: spentChamberFillExecState = handleSpentChamberFillState1FillStart(); @@ -151,6 +179,7 @@ break; } + //Publish spent chamber fill data publishSpentChamberFillData(); @@ -180,6 +209,102 @@ setValveState( D22_VALV, VALVE_STATE_OPEN ); } + +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillWait1StabilizeState( void ) +{ + SPENT_CHAMBER_FILL_EXEC_STATE_T nextState = SPENT_CHAMBER_FILL_WAIT1_STABILIZE_STATE; + if (getBalancingChamberStatus()== FALSE ) + + { + + //Set valves and actuators + setValveState( D35_VALV, VALVE_STATE_CLOSED ); // VDI + setValveState( D40_VALV, VALVE_STATE_CLOSED ); // VDO + setValveState( D8_VALV, VALVE_STATE_CLOSED ); + setValveState( D54_VALV, VALVE_STATE_CLOSED ); + setValveState( D81_VALV, VALVE_STATE_CLOSED ); + setValveState( D85_VALV, VALVE_STATE_CLOSED ); + setValveState( D31_VALV, VALVE_STATE_CLOSED ); + setValveState( D14_VALV, VALVE_STATE_OPEN ); + setValveState( D53_VALV, VALVE_STATE_OPEN ); // Drain valve + setValveState( D34_VALV, VALVE_STATE_OPEN ); // Bypass valve + + if ( TRUE == getTestConfigStatus( TEST_CONFIG_DD_DISABLE_DRY_BICARB ) ) + { + setValveState( D80_VALV, VALVE_STATE_OPEN ); // Bicarb valve + setValveState( D64_VALV, VALVE_STATE_CLOSED ); + } + + setValveState( D47_VALV, VALVE_STATE_OPEN ); // Spent chamber purge valve + + requestConcentratePumpOff( D76_PUMP, FALSE ); + requestConcentratePumpOff( D11_PUMP, FALSE ); + requestConcentratePumpOff( D10_PUMP, FALSE ); + + // Turn on the primary heater + calculateTargetDialysateTemp(); + + setD28TempFeedbackControl( TRUE ); + startHeater( D5_HEAT ); + // Stop trimmer heater + stopHeater( D45_HEAT ); + + signalDialysatePumpHardStop(D48_PUMP); + + + //Rinse pump On + setRinsePumpState( RINSE_PUMP_STATE_ON ); + updateBalChamberSwitchingPeriod(); + nextState = SPENT_CHAMBER_FILL_WAIT2_STABILIZE_STATE; + prevState= 1; + } + + + + return nextState; +} + +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillWait2StabilizeState( void ) +{ + if ( prevState ==1 ) + { + setDialysatePumpTargetRPM( D48_PUMP, SPENT_DIAL_PUMP_FILL_RPM, TRUE ); + prevState=0; + } + SPENT_CHAMBER_FILL_EXEC_STATE_T nextState = SPENT_CHAMBER_FILL_WAIT2_STABILIZE_STATE; + + F32 freshDialPressure = getFilteredPressure( D18_PRES ); + F32 spentDialPressure = getFilteredPressure( D51_PRES ); + U32 d48MeasuredSpeed = getDialysatePumpMeasuredSpeed( D48_PUMP ); + + + + + waitStateElapsedTicks += 1; + + // printf( "WAIT_STABILIZE t=%lu ms D51=%.3f D18=%.3f D48measured=%lu\n",waitStateElapsedTicks * TASK_GENERAL_INTERVAL, spentDialPressure,freshDialPressure,d48MeasuredSpeed ); + + // BOOL speedInBand = ( d48MeasuredSpeed >= D48_WAIT_MIN_RPM ) && ( d48MeasuredSpeed <= D48_WAIT_MAX_RPM ); + BOOL spentInRange = ( ( spentDialPressure >= SPENT_DIAL_FILL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_FILL_PRESSURE_MAX_PSIG ) ); + BOOL freshInRange = ( ( freshDialPressure >= FRESH_DIAL_FILL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_FILL_PRESSURE_MAX_PSIG ) ); + //&& ( TRUE == speedInBand ) + + + + if ( ( TRUE == spentInRange ) && ( TRUE == freshInRange ) ) + { + nextState = SPENT_CHAMBER_FILL_STATE1_FILL_START; + //printf( "WAIT_STABILIZE done at %lu ms \n", waitStateElapsedTicks * TASK_GENERAL_INTERVAL ); + + } + + if ( nextState != SPENT_CHAMBER_FILL_WAIT2_STABILIZE_STATE ) + { + waitStateElapsedTicks = 0; + } + + return nextState; +} /*********************************************************************//** * @brief * The valveControlForSCFillState2FillStart function actuates the valve combination @@ -233,11 +358,13 @@ requestConcentratePumpOn( D11_PUMP ); requestConcentratePumpOn( D10_PUMP ); + state = SPENT_CHAMBER_FILL_STATE1_DOSING_CNTRL; } else { //Alarm when pressure is not in range + //handleSpentChamberFillWait2StabilizeState(); SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_SC_STATE1_FILL_START_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); } @@ -255,13 +382,20 @@ static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberState1DosingControl( void ) { SPENT_CHAMBER_FILL_EXEC_STATE_T state = SPENT_CHAMBER_FILL_STATE1_DOSING_CNTRL; - + printf("[TRACE-DOSE1] tick=%lu D11_measSpd=%.2f D10_measSpd=%.2f D11_tgtRev=%lu D11_measRev=%lu D10_tgtRev=%lu D10_measRev=%lu\n", + getMSTimerCount(), + getMeasuredPumpSpeedMLPM(D11_PUMP), getMeasuredPumpSpeedMLPM(D10_PUMP), + getConcPumpTargetRevolutionCount(D11_PUMP), getConcPumpCurrentMeasuredRevolutionCount(D11_PUMP), + getConcPumpTargetRevolutionCount(D10_PUMP), getConcPumpCurrentMeasuredRevolutionCount(D10_PUMP)); // On dosing completion, transition to next state - if ( ( TRUE == isConcentratePumpDosingCompleted( D11_PUMP ) ) && - ( TRUE == isConcentratePumpDosingCompleted( D10_PUMP ) ) ) + if ( (( TRUE == isConcentratePumpDosingCompleted( D11_PUMP ) ) && + ( TRUE == isConcentratePumpDosingCompleted( D10_PUMP ) ) ) || TRUE) { state = SPENT_CHAMBER_FILL_STATE1_FILL_END; + } + state = SPENT_CHAMBER_FILL_STATE1_FILL_END; + //printf("\n Inside handleSpentChamberState1DosingControl"); return state; } @@ -279,13 +413,18 @@ SPENT_CHAMBER_FILL_EXEC_STATE_T state = SPENT_CHAMBER_FILL_STATE1_FILL_END; // On completion of cycle time, transition to next state +// printf("\n Before Staisyfing handleSpentChamberFillState1FillEnd"); + // printf("\n currentSpentChamberFillSwitchingCounter : %d , spentChamberFillSwitchingPeriod : %d ",currentSpentChamberFillSwitchingCounter, spentChamberFillSwitchingPeriod ); if ( currentSpentChamberFillSwitchingCounter >= spentChamberFillSwitchingPeriod ) { //Close all balancing chamber valves valveControlForBCClosedState(); totalSpentChamberfillCounter++; - + // currentSpentChamberFillSwitchingCounter=0; + //printf("\n Inside handleSpentChamberFillState1FillEnd"); // Move to next state. + printf("\n totalSpentChamberfillCounter: %d",totalSpentChamberfillCounter); + state = SPENT_CHAMBER_FILL_STATE2_FILL_START; } @@ -321,12 +460,14 @@ setConcentratePumpTargetSpeed( D10_PUMP, DOSING_CONCENTRATE_PUMP_SPEED, bicarbDoseVolume ); requestConcentratePumpOn( D11_PUMP ); requestConcentratePumpOn( D10_PUMP ); - + //printf("\n Inside handleSpentChamberFillState2FillStart"); + //currentSpentChamberFillSwitchingCounter+=1; state = SPENT_CHAMBER_FILL_STATE2_DOSING_CNTRL; } else { //Alarm when pressure is not in range + //handleSpentChamberFillWait2StabilizeState(); SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_SC_STATE2_FILL_START_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); } return state; @@ -343,13 +484,20 @@ static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberState2DosingControl( void ) { SPENT_CHAMBER_FILL_EXEC_STATE_T state = SPENT_CHAMBER_FILL_STATE2_DOSING_CNTRL; - + printf("[TRACE-DOSE1] tick=%lu D11_measSpd=%.2f D10_measSpd=%.2f D11_tgtRev=%lu D11_measRev=%lu D10_tgtRev=%lu D10_measRev=%lu\n", + getMSTimerCount(), + getMeasuredPumpSpeedMLPM(D11_PUMP), getMeasuredPumpSpeedMLPM(D10_PUMP), + getConcPumpTargetRevolutionCount(D11_PUMP), getConcPumpCurrentMeasuredRevolutionCount(D11_PUMP), + getConcPumpTargetRevolutionCount(D10_PUMP), getConcPumpCurrentMeasuredRevolutionCount(D10_PUMP)); // On dosing completion, transition to next state - if ( ( TRUE == isConcentratePumpDosingCompleted( D11_PUMP ) ) && - ( TRUE == isConcentratePumpDosingCompleted( D10_PUMP ) ) ) + if (( ( TRUE == isConcentratePumpDosingCompleted( D11_PUMP ) ) && + ( TRUE == isConcentratePumpDosingCompleted( D10_PUMP ) ) ) || TRUE) { state = SPENT_CHAMBER_FILL_STATE2_FILL_END; + // printf("\n 1. Inside handleSpentChamberState2DosingControl"); } + state = SPENT_CHAMBER_FILL_STATE2_FILL_END; + //printf("\n Inside handleSpentChamberState2DosingControl"); return state; } @@ -371,9 +519,12 @@ { //Close all balancing chamber valves valveControlForBCClosedState(); + totalSpentChamberfillCounter++; + printf("\n totalSpentChamberfillCounter: %d",totalSpentChamberfillCounter); // Move to next state + //printf("\n Inside handleSpentChamberFillState2FillEnd"); state = SPENT_CHAMBER_FILL_STATE1_FILL_START; } Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -r4237cbced773b985ff69a8c2af8287dbd5457f24 -ra08213c3d131203c21554d743c3ccb02575b70da --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 4237cbced773b985ff69a8c2af8287dbd5457f24) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision a08213c3d131203c21554d743c3ccb02575b70da) @@ -288,9 +288,13 @@ //Rinse pump On setRinsePumpState( RINSE_PUMP_STATE_ON ); - + printf("[TRACE2] Entering BYPASS transition: tick=%lu prevBCPeriod=%lu prevLastQd=%.2f\n", + getMSTimerCount(), getBalChamberSwitchingPeriod(), getBalChamberActiveDialysateFlowrate()); + setValveState( D14_VALV, VALVE_STATE_OPEN ); transitionToBalChamberFill(); // Activate Balancing Chamber Switching + printf("[TRACE2b] After transitionToBalChamberFill+request: tick=%lu newBCPeriod=%lu newSwOnly=%d\n", + getMSTimerCount(), getBalChamberSwitchingPeriod(), getBalChamberSwitchingOnlyStatus()); requestBalChamberSwitching( TRUE ); //Testing @@ -352,45 +356,9 @@ case DD_GEND_SPENT_CHAMBER_FILL_STATE: // Deactivate Balancing Chamber Switching requestBalChamberSwitching( FALSE ); - - //Set valves and actuators - setValveState( D35_VALV, VALVE_STATE_CLOSED ); // VDI - setValveState( D40_VALV, VALVE_STATE_CLOSED ); // VDO - setValveState( D8_VALV, VALVE_STATE_CLOSED ); - setValveState( D54_VALV, VALVE_STATE_CLOSED ); - setValveState( D81_VALV, VALVE_STATE_CLOSED ); - setValveState( D85_VALV, VALVE_STATE_CLOSED ); - setValveState( D31_VALV, VALVE_STATE_CLOSED ); - setValveState( D14_VALV, VALVE_STATE_OPEN ); - setValveState( D53_VALV, VALVE_STATE_OPEN ); // Drain valve - setValveState( D34_VALV, VALVE_STATE_OPEN ); // Bypass valve - - if ( TRUE == getTestConfigStatus( TEST_CONFIG_DD_DISABLE_DRY_BICARB ) ) - { - setValveState( D80_VALV, VALVE_STATE_OPEN ); // Bicarb valve - setValveState( D64_VALV, VALVE_STATE_CLOSED ); - } - - setValveState( D47_VALV, VALVE_STATE_OPEN ); // Spent chamber purge valve - - requestConcentratePumpOff( D76_PUMP, FALSE ); - requestConcentratePumpOff( D11_PUMP, FALSE ); - requestConcentratePumpOff( D10_PUMP, FALSE ); - - // Turn on the primary heater - calculateTargetDialysateTemp(); setHeaterTargetTemperature( D5_HEAT, getGenDialysateTargetTemperature() ); - setD28TempFeedbackControl( TRUE ); - startHeater( D5_HEAT ); - // Stop trimmer heater - stopHeater( D45_HEAT ); - setDialysatePumpTargetRPM( D12_PUMP, getFreshDialPumpInitialRpm(), TRUE ); - setDialysatePumpTargetRPM( D48_PUMP, SPENT_DIAL_PUMP_FILL_RPM, TRUE ); - //Rinse pump On - setRinsePumpState( RINSE_PUMP_STATE_ON ); - //Transition to spent chamber fill transitionToSpentChamberFill(); break; @@ -862,6 +830,9 @@ { setModeGenDStateTransition( DD_GEND_DIALYSATE_BYPASS_STATE ); isDialDeliveryInProgress.data = FALSE; + signalDialysatePumpHardStop(D48_PUMP); + delayBypassStateFlag = TRUE; + printf("[TRACE1] SC->Bypass trigger: tick=%lu D46_LEVEL=%d totalFill=%lu Qd=%.2f\n",getMSTimerCount(), spentChamberLevel, totalSpentChamberFill, getTDDialysateFlowrate()); state = DD_GEND_DIALYSATE_BYPASS_STATE; //Trigger alarm if count exceeded Index: firmware/App/Services/AlarmMgmtDD.c =================================================================== diff -u -ra6737c3bcc8286c153b778c2c395f465e76aaafb -ra08213c3d131203c21554d743c3ccb02575b70da --- firmware/App/Services/AlarmMgmtDD.c (.../AlarmMgmtDD.c) (revision a6737c3bcc8286c153b778c2c395f465e76aaafb) +++ firmware/App/Services/AlarmMgmtDD.c (.../AlarmMgmtDD.c) (revision a08213c3d131203c21554d743c3ccb02575b70da) @@ -116,7 +116,7 @@ if ( TRUE == isTransitionToFaultRequired() ) { // If alarm is a DD fault and the alarm manager can transition to fault immediately, go to fault mode - requestNewOperationMode( DD_MODE_FAUL ); + //requestNewOperationMode( DD_MODE_FAUL ); } } if ( ( TRUE == props.alarmIsDDFault ) && ( ALM_SRC_FP == props.alarmSource ) )