Index: firmware/App/Controllers/DryBiCart.c =================================================================== diff -u -rfd2fa46f071ef8943c9c2e432439e34597254bfc -rfc26356f5aae3e51f6267e41da0d74e76a9d5b6d --- firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision fd2fa46f071ef8943c9c2e432439e34597254bfc) +++ firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision fc26356f5aae3e51f6267e41da0d74e76a9d5b6d) @@ -42,80 +42,45 @@ // ********** private definitions ********** -#define DRY_BICART_DATA_PUBLISH_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the balancing chamber data published. -#define PRESSURE_OFFSET_PSI 7.0F ///< Dry bicart pressure offset. +#define DRY_BICART_DATA_PUBLISH_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the drybicart data published. +#define PRESSURE_OFFSET_PSI 7.0F ///< The difference between the actual pressure measured at bicart assembly and the measured D66 pressure based on the placement of the sensor +#define DRY_BICART_PERSISTENCE_DURATION_MS 200 ///< Fill persistence duration to overcome the pressure overshoot/ drop for beta 1.9 and above. // Dry Bicart Fill -#define DRY_BICART_FILL_PERSISTENCE_MS 200 ///< Fill persistence duration to overcome the pressure over shoot for beta 1.9 and above. -#define DRY_BICART_FILL_COMPLETE_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to reset the request flag after fill complete -#define DRY_BICART_FILL_COMPLETE_PRESSURE ( 10.0F + PRESSURE_OFFSET_PSI ) ///< Maximum pressure reached to indicate the dry bicart fill being completed. -#define DRY_BICART_FILL_INITIATE_PRESSURE 1.5F ///< Minimum pressure required to initiate the dry bicart fill process. -#define DRY_BICART_FILL_COMPLETE_SUPPLY_PRESSURE 10.0F ///< Maximum pressure allowed at bicart fill during supply process/state -#define DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE 3.0F ///< Minimum pressure required to initiate the dry bicart fill during supply process/state -#define MAX_DRY_BICART_FILL_COMPLETE_PRESSURE 20.0F ///< Very max dry bicart fill complete pressure for persistence on d66 -#define DRY_BICART_DEFAULT_MAX_FILL_CYCLE_CNT 10 ///< Default max fill cycle allowed for dry bicart fill/mix with water. -#define DRY_BICART_MAX_FILL_CYCLE_CNT 30 ///< Max fill cycle allowed (by override) for dry bicart fill/mix with water. -#define DRY_BICART_MINIMUM_FILL_CYCLE_CNT 3 ///< Minimum fill cycle count for filling dry bicart without overpressuring + +#define DRY_BICART_FILL_COMPLETE_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to reset the request flag after fill complete +#define DRY_BICART_FILL_COMPLETE_PRESSURE_PSI ( 10.0F + PRESSURE_OFFSET_PSI ) ///< Maximum pressure reached to indicate the dry bicart fill being completed. +#define DRY_BICART_FILL_INITIATE_PRESSURE_PSI 1.5F ///< Minimum pressure required to initiate the dry bicart fill process. +#define DRY_BICART_FILL_COMPLETE_SUPPLY_PRESSURE_PSI 10.0F ///< Maximum pressure allowed at bicart fill during supply process/state +#define DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE_PSI 3.0F ///< Minimum pressure required to initiate the dry bicart fill during supply process/state +#define MAX_DRY_BICART_FILL_COMPLETE_PRESSURE 20.0F ///< Very max dry bicart fill complete pressure for persistence on d66 +#define DRY_BICART_DEFAULT_MAX_FILL_CYCLE_CNT 10 ///< Default max fill cycle allowed for dry bicart fill/mix with water. +#define DRY_BICART_MAX_FILL_CYCLE_CNT 15 ///< Max fill cycle allowed (by override) for dry bicart fill/mix with water. +#define DRY_BICART_MINIMUM_FILL_CYCLE_CNT 3 ///< Minimum fill cycle count for filling dry bicart // Dry Bicart Fill Vent -#define DRY_BICART_FILL_VENT_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to vent dry bicart gas before actuating Bicarb chamber(F) venting. -#define DRY_BICART_FILL_VENT_MAX_TIME_MS ( 3 * MS_PER_SECOND ) ///< Max time to vent both dry bicart and Chamber F. -#define DRY_BICART_FILL_VENT_COMPLETE_PRESSURE 1.5F ///< Pressure reached to indicate the dry bicart venting being completed. +#define DRY_BICART_FILL_VENT_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to vent dry bicart gas before actuating Bicarb chamber(F) venting. +#define DRY_BICART_FILL_VENT_MAX_TIME_MS ( 3 * MS_PER_SECOND ) ///< Max time to vent both dry bicart and Chamber F. +#define DRY_BICART_FILL_VENT_COMPLETE_PRESSURE_PSI 1.5F ///< Pressure reached to indicate the dry bicart venting being completed. // Bicarb chamber fill/Supply #ifdef CONDUCTIVE_LEVEL_SENSOR_ENABLED -#define DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ( 10 * MS_PER_SECOND ) ///< Max time allowed for supply (opening D80 valve) during bicarb chamber (F) fill using level sensor +#define DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ( 10 * MS_PER_SECOND ) ///< Max time allowed for supply (opening D80 valve) during bicarb chamber (F) fill using level sensor #else -#define DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ( 3 * MS_PER_SECOND ) ///< Max time allowed for supply (opening D80 valve) during bicarb chamber (F) fill time based fill +#define DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ( 3 * MS_PER_SECOND ) ///< Max time allowed for supply (opening D80 valve) during bicarb chamber (F) fill time based fill #endif -#define DRY_BICART_SUPPLY_VENT_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to vent dry bicart gas before actuating Bicarb chamber(F) venting. -#define DRY_BICART_SUPPLY_VENT_MAX_TIME_MS ( 1 * MS_PER_SECOND ) ///< Max time to vent both dry bicart and Chamber F. -#define DRY_BICART_SUPPLY_COMPLETE_TIME_MS ( 2 * MS_PER_SECOND ) ///< Wait time to close the D80 valve after D65 is closed -#define DRY_BICART_SUPPLY_FILL_PERSISTENCE_MS 200 ///< Supply fill persistence duration to overcome the pressure over shoot for beta 1.9 and above. -#define DRY_BICART_SUPPLY_VENT_PERSISTENCE_MS 200 ///< Supply vent persistence duration to overcome the pressure over shoot for beta 1.9 and above. +#define DRY_BICART_SUPPLY_VENT_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to vent dry bicart gas before actuating Bicarb chamber(F) venting. +#define DRY_BICART_SUPPLY_VENT_MAX_TIME_MS ( 1 * MS_PER_SECOND ) ///< Max time to vent both dry bicart and Chamber F. +#define DRY_BICART_SUPPLY_COMPLETE_TIME_MS ( 2 * MS_PER_SECOND ) ///< Wait time to close the D80 valve after D65 is closed // Dry Bicart Drain -#define LARGE_DRY_BICART_MAX_DRAIN_TIME_MS ( 8 * SEC_PER_MIN * MS_PER_SECOND ) ///< Max drain time for large dry bicart in ms. -#define SMALL_DRY_BICART_MAX_DRAIN_TIME_MS ( 4 * SEC_PER_MIN * MS_PER_SECOND ) ///< Max drain time for small dry bicart in ms. -#define DRY_BICART_DRAIN_FLUID_PHASE_TIME_MS ( 3 * MS_PER_SECOND ) ///< Time to stay in fluid drain per cycle -#define DRY_BICART_DRAIN_VENT_PHASE_TIME_MS ( 8 * MS_PER_SECOND ) ///< Time to keep D64 open per vent cycle -#define DRY_BICART_DRAIN_COND_SAMPLE_PERIOD_MS 500 ///< Conductivity sample period -#define DRY_BICART_DRAIN_COND_ZERO_THRESH 0.05F ///< Zero conductivity threshold -#define DRY_BICART_DRAIN_COND_STABLE_SAMPLES 10U ///< Debounce samples (10*50ms=500ms) +#define LARGE_DRY_BICART_MAX_DRAIN_TIME_MS ( 8 * SEC_PER_MIN * MS_PER_SECOND ) ///< Max drain time for large dry bicart in ms. +#define SMALL_DRY_BICART_MAX_DRAIN_TIME_MS ( 4 * SEC_PER_MIN * MS_PER_SECOND ) ///< Max drain time for small dry bicart in ms. +#define DRY_BICART_DRAIN_FLUID_PHASE_TIME_MS ( 3 * MS_PER_SECOND ) ///< Time to stay in fluid drain per cycle +#define DRY_BICART_DRAIN_VENT_PHASE_TIME_MS ( 8 * MS_PER_SECOND ) ///< Time to keep D64 open per vent cycle +#define DRY_BICART_DRAIN_COND_SAMPLE_PERIOD_MS 500 ///< Conductivity sample period +#define DRY_BICART_DRAIN_COND_ZERO_THRESH 0.05F ///< Zero conductivity threshold +#define DRY_BICART_DRAIN_COND_STABLE_SAMPLES 10U ///< De-bounce samples (10*50ms=500ms) -// drybicarb mixing -#define BICARB_VOL_CONTROL_P_COEFFICIENT ( 0.00008484 * 2 ) ///< Bicarb proportional gain (kp) -#define BICARB_VOL_CONTROL_I_COEFFICIENT ( 0.00033936 / 5 ) ///< Bicarb integral gain. (ki) -#define MIN_BICARB_VOLUME_ML 0.868686869 ///< Minimum bicarb volume in mL -#define MAX_BICARB_VOLUME_ML 1.8 ///< Maximum bicarb volume in mL - -#define ACID_VOL_CONTROL_P_COEFFICIENT ( 0.00000997 / 2 ) ///< Acid proportional gain (kp) -#define ACID_VOL_CONTROL_I_COEFFICIENT ( 0.00003988 / 2 ) ///< Acid integral gain. (ki) -#define MIN_ACID_VOLUME_ML 0.3 ///< Minimum acid volume in mL -#define MAX_ACID_VOLUME_ML 1.0 ///< Maximum acid volume in mL/min. - -#define DRY_BICARB_TARGET_CONDUCTIVITY 2714.0F ///< Target bicarb conductivity -#define DRY_BICARB_DELTA_CONDUCTIVITY 500.0F ///< Delta bicarb conductivity - -#define DRY_ACID_BICARB_TARGET_CONDUCTIVITY 13734.87F ///< Target acid bicarb mix conductivity -#define DRY_ACID_BICARB_DELTA_CONDUCTIVITY 700.0F ///< Delta acid bicarb mix conductivity - -#define ACID_TYPE_1K_2_5_CA 11192.55F ///< standard acid conductivity for 1K -#define ACID_TYPE_2K_2_5_CA 11313.62F ///< standard acid conductivity for 2K -#define ACID_TYPE_3K_2_5_CA 11435.68F ///< standard acid conductivity for 3K - -#define MIN_BICARB_CONDUCTIVITY 2000 ///< Minimum Bicarb conductivity limit -#define MAX_BICARB_CONDUCTIVITY 4000 ///< Maximum Bicarb conductivity limit - -#define MIX_NO_FEED_FORWARD 0.0F ///< Feedforward term for dialysate closed loop control - -#define MIX_CONTROL_INTERVAL_MS ( 15 * MS_PER_SECOND ) ///< Dialysate mixing control interval in ms -#define BICARB_MIX_CONTROL_INTERVAL ( 3 * MS_PER_SECOND /\ - TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the dialysate mix is controlled. -#define ACID_MIX_CONTROL_INTERVAL ( MIX_CONTROL_INTERVAL_MS /\ - TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the dialysate mix is controlled. -#define BICARB_DEADBAND_CONTROL 50.0F ///< Dry Bicarb dead band control -#define ACID_DEADBAND_CONTROL 100.0F ///< Acid dead band control - /// Payload record structure for dry bicart fill request typedef struct { @@ -132,31 +97,6 @@ NUM_OF_DRY_BICART_OPERATION ///< Number of dry bicart operation } DRY_BICART_OPERATION_T; -/// Enumeration of dialysate Mixing id. -typedef enum DialysateMixingID -{ - BICARB_MIX_ID = 0, ///< Bicarb mixing id - DIALYSATE_MIX_ID_FIRST = BICARB_MIX_ID, ///< First dialysate mixing in list - ACID_MIX_ID, ///< Acid mix id - NUM_OF_DIALYSATE_MIXING_ID ///< Number of dialysate mix ids -} DIALYSATE_MIXING_ID_T; - -/// Enumeration of dialysate Mixing states. -typedef enum DialysateMixing_States -{ - DIALYSATE_MIXING_OPEN_LOOP_STATE = 0, ///< Dialysate open loop state - DIALYSATE_MIXING_RAMP_UP_STATE, ///< Dialysate mixing ramp up state - DIALYSATE_MIXING_CONTROL_TO_TARGET_STATE, ///< Dialysate mixing control to target state - NUM_OF_DIALYSATE_MIXING_STATES ///< Number of dialysate mixing states -} DIALYSATE_MIXING_STATE_T; - -/// Dialysate Mixing state machine data structure -typedef struct -{ - U32 controlTimerCounter; ///< Timer counter to perform control on dialysate mixing. - DIALYSATE_MIXING_STATE_T dialysateMixingState; ///< Current state of dialysate mixing controller state machine. -} DIALYSATE_MIXING_DATA_T; - // ********** private data ********** static DRY_BICART_FILL_EXEC_STATE_T dryBiCartFillExecState; ///< Current state of dry bicart fill executive state machine. @@ -192,38 +132,10 @@ static U32 dryBiCartDrainTimePeriod; ///< Dry bicart drain time period static U32 dryBiCartPersistenceStartTime; ///< Dry bicart Persistence time. -static U32 drybicartPersistenceOnLowercartPressureStartTime; ///< Dry bicart Persistence on lower cart pressure start time. +static U32 drybicartPersistenceOnLowercartPressureStartTime; ///< Dry bicart Persistence on lower cart pressure start time. static BOOL dryBiCartPressureDecayStartTimeFlag; ///< Dry bicart d66 pressure decay start timer. static DRY_BICART_OPERATION_T dryBicartStartRequest; ///< Dry bicart operation, fill or supply or drain request -// drybicart mixing -static OVERRIDE_F32_T dryBiCartAcidMixVolume; ///< Acid concentrate volume in ml ( overrideable). -static OVERRIDE_F32_T dryBiCartBicarbMixVolume; ///< Bicarb concentrate volume in ml ( overrideable). - -static OVERRIDE_F32_T dryBiCartAcidMixVolumeKpGain; ///< Acid kp gain. -static OVERRIDE_F32_T dryBiCartAcidMixVolumeKiGain; ///< Acid ki gain. - -static OVERRIDE_F32_T dryBiCartBicarbMixVolumeKpGain; ///< Bicarb kp gain -static OVERRIDE_F32_T dryBiCartBicarbMixVolumeKiGain; ///< Acid ki gain. - -static DIALYSATE_MIXING_DATA_T dialysateMix[ NUM_OF_DIALYSATE_MIXING_ID ]; ///< Array of dialysate mixing data structure. - -static OVERRIDE_F32_T dryBiCartBicarbTargetConductivity; ///< Target bicarb conductivity -static OVERRIDE_F32_T dryBiCartBicarbDeltaConductivity; ///< Target delta conductivity - -static OVERRIDE_F32_T dryBiCartDialysateTargetConductivity; ///< Acid bicarb mix conductivity -static OVERRIDE_F32_T dryBiCartDialysateDeltaConductivity; ///< Acid bicarb delta conductivity - -static OVERRIDE_F32_T dryBiCartStdMixingBCVolume; ///< Acid bicarb mix conductivity -static OVERRIDE_F32_T dryBiCartTargetAdjNaSettings; ///< Acid bicarb delta conductivity -static OVERRIDE_F32_T dryBiCartTargetAdjBicarbSettings; ///< Acid bicarb delta conductivity - -static OVERRIDE_U32_T dryBiCartMixControlInterval; ///< Mix control interval -static OVERRIDE_U32_T dryBiCartAcidMixControlInterval; ///< Mix control interval - -static PI_CONTROLLER_SIGNALS_DATA bicarbControlSignals; ///< Bicarb closed loop control signal data -static PI_CONTROLLER_SIGNALS_DATA acidControlSignals; ///< Acid closed loop control signal data - // ********** private function prototypes ********** static void updateDrybicartOperation(void); @@ -239,7 +151,7 @@ static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberStartState( void ); static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterStartState( void ); static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterEndState( void ); -static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberFillState( void ); +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChambeSupplyStart( void ); static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberPressureCheckState( void ); static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentStartState(void); static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentEndState(void); @@ -249,21 +161,6 @@ static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainDurationCheckState( void ); static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainEndState( void ); -// Mixing control loop -static DIALYSATE_MIXING_STATE_T handleDialysateMixOpenLoopState( DIALYSATE_MIXING_ID_T mixId ); -static DIALYSATE_MIXING_STATE_T handleDialysateMixRampToTargetState( DIALYSATE_MIXING_ID_T mixId ); -static DIALYSATE_MIXING_STATE_T handleDialysateMixControlToTargetState( DIALYSATE_MIXING_ID_T mixId ); - -static void setBicarbMixVol( F32 targetValue ); -static void setAcidMixVol( F32 targetValue ); -static F32 getBicarbDeltaConductivity( void ); -static F32 getBicarbTargetConductivity( void ); -static F32 getAcidBicarbDeltaConductivity( void ); -static F32 getAcidBicarbTargetConductivity( void ); -static F32 getBicarbKpGainCoefficient( void ); -static F32 getBicarbKiGainCoefficient( void ); -static F32 getAcidKpGainCoefficient( void ); -static F32 getAcidKiGainCoefficient( void ); static F32 getDryBicartLowerCartPressure( void ); static F32 getDryBicartUpperCartPressure( void ); static U32 getDryBicartMixControlInterval( void ); @@ -282,19 +179,11 @@ *************************************************************************/ void initDryBiCart( void ) { - DIALYSATE_MIXING_ID_T mixId; - dryBiCartFillExecState = DRY_BICART_START_STATE; bicarbChamberFillExecState = BICARB_CHAMBER_START_STATE; dryBiCartDrainExecState = DRY_BICART_DRAIN_START_STATE; dryBicartStartRequest = DRY_BICART_IDLE; - for ( mixId = DIALYSATE_MIX_ID_FIRST; mixId < NUM_OF_DIALYSATE_MIXING_ID; mixId++ ) - { - dialysateMix[ mixId ].dialysateMixingState = DIALYSATE_MIXING_OPEN_LOOP_STATE; - dialysateMix[ mixId ].controlTimerCounter = 0; - } - dryBiCartDataPublishInterval.data = DRY_BICART_DATA_PUBLISH_INTERVAL; dryBiCartDataPublishInterval.ovData = DRY_BICART_DATA_PUBLISH_INTERVAL; dryBiCartDataPublishInterval.ovInitData = 0; @@ -325,71 +214,16 @@ dryBiCartType.ovInitData = 0; dryBiCartType.override = OVERRIDE_RESET; - dryBiCartAcidMixVolume.data = DEFAULT_ACID_VOLUME_ML; - dryBiCartAcidMixVolume.ovData = DEFAULT_ACID_VOLUME_ML; - dryBiCartAcidMixVolume.ovInitData = 0.0F; - dryBiCartAcidMixVolume.override = OVERRIDE_RESET; - - dryBiCartBicarbMixVolume.data = DEFAULT_BICARB_VOLUME_ML; - dryBiCartBicarbMixVolume.ovData = DEFAULT_BICARB_VOLUME_ML; - dryBiCartBicarbMixVolume.ovInitData = 0.0F; - dryBiCartBicarbMixVolume.override = OVERRIDE_RESET; - - dryBiCartAcidMixVolumeKpGain.data = ACID_VOL_CONTROL_P_COEFFICIENT; - dryBiCartAcidMixVolumeKpGain.ovData = ACID_VOL_CONTROL_P_COEFFICIENT; - dryBiCartAcidMixVolumeKpGain.ovInitData = 0.0F; - dryBiCartAcidMixVolumeKpGain.override = OVERRIDE_RESET; - - dryBiCartAcidMixVolumeKiGain.data = ACID_VOL_CONTROL_I_COEFFICIENT; - dryBiCartAcidMixVolumeKiGain.ovData = ACID_VOL_CONTROL_I_COEFFICIENT; - dryBiCartAcidMixVolumeKiGain.ovInitData = 0.0F; - dryBiCartAcidMixVolumeKiGain.override = OVERRIDE_RESET; - - dryBiCartBicarbMixVolumeKpGain.data = BICARB_VOL_CONTROL_P_COEFFICIENT; - dryBiCartBicarbMixVolumeKpGain.ovData = BICARB_VOL_CONTROL_P_COEFFICIENT; - dryBiCartBicarbMixVolumeKpGain.ovInitData = 0.0F; - dryBiCartBicarbMixVolumeKpGain.override = OVERRIDE_RESET; - - dryBiCartBicarbMixVolumeKiGain.data = BICARB_VOL_CONTROL_I_COEFFICIENT; - dryBiCartBicarbMixVolumeKiGain.ovData = BICARB_VOL_CONTROL_I_COEFFICIENT; - dryBiCartBicarbMixVolumeKiGain.ovInitData = 0.0F; - dryBiCartBicarbMixVolumeKiGain.override = OVERRIDE_RESET; - - dryBiCartBicarbTargetConductivity.data = DRY_BICARB_TARGET_CONDUCTIVITY; - dryBiCartBicarbTargetConductivity.ovData = DRY_BICARB_TARGET_CONDUCTIVITY; - dryBiCartBicarbTargetConductivity.ovInitData = 0.0F; - dryBiCartBicarbTargetConductivity.override = OVERRIDE_RESET; - - dryBiCartBicarbDeltaConductivity.data = DRY_BICARB_DELTA_CONDUCTIVITY; - dryBiCartBicarbDeltaConductivity.ovData = DRY_BICARB_DELTA_CONDUCTIVITY; - dryBiCartBicarbDeltaConductivity.ovInitData = 0.0F; - dryBiCartBicarbDeltaConductivity.override = OVERRIDE_RESET; - - dryBiCartDialysateTargetConductivity.data = DRY_ACID_BICARB_TARGET_CONDUCTIVITY; - dryBiCartDialysateTargetConductivity.ovData = DRY_ACID_BICARB_TARGET_CONDUCTIVITY; - dryBiCartDialysateTargetConductivity.ovInitData = 0.0F; - dryBiCartDialysateTargetConductivity.override = OVERRIDE_RESET; - - dryBiCartDialysateDeltaConductivity.data = DRY_ACID_BICARB_DELTA_CONDUCTIVITY; - dryBiCartDialysateDeltaConductivity.ovData = DRY_ACID_BICARB_DELTA_CONDUCTIVITY; - dryBiCartDialysateDeltaConductivity.ovInitData = 0.0F; - dryBiCartDialysateDeltaConductivity.override = OVERRIDE_RESET; - - dryBiCartUpperCartPressure.data = DRY_BICART_FILL_COMPLETE_SUPPLY_PRESSURE; - dryBiCartUpperCartPressure.ovData = DRY_BICART_FILL_COMPLETE_SUPPLY_PRESSURE; + dryBiCartUpperCartPressure.data = DRY_BICART_FILL_COMPLETE_SUPPLY_PRESSURE_PSI; + dryBiCartUpperCartPressure.ovData = DRY_BICART_FILL_COMPLETE_SUPPLY_PRESSURE_PSI; dryBiCartUpperCartPressure.ovInitData = 0.0F; dryBiCartUpperCartPressure.override = OVERRIDE_RESET; - dryBiCartLowerCartPressure.data = DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE; - dryBiCartLowerCartPressure.ovData = DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE; + dryBiCartLowerCartPressure.data = DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE_PSI; + dryBiCartLowerCartPressure.ovData = DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE_PSI; dryBiCartLowerCartPressure.ovInitData = 0.0F; dryBiCartLowerCartPressure.override = OVERRIDE_RESET; - dryBiCartMixControlInterval.data = BICARB_MIX_CONTROL_INTERVAL; - dryBiCartMixControlInterval.ovData = BICARB_MIX_CONTROL_INTERVAL; - dryBiCartMixControlInterval.ovInitData = 0; - dryBiCartMixControlInterval.override = OVERRIDE_RESET; - dryBiCartPressureDecayStartTimeFlag = FALSE; dryBiCartFillVentTimeOut = FALSE; dryBiCartFillStartTime = 0; @@ -403,16 +237,8 @@ dryBiCartDrainLastCondSampleTime = 0; dryBiCartDrainCondStableCount = 0; dryBiCartDrainTimePeriod = 0; - dryBiCartPersistanceStartTime = 0; + dryBiCartPersistenceStartTime = 0; drybicartPersistenceOnLowercartPressureStartTime = 0; - - initializePIController( PI_CONTROLLER_ID_BICARB_VOL, 0.0F,\ - getBicarbKpGainCoefficient(), getBicarbKiGainCoefficient(),\ - MIN_BICARB_VOLUME_ML, MAX_BICARB_VOLUME_ML, FALSE, MIX_NO_FEED_FORWARD ); - - initializePIController( PI_CONTROLLER_ID_ACID_VOL, 0.0F, \ - getAcidKpGainCoefficient(), getAcidKiGainCoefficient(),\ - MIN_ACID_VOLUME_ML, MAX_ACID_VOLUME_ML, FALSE, MIX_NO_FEED_FORWARD ); } /*********************************************************************//** @@ -430,43 +256,6 @@ /*********************************************************************//** * @brief - * The execDialysateCompositionMixingController function executes the dialysate mixing controller. - * @details \b Inputs: dialysateMix[ mixId ].dialysateMixingState - * @details \b Outputs:dialysateMix[ mixId ].dialysateMixingState - * @details \b Alarms: ALARM_ID_DD_SOFTWARE_FAULT if invalid dialysate mixing - * state machine found. - * @return none - *************************************************************************/ -void execDialysateCompositionMixingController( void ) -{ - DIALYSATE_MIXING_ID_T mixId; - - for ( mixId = DIALYSATE_MIX_ID_FIRST; mixId < NUM_OF_DIALYSATE_MIXING_ID; mixId++ ) - { - switch ( dialysateMix[ mixId ].dialysateMixingState ) - { - case DIALYSATE_MIXING_OPEN_LOOP_STATE: - dialysateMix[ mixId ].dialysateMixingState = handleDialysateMixOpenLoopState( mixId ); - break; - - case DIALYSATE_MIXING_RAMP_UP_STATE: - dialysateMix[ mixId ].dialysateMixingState = handleDialysateMixRampToTargetState( mixId ); - break; - - case DIALYSATE_MIXING_CONTROL_TO_TARGET_STATE: - dialysateMix[ mixId ].dialysateMixingState = handleDialysateMixControlToTargetState( mixId ); - break; - - default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_DIALYSATE_MIX_EXEC_INVALID_STATE, mixId ) - dialysateMix[ mixId ].dialysateMixingState = DIALYSATE_MIXING_OPEN_LOOP_STATE; - break; - } - } -} - -/*********************************************************************//** - * @brief * The execDryBicart function executes the set of dry bicarbonate cartridge fill, * bicarbonate chamber fill and bicarbonate cartridge drain related state machines one at time * @details \b Inputs: dryBicartStartRequest @@ -670,34 +459,6 @@ /*********************************************************************//** * @brief - * TThe getBicarbMixVol function gets the bicarb mix volume provided by the controller - * @details \b Inputs: dryBiCartBicarbMixVolume - * @details \b Outputs: none - * @return TRUE if successful, FALSE if not. - *************************************************************************/ -F32 getBicarbMixVol( void ) -{ - F32 result = getF32OverrideValue( &dryBiCartBicarbMixVolume ); - - return result; -} - -/*********************************************************************//** - * @brief - * The getAcidMixVol function gets acid mix volume provided by the controller - * @details \b Inputs: dryBiCartAcidMixVolume - * @details \b Outputs: none - * @return TRUE if successful, FALSE if not. - *************************************************************************/ -F32 getAcidMixVol( void ) -{ - F32 result = getF32OverrideValue( &dryBiCartAcidMixVolume ); - - return result; -} - -/*********************************************************************//** - * @brief * The setBicarbChamberFillRequested function sets the chmaberFillRequest * flag value to be True. * @details \b Inputs: dryBiCartFillRequested, dryBiCartDrainRequested @@ -840,149 +601,6 @@ /*********************************************************************//** * @brief - * The setAcidMixVol function sets acid mix volume provided by the controller - * flag value to be True. - * @details \b Inputs: none - * @details \b Outputs: dryBiCartAcidMixVolume - * @param targetValue acid mix volume - * @return TRUE if successful, FALSE if not. - *************************************************************************/ -static void setAcidMixVol( F32 targetValue ) -{ - dryBiCartAcidMixVolume.data = targetValue; -} - -/*********************************************************************//** - * @brief - * The setBicarbMixVol function sets bicarb Mix volume provided by the controller - * @details \b Inputs: none - * @details \b Outputs: dryBiCartBicarbMixVolume - * @param targetValue bicarb Mix volume - * @return TRUE if successful, FALSE if not. - *************************************************************************/ -static void setBicarbMixVol( F32 targetValue ) -{ - dryBiCartBicarbMixVolume.data = targetValue; -} - -/*********************************************************************//** - * @brief - * The getBicarbDeltaConductivity function gets the delta target conductivity - * @details \b Inputs: dryBiCartBicarbDeltaConductivity - * @details \b Outputs: none - * @return TRUE if successful, FALSE if not. - *************************************************************************/ -static F32 getBicarbDeltaConductivity( void ) -{ - F32 result = getF32OverrideValue( &dryBiCartBicarbDeltaConductivity ); - - return result; -} - -/*********************************************************************//** - * @brief - * The getBicarbTargetConductivity function gets the target conductivity - * @details \b Inputs: dryBiCartBicarbTargetConductivity - * @details \b Outputs: none - * @return TRUE if successful, FALSE if not. - *************************************************************************/ -static F32 getBicarbTargetConductivity( void ) -{ - F32 result = getF32OverrideValue( &dryBiCartBicarbTargetConductivity ); - - return result; -} - -/*********************************************************************//** - * @brief - * The getAcidBicarbDeltaConductivity function gets the acid bicarb delta target conductivity - * @details \b Inputs: dryBiCartAcidBicarbMixDeltaConductivity - * @details \b Outputs: none - * @return TRUE if successful, FALSE if not. - *************************************************************************/ -static F32 getAcidBicarbDeltaConductivity( void ) -{ - F32 result = getF32OverrideValue( &dryBiCartDialysateDeltaConductivity ); - - return result; -} - -/*********************************************************************//** - * @brief - * The getAcidBicarbTargetConductivity function gets the acid bicarb delta target conductivity - * @details \b Inputs: dryBiCartAcidBicarbMixTargetConductivity - * @details \b Outputs: none - * @return TRUE if successful, FALSE if not. - *************************************************************************/ -static F32 getAcidBicarbTargetConductivity( void ) -{ - F32 result = getF32OverrideValue( &dryBiCartDialysateTargetConductivity ); - - return result; -} - -/*********************************************************************//** - * @brief - * The getBicarbKpGainCoefficient function gets the Kp Gain for closed loop - * bicarb mix volume control - * @details \b Inputs: dryBiCartBicarbMixVolumeKpGain - * @details \b Outputs: none - * @return TRUE if successful, FALSE if not. - *************************************************************************/ -static F32 getBicarbKpGainCoefficient( void ) -{ - F32 result = getF32OverrideValue( &dryBiCartBicarbMixVolumeKpGain ); - - return result; -} - -/*********************************************************************//** - * @brief - * The getBicarbKiGainCoefficient function gets the Kp Gain for closed loop - * bicarb mix volume control - * @details \b Inputs: dryBiCartBicarbMixVolumeKiGain - * @details \b Outputs: none - * @return TRUE if successful, FALSE if not. - *************************************************************************/ -static F32 getBicarbKiGainCoefficient( void ) -{ - F32 result = getF32OverrideValue( &dryBiCartBicarbMixVolumeKiGain ); - - return result; -} - -/*********************************************************************//** - * @brief - * The getAcidKpGainCoefficient function gets the Kp Gain for closed loop - * acid mix volume control - * @details \b Inputs: dryBiCartAcidMixVolumeKpGain - * @details \b Outputs: none - * @return TRUE if successful, FALSE if not. - *************************************************************************/ -static F32 getAcidKpGainCoefficient( void ) -{ - F32 result = getF32OverrideValue( &dryBiCartAcidMixVolumeKpGain ); - - return result; -} - -/*********************************************************************//** - * @brief - * The getAcidKiGainCoefficient function gets the Ki Gain for closed loop - * acid mix volume control - * @details \b Inputs: dryBiCartAcidMixVolumeKiGain - * @details \b Outputs: none - * @return TRUE if successful, FALSE if not. - *************************************************************************/ -static F32 getAcidKiGainCoefficient( void ) -{ - F32 result = getF32OverrideValue( &dryBiCartAcidMixVolumeKiGain ); - - return result; -} - -/*********************************************************************//** - * @brief * The getDryBicartUpperCartPressure function gets the bicart upper threshold pressure * @details \b Inputs: dryBiCartUpperCartPressure * @details \b Outputs: none @@ -1011,164 +629,6 @@ /*********************************************************************//** * @brief - * The getDryBicartMixControlInterval function gets the bicart mix control interval - * @details \b Inputs: dryBiCartMixControlInterval - * @details \b Outputs: none - * @return TRUE if successful, FALSE if not. - *************************************************************************/ -static U32 getDryBicartMixControlInterval( void ) -{ - U32 result = getU32OverrideValue( &dryBiCartMixControlInterval ); - - return result; -} - -/*********************************************************************//** - * @brief - * The handleDialysateOpenLoopState function handles the dialysate open loop state of - * the dialysate mix controller state machine. - * @details \b Inputs: D17_COND, D29_COND - * @details \b Outputs: none - * @param mixId dialysate mix id to run the dialysate mix - * @return next state for the controller state machine - *************************************************************************/ -static DIALYSATE_MIXING_STATE_T handleDialysateMixOpenLoopState( DIALYSATE_MIXING_ID_T mixId ) -{ - DIALYSATE_MIXING_STATE_T result; - - if ( BICARB_MIX_ID == mixId ) - { - F32 measuredBicarbConductivity = getFilteredConductivity( D17_COND ); - - result = DIALYSATE_MIXING_OPEN_LOOP_STATE; - - if ( TRUE != getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DOSING_OPEN_LOOP_CONTROL ) ) - { - // if measured conductivity crossed (targetConductivity- deltaConuctivity) , switch to closed loop - if ( measuredBicarbConductivity >= ( getBicarbTargetConductivity() - getBicarbDeltaConductivity() ) ) - { - result = DIALYSATE_MIXING_RAMP_UP_STATE; - } - } - } - else if ( ACID_MIX_ID == mixId ) - { - F32 measuredAcidBicarbMixConductivity = getFilteredConductivity( D27_COND ); - - result = DIALYSATE_MIXING_OPEN_LOOP_STATE; - - if ( TRUE != getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DOSING_OPEN_LOOP_CONTROL ) ) - { - // if measured conductivity crossed (targetConductivity- deltaConuctivity) , switch to closed loop - if ( measuredAcidBicarbMixConductivity >= ( getAcidBicarbTargetConductivity() - getAcidBicarbDeltaConductivity() ) ) - { - result = DIALYSATE_MIXING_RAMP_UP_STATE; - } - } - } - - return result; -} - -/*********************************************************************//** - * @brief - * The handleDialysatePumpRampToTargetState function handles the dialysate ramp to target state of - * the dialysate mix controller state machine. - * @details \b Inputs: none - * @details \b Outputs: none - * @param mixId mix id to - * @return next state for the controller state machine - *************************************************************************/ -static DIALYSATE_MIXING_STATE_T handleDialysateMixRampToTargetState( DIALYSATE_MIXING_ID_T mixId ) -{ - DIALYSATE_MIXING_STATE_T state = DIALYSATE_MIXING_RAMP_UP_STATE; - - if ( BICARB_MIX_ID == mixId ) - { - resetPIController( PI_CONTROLLER_ID_BICARB_VOL, DEFAULT_BICARB_VOLUME_ML, MIX_NO_FEED_FORWARD ); - - state = DIALYSATE_MIXING_CONTROL_TO_TARGET_STATE; - } - else if ( ACID_MIX_ID == mixId ) - { - resetPIController( PI_CONTROLLER_ID_ACID_VOL, DEFAULT_ACID_VOLUME_ML, MIX_NO_FEED_FORWARD ); - - state = DIALYSATE_MIXING_CONTROL_TO_TARGET_STATE; - } - - return state; -} - -/*********************************************************************//** - * @brief - * The handleDialysatePumpControlToTargetState function handles the control to - * target state of the dialysate mix controller state machine.. - * @details \b Inputs: D17_COND, D29_COND, controlTimerCounter - * @details \b Outputs:none - * @return next state of the controller state machine - *************************************************************************/ -static DIALYSATE_MIXING_STATE_T handleDialysateMixControlToTargetState( DIALYSATE_MIXING_ID_T mixId ) -{ - DIALYSATE_MIXING_STATE_T state = DIALYSATE_MIXING_CONTROL_TO_TARGET_STATE; - - if ( BICARB_MIX_ID == mixId ) - { - // control interval for bicarb - if ( ( ++dialysateMix[ mixId ].controlTimerCounter >= getDryBicartMixControlInterval() ) ) - { - F32 bicarbMixVol; - - dialysateMix[ mixId ].controlTimerCounter = 0; - - // Control based on the measured and target conductivity - PI_CONTROLLER_SIGNALS_DATA debugBicarbControl; - F32 measuredBicarbConductivity; - - measuredBicarbConductivity = getFilteredConductivity( D17_COND ); - - if ( fabs ( getBicarbTargetConductivity() - measuredBicarbConductivity ) > BICARB_DEADBAND_CONTROL ) - { - bicarbMixVol = runPIController( PI_CONTROLLER_ID_BICARB_VOL, getBicarbTargetConductivity(), measuredBicarbConductivity ); - //Set bicarb mix vol only if its above dead band threshold, else use the previous set vlaue - setBicarbMixVol( bicarbMixVol ); - } - - debugBicarbControl = getDebugPIControllerSignals( PI_CONTROLLER_ID_BICARB_VOL ); - - memcpy( (void*)&bicarbControlSignals, (void*)&debugBicarbControl, sizeof(PI_CONTROLLER_SIGNALS_DATA) ); - } - } - - if ( ACID_MIX_ID == mixId ) - { - // control interval for acid - if ( ( ++dialysateMix[ mixId ].controlTimerCounter >= ACID_MIX_CONTROL_INTERVAL ) ) - { - F32 acidMixVol; - - dialysateMix[ mixId ].controlTimerCounter = 0; - - F32 measuredAcidBicarbMixConductivity = getFilteredConductivity( D27_COND ); - PI_CONTROLLER_SIGNALS_DATA debugAcidControl; - - if ( fabs ( getAcidBicarbTargetConductivity() - measuredAcidBicarbMixConductivity ) > ACID_DEADBAND_CONTROL ) - { - acidMixVol = runPIController( PI_CONTROLLER_ID_ACID_VOL, getAcidBicarbTargetConductivity(), measuredAcidBicarbMixConductivity ); - // set acid mix volume if its above dead band threshold , else use previous set value - setAcidMixVol( acidMixVol ); - } - - debugAcidControl = getDebugPIControllerSignals( PI_CONTROLLER_ID_ACID_VOL ); - - memcpy( (void*)&acidControlSignals, (void*)&debugAcidControl, sizeof(PI_CONTROLLER_SIGNALS_DATA) ); - } - } - - return state; -} - -/*********************************************************************//** - * @brief * The updateDrybicartOperation function initiates the water fill, bicarbonate supply or bicarbonate drain * operation * @details \b Inputs: none @@ -1232,7 +692,7 @@ * The handleDryBicartFillWaterStartState function initiates the water fill * into dry bicarbonate cartridge. * @details \b Inputs: none - * @details \b Outputs: valve states + * @details \b Outputs: valve states, dryBiCartFillStartTime * @return the next drybicart fill water end state. *************************************************************************/ static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterStartState( void ) @@ -1252,6 +712,7 @@ //Initiate timer to measure length of fill dryBiCartFillStartTime = getMSTimerCount(); + state = DRY_BICART_FILL_WATER_END_STATE; return state; @@ -1261,8 +722,9 @@ * @brief * The handleDryBicartFillWaterEndState function closes the valve opened * for Dry bicart fill. - * @details \b Inputs: D66 pressure sensor reading - * @details \b Outputs: valve states + * @details \b Inputs: D66 pressure sensor reading, dryBiCartPersistenceStartTime + * @details \b Outputs: valve states, lastFillDurationInMS, currentFillDurationInMS, + * biCartFillCycleCounter * @return the next drybicart degas start state. *************************************************************************/ static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillWaterEndState( void ) @@ -1271,12 +733,12 @@ F32 d66Pressure = getFilteredPressure( D66_PRES ); // Close dry bicart inlet water if D66 pressure is 17 PSI - if ( d66Pressure >= DRY_BICART_FILL_COMPLETE_PRESSURE ) + if ( d66Pressure >= DRY_BICART_FILL_COMPLETE_PRESSURE_PSI ) { // start the persistence timer once d66 reaches 17 PSI - if ( 0 == dryBiCartPersistanceStartTime ) + if ( 0 == dryBiCartPersistenceStartTime ) { - dryBiCartPersistanceStartTime = getMSTimerCount(); + dryBiCartPersistenceStartTime = getMSTimerCount(); } //check the the maximum cart pressure during persistence on D66 if ( d66Pressure >= MAX_DRY_BICART_FILL_COMPLETE_PRESSURE ) @@ -1287,20 +749,20 @@ currentFillDurationInMS = calcTimeSince( dryBiCartFillStartTime ); //Increment number of fill cycle biCartFillCycleCounter++; - dryBiCartPersistanceStartTime = 0; + dryBiCartPersistenceStartTime = 0; state = DRY_BICART_DEGAS_START_STATE; } // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening - if ( TRUE == didTimeout( dryBiCartPersistanceStartTime, DRY_BICART_FILL_PERSISTENCE_MS ) ) + if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) { setValveState( D65_VALV, VALVE_STATE_CLOSED ); lastFillDurationInMS = currentFillDurationInMS; currentFillDurationInMS = calcTimeSince( dryBiCartFillStartTime ); //Increment number of fill cycle biCartFillCycleCounter++; - dryBiCartPersistanceStartTime = 0; + dryBiCartPersistenceStartTime = 0; state = DRY_BICART_DEGAS_START_STATE; } @@ -1315,7 +777,7 @@ * The handleDryBicartDegasStartState function actuates the vent valve * present in the Bicart assembly. * @details \b Inputs: none - * @details \b Outputs: valve states + * @details \b Outputs: valve states, dryBiCartFillStartTime, dryBiCartPersistenceStartTime * @return the next drybicart degas end state. *************************************************************************/ static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartDegasStartState( void ) @@ -1328,7 +790,7 @@ setValveState( D85_VALV, VALVE_STATE_OPEN ); //Initiate timer to measure length of bicart vent dryBiCartFillStartTime = getMSTimerCount(); - dryBiCartPersistanceStartTime = 0; + dryBiCartPersistenceStartTime = 0; state = DRY_BICART_DEGAS_END_STATE; @@ -1339,8 +801,9 @@ * @brief * The handleDryBicartDegasEndState function open vent valve present in * the F Chamber (Bicarb) and closes the vent valve once pressure is met. - * @details \b Inputs: D66 pressure sensor reading, dryBiCartFillStartTime - * @details \b Outputs: valve states + * @details \b Inputs: D66 pressure sensor reading, dryBiCartFillStartTime, + * dryBiCartPersistenceStartTime + * @details \b Outputs: valve states, dryBiCartFillVentTimeOut * @return the next drybicart fill duration check state. *************************************************************************/ static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartDegasEndState( void ) @@ -1354,26 +817,26 @@ setValveState( D64_VALV, VALVE_STATE_OPEN ); // D66 pressure drops to below 1.5 PSI - if ( ( d66Pressure <= DRY_BICART_FILL_VENT_COMPLETE_PRESSURE ) ) + if ( ( d66Pressure <= DRY_BICART_FILL_VENT_COMPLETE_PRESSURE_PSI ) ) { // start the persistence timer once d66 reaches 1.5 PSI - if ( 0 == dryBiCartPersistanceStartTime ) + if ( 0 == dryBiCartPersistenceStartTime ) { - dryBiCartPersistanceStartTime = getMSTimerCount(); + dryBiCartPersistenceStartTime = getMSTimerCount(); } - // 200 ms persistence on D66 pressure since pressure drop below 1.5 PSI suddenly after opening D64 - if ( TRUE == didTimeout( dryBiCartPersistanceStartTime, DRY_BICART_FILL_PERSISTENCE_MS ) ) + // 200 ms persistence on D66 pressure since pressure drop below 1.5 PSI after opening D64 + if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) { setValveState( D85_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistanceStartTime = 0; + dryBiCartPersistenceStartTime = 0; state = DRY_BICART_FILL_DURATION_CHECK_STATE; } } else if ( ( TRUE == didTimeout( dryBiCartFillStartTime, DRY_BICART_FILL_VENT_MAX_TIME_MS ) ) ) { setValveState( D85_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistanceStartTime = 0; + dryBiCartPersistenceStartTime = 0; dryBiCartFillVentTimeOut = TRUE; state = DRY_BICART_FILL_DURATION_CHECK_STATE; @@ -1389,15 +852,14 @@ * The handleDryBicartFillDurationCheckState function checks the fill duration * between last and current fill and exits if the duration is reduced over period * or number of fill cycle done. - * @details \b Inputs: currentFillDurationInMS, lastFillDurationInMS, biCartMaxFillCycleCount + * @details \b Inputs: biCartMaxFillCycleCount, biCartFillCycleCounter * D66 pressure, biCartFillCycleCounter, dryBiCartFillRequested - * @details \b Outputs: valve states + * @details \b Outputs: valve states, dryBiCartFillStartTime, dryBiCartFillVentTimeOut * @return the next drybicart fill state. *************************************************************************/ static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillDurationCheckState( void ) { DRY_BICART_FILL_EXEC_STATE_T state = DRY_BICART_FILL_DURATION_CHECK_STATE; - U32 diffInFillDuration = abs( currentFillDurationInMS - lastFillDurationInMS ); U32 dryBiCartMaxFillCount = getU32OverrideValue( &biCartMaxFillCycleCount ); F32 d66Pressure = getFilteredPressure( D66_PRES ); @@ -1431,8 +893,9 @@ * @brief * The handleDryBicartFillCompleteState function terminal for the dry bicart * fill states. - * @details \b Inputs: dryBiCartFillRequested - * @details \b Outputs: valve states + * @details \b Inputs: dryBiCartFillRequested, dryBiCartFillStartTime + * @details \b Outputs: valve states, lastFillDurationInMS, biCartFillCycleCounter, + * dryBiCartFillVentTimeOut, dryBiCartFillRequested * @return the next drybicart start state. *************************************************************************/ static DRY_BICART_FILL_EXEC_STATE_T handleDryBicartFillCompleteState( void ) @@ -1446,12 +909,15 @@ currentFillDurationInMS = 0; lastFillDurationInMS = 0; biCartFillCycleCounter = 0; - dryBiCartFillVentTimeOut = FALSE; + dryBiCartFillVentTimeOut = FALSE; // Go idle dryBiCartFillRequested.data = FALSE; // for this request override also cleared dryBiCartFillRequested.ovData = FALSE; + // when fill complete , need to close the d3 valve + hydChamberWaterInletControl(); + state = DRY_BICART_START_STATE; } @@ -1497,7 +963,7 @@ * @brief * The handleBicarbChamberCartridgeFillWaterStartState function fill water in the dry bicart * @details \b Inputs: none - * @details \b Outputs: valve states + * @details \b Outputs: valve states, dryBiCarbSupplyStartTime, dryBiCartPersistenceStartTime * @return the next bicarb cartridge fill water end state. *************************************************************************/ static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberCartridgeFillWaterStartState( void ) @@ -1514,15 +980,15 @@ setValveState( D64_VALV, VALVE_STATE_OPEN ); dryBiCarbSupplyStartTime = getMSTimerCount(); - dryBiCartPersistanceStartTime = 0; + dryBiCartPersistenceStartTime = 0; return state; } /*********************************************************************//** * @brief * The handleBicarbChamberCartridgeFillWaterStartState function stop water in the dry bicart - * @details \b Inputs: D66 pressure + * @details \b Inputs: D66 pressure, dryBiCartPersistenceStartTime * @details \b Outputs: valve states * @return the next bicarb chamber check level state. *************************************************************************/ @@ -1532,29 +998,28 @@ F32 d66Pressure = getFilteredPressure( D66_PRES ); // check D66 pressure greater than or equal to 17 PSI - if ( d66Pressure >= DRY_BICART_FILL_COMPLETE_PRESSURE ) + if ( d66Pressure >= DRY_BICART_FILL_COMPLETE_PRESSURE_PSI ) { - // persistence // start the persistence timer once d66 reaches 17 PSI - if ( 0 == dryBiCartPersistanceStartTime ) + if ( 0 == dryBiCartPersistenceStartTime ) { - dryBiCartPersistanceStartTime = getMSTimerCount(); + dryBiCartPersistenceStartTime = getMSTimerCount(); } // check the the maximum cart pressure during persistence on D66 if ( d66Pressure >= MAX_DRY_BICART_FILL_COMPLETE_PRESSURE ) { // Close water inlet valve as D66 pressure reaches max PSI(20) after persistence setValveState( D65_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistanceStartTime = 0; + dryBiCartPersistenceStartTime = 0; state = BICARB_CHAMBER_FILL_STATE; } // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening - if ( TRUE == didTimeout( dryBiCartPersistanceStartTime, DRY_BICART_FILL_PERSISTENCE_MS ) ) + if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) { // Close water inlet valve as D66 pressure reaches 11 PSI after persistence setValveState( D65_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistanceStartTime = 0; + dryBiCartPersistenceStartTime = 0; state = BICARB_CHAMBER_FILL_STATE; } @@ -1565,13 +1030,12 @@ /*********************************************************************//** * @brief - * The handleBicarbChamberCheckLevelState function checks the bicarb level(D63) - * in the chamber F and decides to open the bicarb inlet valve (D80). - * @details \b Inputs: D63 level + * The handleBicarbChambeSupplyStart function open the bicarb inlet valve (D80). + * @details \b Inputs: none * @details \b Outputs: valve states, dryBiCarbSupplyStartTime * @return the next bicarb chamber fill state. *************************************************************************/ -static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberFillState( void ) +static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChambeSupplyStart( void ) { BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CHAMBER_PRESSURE_CHECK_STATE; @@ -1592,7 +1056,9 @@ * @brief * The handleBicarbChamberPressureCheckStartState function actuates the vent valve * present in the Bicart assembly. - * @details \b Inputs: D66 Pressure, D63 level, dryBiCarbSupplyStartTime + * @details \b Inputs: D66 Pressure, D63 level, dryBiCarbSupplyStartTime, + * dryBiCarbSypplyVentStartTime, dryBiCartPersistenceStartTime, bicarbChamberLevel, + * dryBiCartPressureDecayStartTimeFlag, drybicartPersistenceOnLowercartPressureStartTime * @details \b Outputs: dryBiCarbSypplyVentStartTime * @return the next bicarb chamber Supply Vent Start state. *************************************************************************/ @@ -1637,7 +1103,7 @@ drybicartPersistenceOnLowercartPressureStartTime = getMSTimerCount(); } // 200 ms persistence on D66 pressure - if ( TRUE == didTimeout( drybicartPersistenceOnLowercartPressureStartTime, DRY_BICART_SUPPLY_FILL_PERSISTENCE_MS ) ) + if ( TRUE == didTimeout( drybicartPersistenceOnLowercartPressureStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) { setValveState( D65_VALV, VALVE_STATE_OPEN ); drybicartPersistenceOnLowercartPressureStartTime = 0; @@ -1647,21 +1113,21 @@ else if ( d66Pressure >= getDryBicartUpperCartPressure() ) { // start persistence timer - if ( 0 == dryBiCartPersistanceStartTime ) + if ( 0 == dryBiCartPersistenceStartTime ) { - dryBiCartPersistanceStartTime = getMSTimerCount(); + dryBiCartPersistenceStartTime = getMSTimerCount(); } //check the the maximum cart pressure during persistence on D66 if ( d66Pressure >= MAX_DRY_BICART_FILL_COMPLETE_PRESSURE ) { setValveState( D65_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistanceStartTime = 0; + dryBiCartPersistenceStartTime = 0; } // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening - if ( TRUE == didTimeout( dryBiCartPersistanceStartTime, DRY_BICART_SUPPLY_FILL_PERSISTENCE_MS ) ) + if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) { setValveState( D65_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistanceStartTime = 0; + dryBiCartPersistenceStartTime = 0; } } @@ -1672,7 +1138,7 @@ * @brief * The handleBicarbChamberSupplyVentStartState function actuates the vent valve * present in the Bicart assembly. - * @details \b Inputs: dryBiCarbSypplyVentStartTime + * @details \b Inputs: dryBiCarbSypplyVentStartTime, dryBiCartPersistenceStartTime * @details \b Outputs: dryBiCarbSypplyVentStartTime * @return the next bicarb chamber Supply Vent End state. *************************************************************************/ @@ -1689,25 +1155,24 @@ // D66 pressure drops to below 1.5 PSI or time out if ( ( d66Pressure <= DRY_BICART_FILL_VENT_COMPLETE_PRESSURE ) ) { - // start the persistance timer once d66 reaches 11 PSI - if ( 0 == dryBiCartPersistanceStartTime ) + // start the persistence timer once d66 reaches if it drops below 1.5 + if ( 0 == dryBiCartPersistenceStartTime ) { - dryBiCartPersistanceStartTime = getMSTimerCount(); + dryBiCartPersistenceStartTime = getMSTimerCount(); } // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening - if ( TRUE == didTimeout( dryBiCartPersistanceStartTime, DRY_BICART_SUPPLY_VENT_PERSISTENCE_MS ) ) + if ( TRUE == didTimeout( dryBiCartPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) { - //etValveState( D64_VALV, VALVE_STATE_OPEN ); setValveState( D85_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistanceStartTime = 0; + dryBiCartPersistenceStartTime = 0; state = BICARB_SUPPLY_VENT_END_STATE; } } else if ( ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_FILL_VENT_MAX_TIME_MS ) ) ) { setValveState( D85_VALV, VALVE_STATE_CLOSED ); - dryBiCartPersistanceStartTime = 0; + dryBiCartPersistenceStartTime = 0; dryBiCartFillVentTimeOut = TRUE; state = BICARB_SUPPLY_VENT_END_STATE; @@ -1722,7 +1187,7 @@ * The handleBicarbChamberSupplyVentEndState function actuates the vent valve * present in the Bicart assembly. * @details \b Inputs: dryBiCarbSypplyVentStartTime - * @details \b Outputs: none + * @details \b Outputs: bicarbChamberFillRequested * @return the next bicarb chamber start state. *************************************************************************/ static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentEndState(void) @@ -1769,21 +1234,20 @@ setValveState( D34_VALV, VALVE_STATE_CLOSED ); setValveState( D35_VALV, VALVE_STATE_CLOSED ); setValveState( D40_VALV, VALVE_STATE_CLOSED ); + setValveState( D91_VALV, VALVE_STATE_CLOSED ); // open bypass valve - setValveState( D91_VALV, VALVE_STATE_OPEN ); + setValveState( D34_VALV, VALVE_STATE_OPEN ); - // TODO: open DD drain + // open DD drain setValveState( D53_VALV, VALVE_STATE_OPEN ); - // TODO: open iofp drain valve + // open iofp drain valve setValveState( M12_VALV, VALVE_STATE_OPEN ); // Open balancing chamber valves valveControlForBCOpenState(); - - // Run D10 In Open loop mode(max speed 200ml/min) setConcentratePumpTargetSpeed( D10_PUMP, DRAIN_BICART_PUMP_SPEED, DOSING_CONT_VOLUME ); requestConcentratePumpOn( D10_PUMP ); @@ -1806,14 +1270,14 @@ * The handleDryBicartFluidDrainState function initiates the water drain * from dry bicarbonate cartridge. * @details \b Inputs: none - * @details \b Outputs: none + * @details \b Outputs: valve states * @return the next drybicart drain duration check state. *************************************************************************/ static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainState( void ) { DRY_BICART_DRAIN_EXEC_STATE_T state = DRY_BICART_FLUID_DRAIN_STATE; - // Open vent valves and close descaling valve + // Open vent valves and close de-scaling valve setValveState( D80_VALV, VALVE_STATE_OPEN ); setValveState( D81_VALV, VALVE_STATE_CLOSED ); setValveState( D85_VALV, VALVE_STATE_OPEN ); @@ -1857,7 +1321,7 @@ setValveState( D85_VALV, VALVE_STATE_CLOSED ); // close bypass valve - setValveState( D91_VALV, VALVE_STATE_CLOSED ); + setValveState( D34_VALV, VALVE_STATE_CLOSED ); // TODO: close DD drain setValveState( D53_VALV, VALVE_STATE_CLOSED ); @@ -1948,22 +1412,6 @@ data.dryBiCartType = getU32OverrideValue( &dryBiCartType ); data.dryBiCartDrainTimePeriod = dryBiCartDrainTimePeriod; - // TODO: remove after feature testing - memcpy( &data.dryBiCartBicarbMixingControl, &bicarbControlSignals, sizeof( PI_CONTROLLER_SIGNALS_DATA ) ); - // TODO: remove after feature testing - memcpy( &data.dryBiCartAcidMixingControl , &acidControlSignals , sizeof( PI_CONTROLLER_SIGNALS_DATA ) ); - - data.dryBiCartAcidMixVolume = getAcidMixVol(); - data.dryBiCartBicarbMixVolume = getBicarbMixVol(); - - // TODO: remove after feature testing - data.dryBiCartBicarbMixingKPgain = getBicarbKpGainCoefficient(); - // TODO: remove after feature testing - data.dryBiCartBicarbMixingKIgain = getBicarbKiGainCoefficient(); - - data.dryBiCartAcidMixingKPgain = getAcidKpGainCoefficient(); - data.dryBiCartAcidMixingKIgain = getAcidKiGainCoefficient(); - broadcastData( MSG_ID_DD_DRY_BICART_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( DRY_BICART_DATA_T ) ); dryBiCartDataPublicationTimerCounter = 0; @@ -2078,193 +1526,6 @@ /*********************************************************************//** * @brief - * The testDryBiCartAcidMixVolumeOverride function sets the override value - * of the acid concentrate mixing volume. - * @details Inputs: dryBiCartAcidMixVolume - * @details Outputs: dryBiCartAcidMixVolume - * @param message Override message from Dialin which includes the override - * value to override the acid concentrate mixing volume. - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testDryBiCartAcidMixVolumeOverride( MESSAGE_T *message ) -{ - BOOL result = f32Override( message, &dryBiCartAcidMixVolume ); - - return result; -} - -/*********************************************************************//** - * @brief - * The testDryBiCartBicarbMixVolumeOverride function sets the override value - * of the bicarb concentrate mixing volume. - * @details Inputs: dryBiCartBicarbMixVolume - * @details Outputs: dryBiCartBicarbMixVolume - * @param message Override message from Dialin which includes the override - * value to override the bicarb concentrate mixing volume. - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testDryBiCartBicarbMixVolumeOverride( MESSAGE_T *message ) -{ - BOOL result = f32Override( message, &dryBiCartBicarbMixVolume ); - - return result; -} - -/*********************************************************************//** - * @brief - * The testDryBiCartBicarbMixVolControlKpGainOverride function sets the override value - * of the Kp gain coefficient for closed loop bicarb mixing volume control - * @details Inputs: dryBiCartBicarbMixVolumeKpGain - * @details Outputs: dryBiCartBicarbMixVolumeKpGain - * @param message Override message from Dialin which includes the override - * value to override the bicarb concentrate mixing volume kp gain. - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testDryBiCartBicarbMixVolControlKpGainOverride( MESSAGE_T *message ) -{ - BOOL result = f32Override( message, &dryBiCartBicarbMixVolumeKpGain ); - - initializePIController( PI_CONTROLLER_ID_BICARB_VOL, 0.0F,\ - getBicarbKpGainCoefficient(), getBicarbKiGainCoefficient(),\ - MIN_BICARB_VOLUME_ML, MAX_BICARB_VOLUME_ML, FALSE, MIX_NO_FEED_FORWARD ); - - return result; -} - -/*********************************************************************//** - * @brief - * The testDryBiCartBicarbMixVolControlKiGainOverride function sets the override value - * of the Ki gain coefficient for closed loop bicarb concentrate mixing volume control - * @details Inputs: dryBiCartBicarbMixVolumeKiGain - * @details Outputs: dryBiCartBicarbMixVolumeKiGain - * @param message Override message from Dialin which includes the override - * value to override the bicarb concentrate mixing volume ki gain. - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testDryBiCartBicarbMixVolControlKiGainOverride( MESSAGE_T *message ) -{ - BOOL result = f32Override( message, &dryBiCartBicarbMixVolumeKiGain ); - - initializePIController( PI_CONTROLLER_ID_BICARB_VOL, 0.0F,\ - getBicarbKpGainCoefficient(), getBicarbKiGainCoefficient(),\ - MIN_BICARB_VOLUME_ML, MAX_BICARB_VOLUME_ML, FALSE, MIX_NO_FEED_FORWARD ); - - return result; -} - -/*********************************************************************//** - * @brief - * The testDryBiCartAcidMoxVolControlKpGainOverride function sets the override value - * of the Kp gain coefficient for closed loop acid concentrate mixing volume control - * @details Inputs: dryBiCartAcidMixVolumeKpGain - * @details Outputs: dryBiCartAcidMixVolumeKpGain - * @param message Override message from Dialin which includes the override - * value to override the acid concentrate mixing volume kp gain. - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testDryBiCartAcidMixVolControlKpGainOverride( MESSAGE_T *message ) -{ - BOOL result = f32Override( message, &dryBiCartAcidMixVolumeKpGain ); - - initializePIController( PI_CONTROLLER_ID_ACID_VOL, 0.0F, \ - getAcidKpGainCoefficient(), getAcidKiGainCoefficient(),\ - MIN_ACID_VOLUME_ML, MAX_ACID_VOLUME_ML, FALSE, MIX_NO_FEED_FORWARD ); - - return result; -} - -/*********************************************************************//** - * @brief - * The testDryBiCartAcidMixVolControlKiGainOverride function sets the override value - * of the Ki gain coefficient for closed loop acid concentrate mixing volume control - * @details Inputs: dryBiCartAcidMixVolumeKiGain - * @details Outputs: dryBiCartAcidMixVolumeKiGain - * @param message Override message from Dialin which includes the override - * value to override the bicarb concentrate mixing volume ki gain. - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testDryBiCartAcidMixVolControlKiGainOverride( MESSAGE_T *message ) -{ - BOOL result = f32Override( message, &dryBiCartAcidMixVolumeKiGain ); - - initializePIController( PI_CONTROLLER_ID_ACID_VOL, 0.0F, \ - getAcidKpGainCoefficient(), getAcidKiGainCoefficient(),\ - MIN_ACID_VOLUME_ML, MAX_ACID_VOLUME_ML, FALSE, MIX_NO_FEED_FORWARD ); - - return result; -} - -/*********************************************************************//** - * @brief - * The testDryBiCartTargetConductivityOverride function sets the override value - * of target conductivity for closed loop control - * @details Inputs: dryBiCartTargetConductivity - * @details Outputs: dryBiCartTargetConductivity - * @param message Override message from Dialin which includes the override - * value to override the bicarb concentrate target conductivity. - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testDryBiCartTargetConductivityOverride( MESSAGE_T *message ) -{ - BOOL result = f32Override( message, &dryBiCartBicarbTargetConductivity ); - - return result; -} - -/*********************************************************************//** - * @brief - * The testDryBiCartDeltaConductivityOverride function sets the override value - * of delta target conductivity for closed loop control - * @details Inputs: dryBiCartDeltaConductivity - * @details Outputs: dryBiCartDeltaConductivity - * @param message Override message from Dialin which includes the override - * value to override the bicarb concentrate delta target conductivity. - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testDryBiCartDeltaConductivityOverride( MESSAGE_T *message ) -{ - BOOL result = f32Override( message, &dryBiCartBicarbDeltaConductivity ); - - return result; -} - -/*********************************************************************//** - * @brief - * The testDryBiCartAcidBicarbTargetConductivityOverride function sets the override value - * of acid bicarb mix target conductivity for closed loop control - * @details Inputs: dryBiCartAcidBicarbMixTargetConductivity - * @details Outputs: dryBiCartAcidBicarbMixTargetConductivity - * @param message Override message from Dialin which includes the override - * value to override the acid bicarb mix target conductivity. - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testDryBiCartAcidBicarbTargetConductivityOverride( MESSAGE_T *message ) -{ - BOOL result = f32Override( message, &dryBiCartDialysateTargetConductivity ); - - return result; -} - -/*********************************************************************//** - * @brief - * The testDryBiCartAcidBicarbDeltaConductivityOverride function sets the override value - * of delta target conductivity for acid bicarb mix closed loop control - * @details Inputs: dryBiCartDeltaConductivity - * - * @details Outputs: dryBiCartDeltaConductivity - * @param message Override message from Dialin which includes the override - * value to override the acid bicarb mix target delta conductivity. - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testDryBiCartAcidBicarbDeltaConductivityOverride( MESSAGE_T *message ) -{ - BOOL result = f32Override( message, &dryBiCartDialysateDeltaConductivity ); - - return result; -} - -/*********************************************************************//** - * @brief * The testDryBiCartUpperCartPressureOverride function sets the override value * of bicart upper cart pressure * @details Inputs: dryBiCartUpperCartPressure @@ -2297,21 +1558,4 @@ return result; } -/*********************************************************************//** - * @brief - * The testDryBiCartMixControlIntervalOverride function sets the override value - * of mix control interval - * @details Inputs: dryBiCartMixControlInterval - * @details Outputs: dryBiCartMixControlInterval - * @param message Override message from Dialin which includes the override - * value to override the bicart lower pressure. - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testDryBiCartMixControlIntervalOverride( MESSAGE_T *message ) -{ - BOOL result = u32Override( message, &dryBiCartMixControlInterval, 0, BICARB_MIX_CONTROL_INTERVAL ); - - return result; -} - /**@}*/