Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -r44a100f8e5210a02c23b8fcc4527d8e96d577381 -rafa9d4924d55ac4fc98270a012e92dd1f6ee65d0 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 44a100f8e5210a02c23b8fcc4527d8e96d577381) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision afa9d4924d55ac4fc98270a012e92dd1f6ee65d0) @@ -42,17 +42,18 @@ // ********** private definitions ********** /// Interval (ms/task time) at which the dialIn flow data is published on the CAN bus. -#define DIAL_IN_FLOW_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) +#define DIAL_IN_FLOW_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) -#define MAX_DIAL_IN_PUMP_PWM_STEP_UP_CHANGE 0.0133 ///< Max duty cycle change when ramping up ~ 200 mL/min/s. -#define MAX_DIAL_IN_PUMP_PWM_STEP_DN_CHANGE 0.02 ///< Max duty cycle change when ramping down ~ 300 mL/min/s. -#define MAX_DIAL_IN_PUMP_PWM_DUTY_CYCLE 0.89 ///< Controller will error if PWM duty cycle > 90%, so set max to 89%. -#define MIN_DIAL_IN_PUMP_PWM_DUTY_CYCLE 0.10 ///< Controller will error if PWM duty cycle < 10%, so set min to 10%. +#define MAX_DIAL_IN_PUMP_PWM_STEP_UP_CHANGE 0.0133 ///< Max duty cycle change when ramping up ~ 200 mL/min/s. +#define MAX_DIAL_IN_PUMP_PWM_STEP_DN_CHANGE 0.02 ///< Max duty cycle change when ramping down ~ 300 mL/min/s. +#define MAX_DIAL_IN_PUMP_PWM_DUTY_CYCLE 0.89 ///< Controller will error if PWM duty cycle > 90%, so set max to 89%. +#define MIN_DIAL_IN_PUMP_PWM_DUTY_CYCLE 0.10 ///< Controller will error if PWM duty cycle < 10%, so set min to 10%. +#define DIP_CONTROL_INTERVAL_SEC 10 ///< Dialysate inlet pump control interval (in seconds). /// Interval (ms/task time) at which the dialIn pump is controlled. -static const U32 DIP_CONTROL_INTERVAL = ( 10000 / TASK_GENERAL_INTERVAL ); -#define DIP_P_COEFFICIENT 0.00035 ///< P term for dialIn pump control. -#define DIP_I_COEFFICIENT 0.00035 ///< I term for dialIn pump control. +static const U32 DIP_CONTROL_INTERVAL = ( DIP_CONTROL_INTERVAL_SEC * MS_PER_SECOND / TASK_GENERAL_INTERVAL ); +#define DIP_P_COEFFICIENT 0.0001 ///< P term for dialIn pump control. +#define DIP_I_COEFFICIENT 0.00075 ///< I term for dialIn pump control. #define DIP_HOME_RATE 100 ///< Target pump speed (in estimate mL/min) for homing. #define DIP_HOME_TIMEOUT_MS 10000 ///< Maximum time allowed for homing to complete (in ms). @@ -85,9 +86,9 @@ #ifndef V2_0_SYSTEM #define DIP_SPEED_ADC_TO_RPM_FACTOR 1.751752 ///< Conversion factor from ADC counts to RPM for dialIn pump motor. - #define DIP_MOTOR_RPM_TO_PWM_DC_FACTOR 0.00025 ///< ~40 BP motor RPM = 1% PWM duty cycle + #define DIP_MOTOR_RPM_TO_PWM_DC_FACTOR 0.000193 ///< ~52 BP motor RPM = 1% PWM duty cycle #else - #define DIP_SPEED_ADC_TO_RPM_FACTOR 1.280938 ///< Conversion factor from ADC counts to RPM for blood pump motor + #define DIP_SPEED_ADC_TO_RPM_FACTOR 1.280938 ///< Conversion factor from ADC counts to RPM for dialIn pump motor #define DIP_MOTOR_RPM_TO_PWM_DC_FACTOR 0.0003125 ///< ~32 BP motor RPM = 1% PWM duty cycle #endif #define DIP_CURRENT_ADC_TO_MA_FACTOR 3.002 ///< Conversion factor from ADC counts to mA for dialIn pump motor. @@ -106,7 +107,7 @@ #define SIGN_FROM_12_BIT_VALUE(v) ( (S16)(v) - (S16)DIAL_IN_PUMP_ADC_ZERO ) /// Measured dialIn flow is filtered w/ moving average. -#define SIZE_OF_ROLLING_AVG ( ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) * 10 ) +#define SIZE_OF_ROLLING_AVG ( ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) * DIP_CONTROL_INTERVAL_SEC ) /// Dialysate flow sensor signal strength low alarm persistence. #define FLOW_SIG_STRGTH_ALARM_PERSIST ( 5 * MS_PER_SECOND ) @@ -280,8 +281,10 @@ // Direction change while pump is running is not allowed if ( ( FALSE == isDialInPumpOn ) || ( 0 == flowRate ) || ( dir == dialInPumpDirectionSet ) ) { +#ifndef NO_PUMP_FLOW_LIMITS // Verify flow rate - if ( flowRate <= MAX_DIAL_IN_FLOW_RATE ) + if ( flowRate <= MAX_DIAL_IN_FLOW_RATE ) +#endif { resetDialInFlowMovingAverage(); targetDialInFlowRate = ( dir == MOTOR_DIR_FORWARD ? (S32)flowRate : (S32)flowRate * -1 ); @@ -320,10 +323,12 @@ } result = TRUE; } +#ifndef NO_PUMP_FLOW_LIMITS else // Requested flow rate too high { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_DIAL_IN_FLOW_SET_TOO_HIGH, flowRate ) - } + } +#endif } return result; @@ -566,14 +571,11 @@ else if ( dialInPumpPWMDutyCyclePctSet >= dialInPumpPWMDutyCyclePct ) { resetDialInFlowMovingAverage(); + dialInPumpPWMDutyCyclePctSet = dialInPumpPWMDutyCyclePct; resetPIController( PI_CONTROLLER_ID_DIALYSATE_FLOW, dialInPumpPWMDutyCyclePctSet ); dialInPumpControlModeSet = dialInPumpControlMode; - // If open loop mode, set PWM to requested duty cycle where it will stay during control state - if ( dialInPumpControlModeSet == PUMP_CONTROL_MODE_OPEN_LOOP ) - { - dialInPumpPWMDutyCyclePctSet = dialInPumpPWMDutyCyclePct; - setDialInPumpControlSignalPWM( dialInPumpPWMDutyCyclePct ); - } + setDialInPumpControlSignalPWM( dialInPumpPWMDutyCyclePct ); + dipControlTimerCounter = 0; result = DIAL_IN_PUMP_CONTROL_TO_TARGET_STATE; } // Continue ramp up @@ -608,14 +610,11 @@ else if ( dialInPumpPWMDutyCyclePctSet <= dialInPumpPWMDutyCyclePct ) { resetDialInFlowMovingAverage(); + dialInPumpPWMDutyCyclePctSet = dialInPumpPWMDutyCyclePct; resetPIController( PI_CONTROLLER_ID_DIALYSATE_FLOW, dialInPumpPWMDutyCyclePctSet ); dialInPumpControlModeSet = dialInPumpControlMode; - // If open loop mode, set PWM to requested duty cycle where it will stay during control state - if ( dialInPumpControlModeSet == PUMP_CONTROL_MODE_OPEN_LOOP ) - { - dialInPumpPWMDutyCyclePctSet = dialInPumpPWMDutyCyclePct; - setDialInPumpControlSignalPWM( dialInPumpPWMDutyCyclePct ); - } + setDialInPumpControlSignalPWM( dialInPumpPWMDutyCyclePct ); + dipControlTimerCounter = 0; result = DIAL_IN_PUMP_CONTROL_TO_TARGET_STATE; } // Continue ramp down @@ -880,6 +879,19 @@ } return result; +} + +/*********************************************************************//** + * @brief + * The getDialInPumpPWMDutyCyclePct function gets the current dialIn pump + * PWM duty cycle percentage. + * @details Inputs: dialInPumpPWMDutyCyclePctSet + * @details Outputs: none + * @return the current dialIn pump PWM duty cycle percentage (0..1). + *************************************************************************/ +F32 getDialInPumpPWMDutyCyclePct( void ) +{ + return dialInPumpPWMDutyCyclePctSet; } /*********************************************************************//**