Index: firmware/App/Controllers/DialOutFlow.c =================================================================== diff -u -re283a8f2f25dea73d84f87ac346c23e7b3059531 -rbd1a18097721b1e331761ad88aca0cc2ecb85e1f --- firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision e283a8f2f25dea73d84f87ac346c23e7b3059531) +++ firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision bd1a18097721b1e331761ad88aca0cc2ecb85e1f) @@ -256,6 +256,7 @@ dopMeasuredRate = 0.0; ufMeasuredRate = 0.0; dopRateCorrectionOffset = 0.0; + offsetPWMDutyCyclePct = 0.0; resetDialOutFlowMovingAverage(); initTimeWindowedCount( TIME_WINDOWED_COUNT_DOP_COMMUTATION_ERROR, DOP_COMMUTATION_ERROR_MAX_CNT, DOP_COMMUTATION_ERROR_TIME_WIN_MS ); @@ -279,7 +280,7 @@ // Direction change while pump is running is not allowed if ( ( FALSE == isDialOutPumpOn ) || ( 0 == flowRate ) || ( dir == dialOutPumpDirectionSet ) ) { - F32 pwmDC = getDialInPumpPWMDutyCyclePct( TRUE ); + F32 pwmDC = getDialInPumpPWMDutyCyclePct( TRUE ); // start initial DPo PWM duty cycle % estimate at whatever DPi PWM duty cycle % was set to. if ( mode != PUMP_CONTROL_MODE_CLOSED_LOOP ) { @@ -289,9 +290,10 @@ { // if rate correction offset not yet set, set it based on target dialysate flow rate if ( fabs( dopRateCorrectionOffset ) < NEARLY_ZERO ) { // set initial estimate for rate correction offset - dopRateCorrectionOffset = (F32)getTargetDialInFlowRate() * DOP_RATE_CORRECTION_SCALAR + DOP_RATE_CORRECTION_OFFSET; - // adjust initial pwm duty cycle % per rate correction offset - pwmDC -= ( ( dopRateCorrectionOffset / RPM_2_ML_MIN_CONVERSION ) / DOP_100_PCT_PWM_RPM_RANGE ); + dopRateCorrectionOffset = ( (F32)getTargetDialInFlowRate() + getCurrentUFSetRate() ) * DOP_RATE_CORRECTION_SCALAR + DOP_RATE_CORRECTION_OFFSET; + // adjust initial pwm duty cycle % estimate per set UF rate and rate correction offset + offsetPWMDutyCyclePct = ( ( ( getCurrentUFSetRate() - dopRateCorrectionOffset ) / RPM_2_ML_MIN_CONVERSION ) / DOP_100_PCT_PWM_RPM_RANGE ); + pwmDC += offsetPWMDutyCyclePct; } } // Don't interrupt pump control unless rate or mode is changing @@ -320,6 +322,7 @@ dialOutPumpControlMode = mode; // Set PWM duty cycle target to an estimated initial target to ramp to based on target flow rate - then we will control to flow when ramp completed dialOutPumpPWMDutyCyclePct = pwmDC; + dialOutPumpPWMDutyCyclePct = RANGE( dialOutPumpPWMDutyCyclePct, MIN_DIAL_OUT_PUMP_PWM_DUTY_CYCLE, MAX_DIAL_OUT_PUMP_PWM_DUTY_CYCLE ); switch ( dialOutPumpState ) { @@ -486,7 +489,6 @@ flowReadingsIdx = 0; flowReadingsCount = 0; flowReadingsTotal = 0.0; - offsetPWMDutyCyclePct = 0.0; } /*********************************************************************//**