Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -re5d24f913e4f29d61c813cd1446ac22a368815f2 -r3981c29f7244ab2c4e6b89624e34663303202c77 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision e5d24f913e4f29d61c813cd1446ac22a368815f2) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 3981c29f7244ab2c4e6b89624e34663303202c77) @@ -110,7 +110,7 @@ #define DIP_PWM_ZERO_OFFSET 0.1F ///< 10% PWM duty cycle = zero speed. /// Conversion from PWM duty cycle % to commanded pump motor speed. PWM range is 10% to 90%. RPM range is 0 to 3200. 3200 / 0.8 = 4000. -#define DIP_PWM_TO_MOTOR_SPEED_RPM(pwm) ( ((pwm) - DIP_PWM_ZERO_OFFSET) * 4000.0F ) +#define DIP_PWM_TO_MOTOR_SPEED_RPM(pwm,dir) ( ( ((pwm) - DIP_PWM_ZERO_OFFSET) * 4000.0F ) * ( dir == MOTOR_DIR_FORWARD ? 1.0F : -1.0F ) ) /// Conversion from pump motor speed to PWM duty cycle. #define DIP_MOTOR_SPEED_RPM_TO_PWM(rpm) ( ( rpm / 4000.0F ) + 0.1 ) // Macro converts PWM to estimate flow rate needed to achieve it. TODO - this macro does not reverse the function that estimates PWM from target flow rate - and it should @@ -1273,14 +1273,14 @@ * 2. while pump is controlling, measured motor speed should be within allowed range of commanded speed. * 3. measured motor speed should be within allowed range of measured rotor speed. * All 3 checks have a persistence time that must be met before an alarm is triggered. - * @details Inputs: targetDialInFlowRate, dialInPumpSpeedRPM, dialInPumpRotorSpeedRPM - * @details Outputs: alarm(s) may be triggered + * @details Inputs: targetDialInFlowRate, dialInPumpState, dialInPumpPWMDutyCyclePctSet, dialInPumpDirectionSet + * @details Outputs: errorDialInMotorOffPersistTimerCtr, alarm(s) may be triggered * @return none *************************************************************************/ static void checkDialInPumpSpeeds( void ) { F32 measMotorSpeed = getMeasuredDialInPumpSpeed(); - F32 measMCMotorSpeed = fabs( getMeasuredDialInPumpMCSpeed() ); + F32 measMCMotorSpeed = getMeasuredDialInPumpMCSpeed(); // Check for pump running while commanded off if ( 0 == targetDialInFlowRate ) @@ -1311,11 +1311,11 @@ // Checks that only occur when pump is running (and beyond ramp). if ( DIAL_IN_PUMP_CONTROL_TO_TARGET_STATE == dialInPumpState ) { - F32 cmdMotorSpeed = DIP_PWM_TO_MOTOR_SPEED_RPM( dialInPumpPWMDutyCyclePctSet ); + F32 cmdMotorSpeed = DIP_PWM_TO_MOTOR_SPEED_RPM( dialInPumpPWMDutyCyclePctSet, dialInPumpDirectionSet ); F32 deltaMotorSpeed = fabs( measMotorSpeed - cmdMotorSpeed ); F32 deltaMCMotorSpeed = fabs( measMCMotorSpeed - cmdMotorSpeed ); F32 measRotorSpeed = fabs( getMeasuredDialInPumpRotorSpeed() ); - F32 measMotorSpeedInRotorRPM = measMotorSpeed / DIP_GEAR_RATIO; + F32 measMotorSpeedInRotorRPM = fabs( measMotorSpeed / DIP_GEAR_RATIO ); F32 deltaRotorSpeed = fabs( measRotorSpeed - measMotorSpeedInRotorRPM ); F32 measMotorSpeedDeltaPct = fabs( deltaRotorSpeed / measMotorSpeedInRotorRPM );