Index: firmware/App/Controllers/DialOutFlow.c =================================================================== diff -u -r69ed3f91919e50b68ea448a70db81456fb4946a0 -re190a7eb5fb36d4a0c42e9db709571db3037d39d --- firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision 69ed3f91919e50b68ea448a70db81456fb4946a0) +++ firmware/App/Controllers/DialOutFlow.c (.../DialOutFlow.c) (revision e190a7eb5fb36d4a0c42e9db709571db3037d39d) @@ -7,8 +7,8 @@ * * @file DialOutFlow.c * -* @author (last) Bill Bracken -* @date (last) 29-Jun-2022 +* @author (last) Dara Navaei +* @date (last) 01-Sep-2022 * * @author (original) Sean * @date (original) 24-Jan-2020 @@ -82,8 +82,6 @@ static const U32 DOP_OFF_ERROR_PERSIST = ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); /// Persist time (task intervals) motor speed error condition. static const U32 DOP_MOTOR_SPEED_ERROR_PERSIST = ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); -/// Persist time (task intervals) rotor speed error condition. -static const U32 DOP_ROTOR_SPEED_ERROR_PERSIST = ((12 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); /// Persist time (task intervals) pump direction error condition. static const U32 DOP_DIRECTION_ERROR_PERSIST = (250 / TASK_PRIORITY_INTERVAL); @@ -109,7 +107,7 @@ /// Conversion from PWM duty cycle % to commanded pump motor speed. #define DOP_PWM_TO_MOTOR_SPEED_RPM(pwm) ( ( ( pwm ) - DOP_PWM_ZERO_OFFSET) * 4000.0F ) /// Macro converts a PWM to an estimated flow rate. -#define DOP_ML_PER_MIN_FROM_PWM(pwm) ( ( ( pwm - DOP_PWM_ZERO_OFFSET - 0.0972 ) / 0.0009 ) ) +#define DOP_ML_PER_MIN_FROM_PWM(pwm) ( ( ( pwm - DOP_PWM_ZERO_OFFSET ) - 0.0972 ) / 0.0009 ) #define PUMP_DIR_ERROR_COUNT_MASK 0x3F ///< Bit mask for pump direction error counter. #define DOP_MIN_DIR_CHECK_SPEED_RPM 10.0F ///< Minimum motor speed before we check pump direction. @@ -295,7 +293,7 @@ dialOutPumpDirection = dir; 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 = DOP_PWM_FROM_ML_PER_MIN(pwmDC); switch ( dialOutPumpState ) { @@ -1047,7 +1045,7 @@ F32 cmdMotorSpeed = DOP_PWM_TO_MOTOR_SPEED_RPM( dialOutPumpPWMDutyCyclePctSet ); F32 deltaMotorSpeed = fabs( measMotorSpeed - cmdMotorSpeed ); F32 deltaMCMotorSpeed = fabs( measMCMotorSpeed - cmdMotorSpeed ); - F32 measRotorSpeed = getMeasuredDialOutPumpRotorSpeed(); + F32 measRotorSpeed = fabs( getMeasuredDialOutPumpRotorSpeed() ); F32 measMotorSpeedInRotorRPM = measMotorSpeed / DOP_GEAR_RATIO; F32 deltaRotorSpeed = fabs( measRotorSpeed - measMotorSpeedInRotorRPM ); @@ -1072,7 +1070,7 @@ // Check measured rotor speed vs. measured motor speed while controlling to target if ( deltaRotorSpeed > DOP_MAX_ROTOR_VS_MOTOR_DIFF_RPM ) { - if ( ++errorDialOutRotorSpeedPersistTimerCtr >= DOP_ROTOR_SPEED_ERROR_PERSIST ) + if ( ++errorDialOutRotorSpeedPersistTimerCtr >= ( getPumpRotorErrorPersistTime( measMotorSpeed, DOP_GEAR_RATIO ) / TASK_PRIORITY_INTERVAL ) ) { #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_PUMP_SPEED_CHECKS ) != SW_CONFIG_ENABLE_VALUE ) @@ -1656,10 +1654,16 @@ BOOL testSetDialOutPumpTargetDutyCycle( F32 value ) { BOOL result = FALSE; + F32 targetPWM = DOP_ML_PER_MIN_FROM_PWM(value) ; if ( TRUE == isTestingActivated() ) { - setDialOutPumpTargetRate( (S32)DOP_ML_PER_MIN_FROM_PWM( value ), MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + // currently conversion can create negative values with values <= 10%. + if ( targetPWM < 0 ) + { + targetPWM = 0; + } + setDialOutPumpTargetRate( (U32)targetPWM, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); result = TRUE; }