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;