Index: firmware/App/Controllers/SpentChamberFill.c =================================================================== diff -u -ra08213c3d131203c21554d743c3ccb02575b70da -r173453569b2eb31b3f19572bf5386440667b0162 --- firmware/App/Controllers/SpentChamberFill.c (.../SpentChamberFill.c) (revision a08213c3d131203c21554d743c3ccb02575b70da) +++ firmware/App/Controllers/SpentChamberFill.c (.../SpentChamberFill.c) (revision 173453569b2eb31b3f19572bf5386440667b0162) @@ -14,32 +14,23 @@ * @date (original) 21-Aug-2025 * ***************************************************************************/ + #include "BalancingChamber.h" -#include "ConcentratePumps.h" #include "Conductivity.h" +#include "ConcentratePumps.h" #include "DialysatePumps.h" #include "FpgaDD.h" #include "Heaters.h" -#include "Level.h" -#include "MessagePayloads.h" -#include "Messaging.h" #include "ModeGenDialysate.h" -#include "ModeGenDialysate.h" -#include "ModeStandby.h" +#include "Messaging.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 * @{ @@ -51,14 +42,6 @@ // ********** 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. @@ -67,10 +50,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 handleSpentChamberFillWaitPressureStabilizeState( 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); @@ -89,7 +72,6 @@ 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; @@ -113,7 +95,7 @@ void transitionToSpentChamberFill( void ) { initSpentChamberFill(); - + updateBalChamberSwitchingPeriod(); // Follow the same cycle for spent chamber fill spentChamberFillSwitchingPeriod = getBalChamberSwitchingPeriod(); } @@ -130,24 +112,19 @@ *************************************************************************/ U32 execSpentChamberFillControl( void ) { - // Increment counter indicating fill - + // Increment counter indicating fill is in progress. currentSpentChamberFillSwitchingCounter += 1; - // execute current spent chamber fill exec state - + // execute current spent chamber fill exec state switch ( spentChamberFillExecState ) { - case SPENT_CHAMBER_FILL_STATE_START: - spentChamberFillExecState = SPENT_CHAMBER_FILL_WAIT1_STABILIZE_STATE; + spentChamberFillExecState = SPENT_CHAMBER_FILL_WAIT_PRESSURE_STABILIZE_STATE; break; - case SPENT_CHAMBER_FILL_WAIT1_STABILIZE_STATE: - spentChamberFillExecState = handleSpentChamberFillWait1StabilizeState(); + + case SPENT_CHAMBER_FILL_WAIT_PRESSURE_STABILIZE_STATE: + spentChamberFillExecState = handleSpentChamberFillWaitPressureStabilizeState(); break; - case SPENT_CHAMBER_FILL_WAIT2_STABILIZE_STATE: - spentChamberFillExecState = handleSpentChamberFillWait2StabilizeState(); - break; case SPENT_CHAMBER_FILL_STATE1_FILL_START: spentChamberFillExecState = handleSpentChamberFillState1FillStart(); @@ -179,7 +156,6 @@ break; } - //Publish spent chamber fill data publishSpentChamberFillData(); @@ -209,102 +185,33 @@ setValveState( D22_VALV, VALVE_STATE_OPEN ); } - -static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillWait1StabilizeState( void ) +/*********************************************************************//** + * @brief + * The handleSpentChamberFillWaitPressureStabilizeState function introduces the pressure + * stabilization period before starting the spent chamber fill + * for state 2 fill process. + * @details \b Inputs: none + * @details \b Outputs: valve states + * @return none. + *************************************************************************/ +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillWaitPressureStabilizeState( void ) { - SPENT_CHAMBER_FILL_EXEC_STATE_T nextState = SPENT_CHAMBER_FILL_WAIT1_STABILIZE_STATE; - if (getBalancingChamberStatus()== FALSE ) + SPENT_CHAMBER_FILL_EXEC_STATE_T nextState = SPENT_CHAMBER_FILL_WAIT_PRESSURE_STABILIZE_STATE; - { - - //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 @@ -358,13 +265,11 @@ 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 ); } @@ -382,20 +287,12 @@ 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 ) ) ) || TRUE) + if ( ( TRUE == isConcentratePumpDosingCompleted( D11_PUMP ) ) && + ( TRUE == isConcentratePumpDosingCompleted( D10_PUMP ) ) ) { state = SPENT_CHAMBER_FILL_STATE1_FILL_END; - } - state = SPENT_CHAMBER_FILL_STATE1_FILL_END; - //printf("\n Inside handleSpentChamberState1DosingControl"); return state; } @@ -413,18 +310,13 @@ 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); + // Move to next state. state = SPENT_CHAMBER_FILL_STATE2_FILL_START; } @@ -460,14 +352,12 @@ 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; @@ -484,20 +374,13 @@ 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 ) ) ) || TRUE) + if ( ( TRUE == isConcentratePumpDosingCompleted( D11_PUMP ) ) && + ( TRUE == isConcentratePumpDosingCompleted( D10_PUMP ) ) ) { 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; } @@ -519,12 +402,9 @@ { //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; }