Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -r46b163d19c65e8c21db7b0247bbb1af0dba1ece5 -rd4bc221d9817b488c2dcd00868386d7036a5c9a1 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 46b163d19c65e8c21db7b0247bbb1af0dba1ece5) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision d4bc221d9817b488c2dcd00868386d7036a5c9a1) @@ -110,6 +110,9 @@ #define DIP_PWM_FROM_ML_PER_MIN(rate) ( ( ( (rate) - 49.121F ) / 684.73F ) + DIP_PWM_ZERO_OFFSET ) /// 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 ) +// Macro converts PWM to estimate flow rate needed to achieve it. +#define DIP_ML_PER_MIN_FROM_PWM(pwm) ( (( pwm - DIP_PWM_ZERO_OFFSET) * 684.73 ) + 49.121 ) + /// Measured dialIn flow is filtered w/ moving average. #define SIZE_OF_ROLLING_AVG 10 @@ -261,10 +264,11 @@ * @details Outputs: targetDialInFlowRate, dialInPumpdirection, dialInPumpPWMDutyCyclePct * @param flowRate new target dialIn flow rate * @param dir new dialIn flow direction - * @param mode new control mode + * @param mode new control mode + * @param pwm PWM duty cycle to set pump controller to (optional for open loop) * @return TRUE if new flow rate & dir are set, FALSE if not *************************************************************************/ -BOOL setDialInPumpTargetFlowRate( U32 flowRate, MOTOR_DIR_T dir, PUMP_CONTROL_MODE_T mode ) +BOOL setDialInPumpTargetFlowRate( U32 flowRate, MOTOR_DIR_T dir, PUMP_CONTROL_MODE_T mode, F32 pwm ) { BOOL result = FALSE; @@ -274,7 +278,7 @@ S32 dirFlowRate = ( dir == MOTOR_DIR_FORWARD ? (S32)flowRate : (S32)flowRate * -1 ); // Don't interrupt pump control unless rate or mode is changing - if ( ( dirFlowRate != targetDialInFlowRate ) || ( mode != dialInPumpControlMode ) ) + if ( ( dirFlowRate != targetDialInFlowRate ) || ( mode != dialInPumpControlMode ) || ( fabs(pwm) > NEARLY_ZERO ) ) { BOOL isFlowRateInRange = ( flowRate <= MAX_DIAL_IN_FLOW_RATE ? TRUE : FALSE ); @@ -292,8 +296,15 @@ targetDialInFlowRate = dirFlowRate; dialInPumpDirection = dir; dialInPumpControlMode = 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 - dialInPumpPWMDutyCyclePct = ( 0 == flowRate ? DIP_PWM_ZERO_OFFSET : DIP_PWM_FROM_ML_PER_MIN( (F32)flowRate ) ); + // 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 + if ( PUMP_CONTROL_MODE_CLOSED_LOOP == mode || fabs(pwm) < NEARLY_ZERO ) + { + dialInPumpPWMDutyCyclePct = ( 0 == flowRate ? DIP_PWM_ZERO_OFFSET : DIP_PWM_FROM_ML_PER_MIN( (F32)flowRate ) ); + } + else // Dialin command to open loop w/ set PWM duty cycle + { + dialInPumpPWMDutyCyclePct = pwm; + } switch ( dialInPumpState ) { @@ -403,7 +414,7 @@ { dipStopAtHomePosition = TRUE; dipHomeStartTime = getMSTimerCount(); - result = setDialInPumpTargetFlowRate( DIP_HOME_RATE, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + result = setDialInPumpTargetFlowRate( DIP_HOME_RATE, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP, 0.0F ); } return result; @@ -1407,7 +1418,7 @@ } else { - result = setDialInPumpTargetFlowRate( abs(value), dir, (PUMP_CONTROL_MODE_T)ctrlMode ); + result = setDialInPumpTargetFlowRate( abs(value), dir, (PUMP_CONTROL_MODE_T)ctrlMode, 0.0F ); } } } @@ -1638,6 +1649,27 @@ } return result; -} +} +/*********************************************************************//** + * @brief + * The testSetDialInPumpTargetDutyCycle function resets the override of the + * measured dialIn pump motor current. + * @details Inputs: none + * @details Outputs: adcDialInPumpMCCurrentmA + * @return TRUE if reset successful, FALSE if not + *************************************************************************/ +BOOL testSetDialInPumpTargetDutyCycle( F32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + setDialInPumpTargetFlowRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP, value ); + result = TRUE; + } + + return result; +} + /**@}*/