Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -refd96d27277f97c8ca1ca035cdd4ac3be5b5d6f9 -re190a7eb5fb36d4a0c42e9db709571db3037d39d --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision efd96d27277f97c8ca1ca035cdd4ac3be5b5d6f9) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision e190a7eb5fb36d4a0c42e9db709571db3037d39d) @@ -8,7 +8,7 @@ * @file DialInFlow.c * * @author (last) Dara Navaei -* @date (last) 15-Jun-2022 +* @date (last) 01-Sep-2022 * * @author (original) Sean * @date (original) 16-Dec-2019 @@ -77,8 +77,8 @@ static const U32 DIP_OFF_ERROR_PERSIST = ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); /// Persist time (task intervals) motor speed error condition. static const U32 DIP_MOTOR_SPEED_ERROR_PERSIST = ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); -/// Persist time (task intervals) rotor speed error condition. -static const U32 DIP_ROTOR_SPEED_ERROR_PERSIST = ((12 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); +/// Rotor speed persist time test needs a minimum number of rotations. +static const U32 DIP_ROTOR_ERROR_PERSIST_ROTATION_MIN = 3; /// Persist time (task intervals) pump direction error condition. static const U32 DIP_DIRECTION_ERROR_PERSIST = (250 / TASK_PRIORITY_INTERVAL); /// Persist time (task intervals) dialysate flow rate out of range error condition. @@ -268,7 +268,7 @@ * @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, F32 pwm ) +BOOL setDialInPumpTargetFlowRate( U32 flowRate, MOTOR_DIR_T dir, PUMP_CONTROL_MODE_T mode) { BOOL result = FALSE; @@ -278,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 ) || ( fabs(pwm) > NEARLY_ZERO ) ) + if ( ( dirFlowRate != targetDialInFlowRate ) || ( mode != dialInPumpControlMode ) ) { BOOL isFlowRateInRange = ( flowRate <= MAX_DIAL_IN_FLOW_RATE ? TRUE : FALSE ); @@ -297,14 +297,7 @@ 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 - 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; - } + dialInPumpPWMDutyCyclePct = ( 0 == flowRate ? DIP_PWM_ZERO_OFFSET : DIP_PWM_FROM_ML_PER_MIN( (F32)flowRate ) ); switch ( dialInPumpState ) { @@ -414,7 +407,7 @@ { dipStopAtHomePosition = TRUE; dipHomeStartTime = getMSTimerCount(); - result = setDialInPumpTargetFlowRate( DIP_HOME_RATE, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP, 0.0F ); + result = setDialInPumpTargetFlowRate( DIP_HOME_RATE, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); } return result; @@ -891,6 +884,28 @@ return result; } +/*********************************************************************//** + * @brief + * The getPumpRotorErrorPersistTime function calculates the Rotor error persist time. + * @details Inputs: none + * @details Outputs: none + * @param mtr_rpm, RPM of the motor. + * gear_ratio, Gear ratio of motor vs motor + * @return Persistent error test time in (ms) + *************************************************************************/ +U32 getPumpRotorErrorPersistTime( F32 mtr_rpm, F32 gear_ratio ) +{ + U32 err_persist_time = 0xFFFFFFF; + + if ( mtr_rpm > 0 ) + { + /// Calculate persist time for rotor speed error condition. + err_persist_time = ( ( DIP_ROTOR_ERROR_PERSIST_ROTATION_MIN / ( mtr_rpm / gear_ratio / SEC_PER_MIN ) ) * MS_PER_SECOND ); + } + + return err_persist_time; +} + /*********************************************************************//** * @brief * The publishDialInFlowData function publishes dialIn flow data at the set @@ -1141,7 +1156,7 @@ F32 cmdMotorSpeed = DIP_PWM_TO_MOTOR_SPEED_RPM( dialInPumpPWMDutyCyclePctSet ); F32 deltaMotorSpeed = fabs( measMotorSpeed - cmdMotorSpeed ); F32 deltaMCMotorSpeed = fabs( measMCMotorSpeed - cmdMotorSpeed ); - F32 measRotorSpeed = getMeasuredDialInPumpRotorSpeed(); + F32 measRotorSpeed = fabs( getMeasuredDialInPumpRotorSpeed() ); F32 measMotorSpeedInRotorRPM = measMotorSpeed / DIP_GEAR_RATIO; F32 deltaRotorSpeed = fabs( measRotorSpeed - measMotorSpeedInRotorRPM ); @@ -1166,7 +1181,7 @@ // Check measured rotor speed vs. measured motor speed while controlling to target if ( deltaRotorSpeed > DIP_MAX_ROTOR_VS_MOTOR_DIFF_RPM ) { - if ( ++errorDialInRotorSpeedPersistTimerCtr >= DIP_ROTOR_SPEED_ERROR_PERSIST ) + if ( ++errorDialInRotorSpeedPersistTimerCtr >= ( getPumpRotorErrorPersistTime( measMotorSpeed, DIP_GEAR_RATIO ) / TASK_PRIORITY_INTERVAL ) ) { #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_PUMP_SPEED_CHECKS ) != SW_CONFIG_ENABLE_VALUE ) @@ -1418,7 +1433,7 @@ } else { - result = setDialInPumpTargetFlowRate( abs(value), dir, (PUMP_CONTROL_MODE_T)ctrlMode, 0.0F ); + result = setDialInPumpTargetFlowRate( abs(value), dir, (PUMP_CONTROL_MODE_T)ctrlMode ); } } } @@ -1665,7 +1680,7 @@ if ( TRUE == isTestingActivated() ) { - setDialInPumpTargetFlowRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP, value ); + setDialInPumpTargetFlowRate( (U32)DIP_ML_PER_MIN_FROM_PWM(value), MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); result = TRUE; }