Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -rac6fc5b74e15c8925e4579c847ddfca8e1e361ad -rdecd87eaf64e68ee4690c046f48ae47977928729 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision ac6fc5b74e15c8925e4579c847ddfca8e1e361ad) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision decd87eaf64e68ee4690c046f48ae47977928729) @@ -168,15 +168,16 @@ // ********** private data ********** -static DIAL_IN_PUMP_STATE_T dialInPumpState = DIAL_IN_PUMP_OFF_STATE; ///< Current state of dialIn flow controller state machine -static U32 dialInFlowDataPublicationTimerCounter; ///< Used to schedule dialIn flow data publication to CAN bus -static BOOL isDialInPumpOn = FALSE; ///< DialIn pump is currently running -static F32 dialInPumpPWMDutyCyclePct = 0.0; ///< Initial dialIn pump PWM duty cycle -static F32 dialInPumpPWMDutyCyclePctSet = 0.0; ///< Currently set dialIn pump PWM duty cycle -static MOTOR_DIR_T dialInPumpDirection = MOTOR_DIR_FORWARD; ///< Requested dialysate flow direction -static MOTOR_DIR_T dialInPumpDirectionSet = MOTOR_DIR_FORWARD; ///< Currently set dialysate flow direction -static PUMP_CONTROL_MODE_T dialInPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< Requested dialIn pump control mode. -static PUMP_CONTROL_MODE_T dialInPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP;///< Currently set dialIn pump control mode. +static DIAL_IN_PUMP_STATE_T dialInPumpState = DIAL_IN_PUMP_OFF_STATE; ///< Current state of dialIn flow controller state machine +static U32 dialInFlowDataPublicationTimerCounter; ///< Used to schedule dialIn flow data publication to CAN bus +static BOOL isDialInPumpOn = FALSE; ///< DialIn pump is currently running +static F32 dialInPumpPWMDutyCyclePct = 0.0; ///< Initial dialIn pump PWM duty cycle +static F32 dialInPumpPWMDutyCyclePctSet = 0.0; ///< Currently set dialIn pump PWM duty cycle +static MOTOR_DIR_T dialInPumpDirection = MOTOR_DIR_FORWARD; ///< Requested dialysate flow direction +static MOTOR_DIR_T dialInPumpDirectionSet = MOTOR_DIR_FORWARD; ///< Currently set dialysate flow direction +static PUMP_CONTROL_MODE_T dialInPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< Requested dialIn pump control mode. +static PUMP_CONTROL_MODE_T dialInPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< Currently set dialIn pump control mode. +static BOOL isTestPWMSet = FALSE; ///< Using PWM to set the rate instead of target flow. /// Interval (in ms) at which to publish dialIn flow data to CAN bus static OVERRIDE_U32_T dialInFlowDataPublishInterval = { DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, 0 }; @@ -238,6 +239,7 @@ static void checkDialInPumpFlowRate( void ); static F32 calcDialInFlow( void ); static F32 dialysateInPumpPWMFromTargetFlowRate( F32 QdTarget ); +static BOOL testSetDialInPumpWithPWM( F32 pwm ); /*********************************************************************//** * @brief @@ -251,7 +253,7 @@ U32 i; dialInFlowDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; - + isTestPWMSet = FALSE; signalDialInPumpHardStop(); setDialInPumpDirection( MOTOR_DIR_FORWARD ); @@ -283,7 +285,8 @@ * The setDialInPumpTargetFlowRate function sets a new target flow rate and * pump direction. * @details Inputs: isDialInPumpOn, dialInPumpDirectionSet - * @details Outputs: targetDialInFlowRate, dialInPumpdirection, dialInPumpPWMDutyCyclePct + * @details Outputs: targetDialInFlowRate, dialInPumpdirection, + * dialInPumpPWMDutyCyclePct, isTestPWMSet * @param flowRate new target dialIn flow rate * @param dir new dialIn flow direction * @param mode new control mode @@ -294,7 +297,7 @@ BOOL result = FALSE; // Direction change while pump is running is not allowed - if ( ( FALSE == isDialInPumpOn ) || ( 0 == flowRate ) || ( dir == dialInPumpDirectionSet ) ) + if ( ( FALSE == isDialInPumpOn ) || ( 0 == flowRate ) || ( dir == dialInPumpDirectionSet ) ) { S32 dirFlowRate = ( dir == MOTOR_DIR_FORWARD ? (S32)flowRate : (S32)flowRate * -1 ); @@ -303,6 +306,7 @@ { BOOL isFlowRateInRange = ( flowRate <= MAX_DIAL_IN_FLOW_RATE ? TRUE : FALSE ); + isTestPWMSet = FALSE; #ifndef _RELEASE_ if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_PUMPS_FLOW_LIMITS ) ) { @@ -577,7 +581,8 @@ DIAL_IN_PUMP_STATE_T result = DIAL_IN_PUMP_OFF_STATE; // If we have been given a flow rate, setup ramp up and transition to ramp up state - if ( targetDialInFlowRate != 0 ) + if ( ( targetDialInFlowRate != 0 ) || + ( TRUE == isTestPWMSet ) ) { // Set initial PWM duty cycle dialInPumpPWMDutyCyclePctSet = DIP_PWM_ZERO_OFFSET + MAX_DIAL_IN_PUMP_PWM_STEP_UP_CHANGE; @@ -605,7 +610,8 @@ DIAL_IN_PUMP_STATE_T result = DIAL_IN_PUMP_RAMPING_UP_STATE; // Have we been asked to stop the dialIn pump? - if ( 0 == targetDialInFlowRate ) + if ( ( 0 == targetDialInFlowRate ) && + ( FALSE == isTestPWMSet ) ) { // Start ramp down to stop dialInPumpPWMDutyCyclePctSet -= MAX_DIAL_IN_PUMP_PWM_STEP_DN_CHANGE; @@ -1500,6 +1506,91 @@ * TEST SUPPORT FUNCTIONS *************************************************************************/ + +/*********************************************************************//** + * @brief + * The testSetDialInPumpWithPWM function sets a new pwm value and + * pump direction. + * @details Inputs: isDialInPumpOn, dialInPumpPWMDutyCyclePct, dialInPumpDirectionSet, + * dialInPumpState + * @details Outputs: dialInPumpControlMode, dialInPumpdirection, dialInPumpPWMDutyCyclePct + * @param pwm the new pwm value + * @return TRUE if new flow rate & dir are set, FALSE if not + **************************************************************************/ +static BOOL testSetDialInPumpWithPWM( F32 pwm ) +{ + MOTOR_DIR_T dir = MOTOR_DIR_FORWARD; + BOOL result = FALSE; + F32 pwmFabs = fabs(pwm); + + if ( pwm < 0 ) + { + dir = MOTOR_DIR_REVERSE; + } + + // Direction change while pump is running is not allowed unless we are turning off + if ( ( FALSE == isDialInPumpOn ) && ( dir != dialInPumpDirectionSet ) ) + { + dialInPumpDirection = dir; + } + + // Allow pump to turn on, change rate in same direction, or turn off. + if ( ( ( FALSE == isDialInPumpOn ) || ( dir == dialInPumpDirectionSet ) ) || ( pwmFabs <= MIN_DIAL_IN_PUMP_PWM_DUTY_CYCLE ) ) + { + // Don't interrupt pump control unless rate is changing + if ( ( pwmFabs != dialInPumpPWMDutyCyclePct ) ) + { + resetDialInFlowMovingAverage(); + dialInPumpControlMode = PUMP_CONTROL_MODE_OPEN_LOOP; + dialInPumpPWMDutyCyclePct = RANGE( pwmFabs, MIN_DIAL_IN_PUMP_PWM_DUTY_CYCLE, MAX_DIAL_IN_PUMP_PWM_DUTY_CYCLE ); + + // clear test flag if we are turning off the pump. + if ( pwmFabs <= MIN_DIAL_IN_PUMP_PWM_DUTY_CYCLE ) + { + isTestPWMSet = FALSE; + } + else + { + isTestPWMSet = TRUE; + } + + switch ( dialInPumpState ) + { + case DIAL_IN_PUMP_RAMPING_UP_STATE: // See if we need to reverse direction of ramp + if ( dialInPumpPWMDutyCyclePct < dialInPumpPWMDutyCyclePctSet ) + { + dialInPumpState = DIAL_IN_PUMP_RAMPING_DOWN_STATE; + } + break; + + case DIAL_IN_PUMP_RAMPING_DOWN_STATE: // See if we need to reverse direction of ramp + if ( dialInPumpPWMDutyCyclePct > dialInPumpPWMDutyCyclePctSet ) + { + dialInPumpState = DIAL_IN_PUMP_RAMPING_UP_STATE; + } + break; + + case DIAL_IN_PUMP_CONTROL_TO_TARGET_STATE: // Start ramp to new target in appropriate direction + if ( dialInPumpPWMDutyCyclePctSet > dialInPumpPWMDutyCyclePct ) + { + dialInPumpState = DIAL_IN_PUMP_RAMPING_DOWN_STATE; + } + else + { + dialInPumpState = DIAL_IN_PUMP_RAMPING_UP_STATE; + } + break; + + default: + // Ok - not all states need to be handled here + break; + } + result = TRUE; + } + } + + return result; +} /*********************************************************************//** * @brief @@ -1824,16 +1915,19 @@ * @param value duty cycle of the dialysate inlet pump (as a percentage). * @return TRUE if reset successful, FALSE if not *************************************************************************/ -BOOL testSetDialInPumpTargetDutyCycle( F32 value ) +BOOL testSetDialInPumpTargetDutyCycle( F32 pwmPct ) { BOOL result = FALSE; + F32 absolutePWM = fabs( pwmPct ); if ( TRUE == isTestingActivated() ) { - setDialInPumpTargetFlowRate( (U32)DIP_ML_PER_MIN_FROM_PWM(value), MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); - result = TRUE; + // check for max of pump pwm for acceptance. + if ( absolutePWM < MAX_DIAL_IN_PUMP_PWM_DUTY_CYCLE ) + { + result = testSetDialInPumpWithPWM( pwmPct ); + } } - return result; }