Index: firmware/App/Controllers/DialOutFlow.c =================================================================== diff -u -rb660c59e56cd7cd0123206e918aacc4225cca94b -rbb648110d33fb859beed67fabc43f7e9614fc00a --- firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision b660c59e56cd7cd0123206e918aacc4225cca94b) +++ firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision bb648110d33fb859beed67fabc43f7e9614fc00a) @@ -54,6 +54,7 @@ #define MAX_DIAL_OUT_FLOW_RATE 700 ///< Maximum dialysate outlet pump flow rate in mL/min. #define MIN_DIAL_OUT_FLOW_RATE 100 ///< Minimum dialysate outlet pump flow rate in mL/min. +#define MAX_DIAL_OUT_PUMP_PWM_CHANGE 0.05F ///< Maximum duty cycle change allowed. #define MAX_DIAL_OUT_PUMP_PWM_STEP_UP_CHANGE 0.01064F ///< Maximum duty cycle change when ramping up. #define MAX_DIAL_OUT_PUMP_PWM_STEP_DN_CHANGE 0.016F ///< Maximum duty cycle change when ramping down. #define MAX_DIAL_OUT_PUMP_PWM_DUTY_CYCLE 0.90F ///< Controller will error if PWM duty cycle > 90%, so set max to 89%. @@ -846,12 +847,32 @@ offsetPWMDutyCyclePct += ( ufrErr * P_UF ); // Add PWM offset to DPi PWM mirror for our new DPo PWM - dialOutPumpPWMDutyCyclePctSet = getDialInPumpPWMDutyCyclePct( FALSE ) + offsetPWMDutyCyclePct; + dialOutPumpPWMDutyCyclePct = getDialInPumpPWMDutyCyclePct( FALSE ) + offsetPWMDutyCyclePct; // Limit PWM range - dialOutPumpPWMDutyCyclePctSet = MIN( dialOutPumpPWMDutyCyclePctSet, MAX_DIAL_OUT_PUMP_PWM_DUTY_CYCLE ); - dialOutPumpPWMDutyCyclePctSet = MAX( dialOutPumpPWMDutyCyclePctSet, MIN_DIAL_OUT_PUMP_PWM_DUTY_CYCLE ); - // Apply new PWM to DPo pump - setDialOutPumpControlSignalPWM( dialOutPumpPWMDutyCyclePctSet ); + dialOutPumpPWMDutyCyclePct = MIN( dialOutPumpPWMDutyCyclePct, MAX_DIAL_OUT_PUMP_PWM_DUTY_CYCLE ); + dialOutPumpPWMDutyCyclePct = MAX( dialOutPumpPWMDutyCyclePct, MIN_DIAL_OUT_PUMP_PWM_DUTY_CYCLE ); + + // change in PWM duty cycle should not cross the defined threshold value, if so, step changes should be applied + // to have gradual increase/decrease in PWM duty cycle. This is to avoid few undefined scenarios where sudden ramp down/up seen + // TODO : Need to define the threshold value, for now up to 5% change is allowed?? + if( fabs( dialOutPumpPWMDutyCyclePct - dialOutPumpPWMDutyCyclePctSet ) > MAX_DIAL_OUT_PUMP_PWM_CHANGE ) + { + if ( dialOutPumpPWMDutyCyclePctSet > dialOutPumpPWMDutyCyclePct ) + { + dialOutPumpState = DIAL_OUT_PUMP_RAMPING_DOWN_STATE; + } + else + { + dialOutPumpState = DIAL_OUT_PUMP_RAMPING_UP_STATE; + } + } + else + { + dialOutPumpPWMDutyCyclePctSet = dialOutPumpPWMDutyCyclePct; + // Apply new PWM to DPo pump + setDialOutPumpControlSignalPWM( dialOutPumpPWMDutyCyclePctSet ); + } + } } @@ -957,6 +978,7 @@ dialOutBroadCastVariables.ufCalcRate = ufMeasuredRate; dialOutBroadCastVariables.rotorHall = ( hallSensor > 0 ? 0 : 1 ); // 1=home, 0=not home dialOutBroadCastVariables.currentSetUFRate = getCurrentUFSetRate(); + dialOutBroadCastVariables.dialOutPumpState = (U32)dialOutPumpState; broadcastData( MSG_ID_DIALYSATE_OUT_FLOW_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&dialOutBroadCastVariables, sizeof( DIAL_OUT_FLOW_DATA_T ) ); dialOutFlowDataPublicationTimerCounter = 0; Index: firmware/App/Controllers/DialOutFlow.h =================================================================== diff -u -rff9c8ebdcf0ee2188346cfaa27ff5c2027dcd0a8 -rbb648110d33fb859beed67fabc43f7e9614fc00a --- firmware/App/Controllers/DialOutFlow.h (.../DialOutFlow.h) (revision ff9c8ebdcf0ee2188346cfaa27ff5c2027dcd0a8) +++ firmware/App/Controllers/DialOutFlow.h (.../DialOutFlow.h) (revision bb648110d33fb859beed67fabc43f7e9614fc00a) @@ -49,6 +49,7 @@ F32 ufCalcRate; ///< Latest calculated UF rate. U32 rotorHall; ///< Latest rotor hall sensor state (1=home, 0=not home) F32 currentSetUFRate; ///< Latest UF set rate. + U32 dialOutPumpState; ///< Current state of execution } DIAL_OUT_FLOW_DATA_T; #pragma pack(pop) Index: firmware/App/Modes/ModeTreatment.c =================================================================== diff -u -rf47dd3b39499eee03d3e93236335c087b4ad71fb -rbb648110d33fb859beed67fabc43f7e9614fc00a --- firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision f47dd3b39499eee03d3e93236335c087b4ad71fb) +++ firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision bb648110d33fb859beed67fabc43f7e9614fc00a) @@ -1283,16 +1283,17 @@ result = TRUE; sendTreatmentLogEventData( BLOOD_FLOW_RATE_CHANGE_EVENT, getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ), bloodRate ); sendTreatmentLogEventData( DIALYSATE_FLOW_RATE_CHANGE_EVENT, getTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW ), dialRate ); + // when one of the parameters change from the previous value, then allow to update new rates, otherwise ignore it. if ( ( bloodRate != (U32)getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ) ) || ( dialRate != (U32)getTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW ) ) ) { signalInitiatePressureStabilization( USE_NORMAL_STABILIZATION_PERIOD ); + // Set to new rates + setTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW, bloodRate ); + setTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW, dialRate ); + setDialysisParams( getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ), getTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW ), + presMaxUFVolumeML, presUFRate ); } - // Set to new rates - setTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW, bloodRate ); - setTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW, dialRate ); - setDialysisParams( getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ), getTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW ), - presMaxUFVolumeML, presUFRate ); } else {