Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -r9ff57b5ab7490ee5bbc2c51b25f738ee6c569ec1 -r4a80b214d221c1f64feb215d828a10d8fddbaf4d --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 9ff57b5ab7490ee5bbc2c51b25f738ee6c569ec1) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 4a80b214d221c1f64feb215d828a10d8fddbaf4d) @@ -20,6 +20,7 @@ #include "ConcentratePumps.h" #include "DialysatePumps.h" #include "FpgaDD.h" +#include "Heaters.h" #include "ModeStandby.h" #include "Messaging.h" #include "OperationModes.h" @@ -63,6 +64,7 @@ static BOOL balanceChamberSwitchingOnly; ///< Balancing chamber switching without any pressure check and dosing delivery. static OVERRIDE_F32_T acidDoseVolume; ///< Acid concentrate volume in ml ( overrideable). static OVERRIDE_F32_T bicarbDoseVolume; ///< Bicarb concentrate volume in ml ( overrideable). +static F32 lastTdDialysateFlowrate; ///< Previous TD dialysate flow rate // ********** private function prototypes ********** @@ -107,6 +109,7 @@ isBalChamberFillInProgress = FALSE; currentBalChamberSwitchingCounter = 0; isPressureStalbilizedDuringFill = FALSE; + lastTdDialysateFlowrate = 0.0F; balChamberDataPublicationTimerCounter = 0; } @@ -134,18 +137,29 @@ *************************************************************************/ void updateBalChamberSwitchingPeriod( void ) { - // update the balancing chamber switching frequency - balChamberSwitchingFreq.data = getTDDialysateFlowrate() / BAL_CHAMBER_FILL_VOLUME_ML; + F32 tdDialysateFlowrate = getTDDialysateFlowrate(); - //update the switching period in task interval for balancing chamber fill timeout check - balChamberSwitchingPeriod = (U32)( (F32)SEC_PER_MIN / getBalChamberSwitchingFreq() * ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); + if ( lastTdDialysateFlowrate != tdDialysateFlowrate ) + { + // update the balancing chamber switching frequency + balChamberSwitchingFreq.data = tdDialysateFlowrate / BAL_CHAMBER_FILL_VOLUME_ML; - // finish the balancing chamber fill 50 ms prior completing the regular cycle time. - balChamberSwitchingPeriod -= 1; + //update the switching period in task interval for balancing chamber fill timeout check + balChamberSwitchingPeriod = (U32)( (F32)SEC_PER_MIN / getBalChamberSwitchingFreq() * ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); - //Testing - balChamberValveClosePeriod = balChamberSwitchingPeriod; - balChamberValveClosePeriod -= 1; // Close valves prior 50 msecond for testing + // finish the balancing chamber fill 50 ms prior completing the regular cycle time. + balChamberSwitchingPeriod -= 1; + + //Update last td dialysate flow rate + lastTdDialysateFlowrate = tdDialysateFlowrate; + + //Update heater control on dialysate flow change + signalHeaterControlOnQDUpdate( D5_HEAT ); + + //Testing + balChamberValveClosePeriod = balChamberSwitchingPeriod; + balChamberValveClosePeriod -= 1; // Close valves prior 50 msecond for testing + } } /*********************************************************************//** Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -r363b26b9ab427b7e39e505425c1b15e0584669cb -r4a80b214d221c1f64feb215d828a10d8fddbaf4d --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 363b26b9ab427b7e39e505425c1b15e0584669cb) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 4a80b214d221c1f64feb215d828a10d8fddbaf4d) @@ -51,8 +51,8 @@ #define HEATERS_ZERO_EFFICIENCY 0.0F ///< Zero heater efficiency #define D5_HEAT_TX_INIT_FEED_FORWARD 0.0F ///< Initial Feed forward term for heater control -#define D5_HEAT_TX_P_COEFFICIENT 0.015F ///< P Term for AC primary heater control during treatment mode. -#define D5_HEAT_TX_I_COEFFICIENT 0.0021F ///< I Term for AC primary heater control during treatment mode. +#define D5_HEAT_TX_P_COEFFICIENT 0.050F ///< P Term for AC primary heater control during treatment mode. +#define D5_HEAT_TX_I_COEFFICIENT 0.015F ///< I Term for AC primary heater control during treatment mode. #define D45_HEAT_P_COEFFICIENT 0.20F ///< P Term for trimmer heater control. #define D45_HEAT_I_COEFFICIENT 0.05F ///< I Term for trimmer heater control. @@ -119,6 +119,7 @@ static const F32 WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES = 4184.0F / (F32)SEC_PER_MIN; ///< Water specific heat in J/KgC / 60. static OVERRIDE_U32_T heatersDataPublishInterval = { HEATERS_DATA_PUBLISH_INTERVAL, HEATERS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Heaters data publish time interval. static F32 convertDC; ///< AC Heater converted duty cycle +static F32 lastDialTargetTemperatureSet; ///< last dialysate target temperature set for heater control static BOOL startupHeaterControl; ///< First time control with the energy equation. //For testing @@ -180,6 +181,7 @@ heatersStatus[ D5_HEAT ].controlIntervalCounter = D5_HEAT_CONTROL_INTERVAL_START_COUNT; heatersStatus[ D45_HEAT ].controlIntervalCounter = 0; startupHeaterControl = TRUE; + lastDialTargetTemperatureSet = 0.0F; for ( heater = DD_HEATERS_FIRST; heater < NUM_OF_DD_HEATERS; heater++ ) { @@ -241,17 +243,25 @@ { BOOL result = FALSE; - if( heater < NUM_OF_DD_HEATERS ) + if ( heater < NUM_OF_DD_HEATERS ) { // Assume the target temperature has not changed heatersStatus[ heater ].hasTargetTempChanged = FALSE; // Check if the requested temperature is within the allowed range - if ( ( targetTemperature >= HEATER_TARGET_TEMPERATURE_MIN ) && ( targetTemperature <= HEATER_TARGET_TEMPERATURE_MAX ) ) + if ( ( ( targetTemperature >= HEATER_TARGET_TEMPERATURE_MIN ) && ( targetTemperature <= HEATER_TARGET_TEMPERATURE_MAX ) ) && + ( lastDialTargetTemperatureSet != targetTemperature ) ) { targetTempC[ heater ].data = targetTemperature; heatersStatus[ heater ].hasTargetTempChanged = TRUE; result = TRUE; + lastDialTargetTemperatureSet = targetTemperature; + + if ( D5_HEAT == heater ) + { + startupHeaterControl = TRUE; + } + } } else @@ -372,12 +382,12 @@ heatersStatus[ heater ].heaterOnState = FALSE; control[ heater ].data = HEATERS_MIN_DUTY_CYCLE; heatersStatus[ heater ].state = HEATER_EXEC_STATE_OFF; - startupHeaterControl = TRUE; //Update control interval counter if ( D5_HEAT == heater ) { heatersStatus[ D5_HEAT ].controlIntervalCounter = D5_HEAT_CONTROL_INTERVAL_START_COUNT; + startupHeaterControl = TRUE; } else { @@ -656,14 +666,14 @@ ctrl = runPIController( PI_CONTROLLER_ID_D45_HEAT, targetTemperature, measuredTemperature ); control[ heater ].data = ctrl; -#ifdef __HEATERS_DEBUG__ - U32 i; - - for ( i = 0; i < NUM_OF_CONTROLLER_SIGNAL; i++ ) - { - pIControlSignal[ i ] = getPIControllerSignals( PI_CONTROLLER_ID_D45_HEAT, (PI_CONTROLLER_SIGNALS_ID)i ); - } -#endif +//#ifdef __HEATERS_DEBUG__ +// U32 i; +// +// for ( i = 0; i < NUM_OF_CONTROLLER_SIGNAL; i++ ) +// { +// pIControlSignal[ i ] = getPIControllerSignals( PI_CONTROLLER_ID_D45_HEAT, (PI_CONTROLLER_SIGNALS_ID)i ); +// } +//#endif } heatersStatus[ heater ].hasTargetTempChanged = FALSE; Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -r9ff57b5ab7490ee5bbc2c51b25f738ee6c569ec1 -r4a80b214d221c1f64feb215d828a10d8fddbaf4d --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 9ff57b5ab7490ee5bbc2c51b25f738ee6c569ec1) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 4a80b214d221c1f64feb215d828a10d8fddbaf4d) @@ -44,7 +44,7 @@ #define GEN_DIALYSATE_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the gen dialysate mode data published. //Testing -#define DELAY_BYPASS_STATE_AT_START_UP ( 1 * MS_PER_SECOND ) ///< Provide a bypass state start up delay to stabilize pump speed etc., +#define DELAY_BYPASS_STATE_AT_START_UP ( 3 * MS_PER_SECOND ) ///< Provide a bypass state start up delay to stabilize pump speed etc., /// Payload record structure for Gen dialysate execution state set request typedef struct { @@ -60,7 +60,6 @@ static OVERRIDE_U32_T pendingStopDDGenDialRequest; ///< Flag indicating TD has requested DD stop the generate dialysate (Overridable). static U32 genDialysateDataPublicationTimerCounter; ///< Used to schedule generate dialysate data publication to CAN bus. static OVERRIDE_U32_T genDialysateDataPublishInterval; ///< Generate dialysate mode data publish interval. -static F32 lastDialTargetTemperatureSet; ///< last dialysate target temperature set for heater control static BOOL isTreatmentParamUpdated; ///< To indicate change in treatment parameters //Testing static U32 bypassStateDelayStartTimeMS; ///< Delay balancing chamber switching for a second to preapre pump steady state. @@ -107,7 +106,6 @@ genDialysateDataPublishInterval.ovInitData = 0; genDialysateDataPublishInterval.override = OVERRIDE_RESET; genDialysateDataPublicationTimerCounter = 0; - lastDialTargetTemperatureSet = 0.0F; isTreatmentParamUpdated = FALSE; //Testing bypassStateDelayStartTimeMS = 0; @@ -184,7 +182,6 @@ // Turn on the primary heater setHeaterTargetTemperature( D5_HEAT, getGenDialysateTargetTemperature() ); startHeater( D5_HEAT ); - lastDialTargetTemperatureSet = getGenDialysateTargetTemperature(); setValveState( D14_VALV, VALVE_STATE_OPEN ); //Testing : Enable close loop once testing is complete @@ -206,6 +203,9 @@ case DD_GEND_DIALYSATE_DELIVERY_STATE: //Previous state setValveState( M4_VALV, VALVE_STATE_OPEN ); + // Get the target temperature from TD + targetHydChamberFluidTemp.data = getTDTargetDialysateTemperature(); + setHeaterTargetTemperature( D5_HEAT, getGenDialysateTargetTemperature() ); startHeater( D5_HEAT ); setValveState( D14_VALV, VALVE_STATE_OPEN ); //setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM, FALSE ); @@ -334,25 +334,12 @@ //Make sure Water Inlet Valve is open setValveState( M4_VALV, VALVE_STATE_OPEN ); - // Get the target temperature from TD - targetHydChamberFluidTemp.data = getTDTargetDialysateTemperature(); - // High level is met if ( LEVEL_STATE_HIGH == floaterLevel ) { - // Get the target dialysate temperature - F32 targetTemperature = getGenDialysateTargetTemperature(); - //turn off inlet water valve setValveState( D3_VALV, VALVE_STATE_CLOSED ); - if ( lastDialTargetTemperatureSet != targetTemperature ) - { - // Update the target temperature for heater control - setHeaterTargetTemperature( D5_HEAT, targetTemperature ); - lastDialTargetTemperatureSet = targetTemperature; - } - // Water level reached high. result = TRUE; } @@ -527,9 +514,14 @@ // Update any dynamic treatment parameter changes if ( TRUE == isTreatmentParamUpdated ) { - // Update the Balancing chamber switching rate based on dialysis rate + // Update the balancing chamber switching rate based on dialysis rate updateBalChamberSwitchingPeriod(); + // Get the target temperature from TD + targetHydChamberFluidTemp.data = getTDTargetDialysateTemperature(); + // Update the target temperature for heater control + setHeaterTargetTemperature( D5_HEAT, getGenDialysateTargetTemperature() ); + //TODO: update others parameters setting as needed. //reset the flag