Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -r8377b4e6ed494cbfc5dfc2bd9ad3c89b85b333cd -r93a439cf9d1b347e23b84d1156417380ee01efaa --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 8377b4e6ed494cbfc5dfc2bd9ad3c89b85b333cd) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 93a439cf9d1b347e23b84d1156417380ee01efaa) @@ -49,11 +49,21 @@ #define DIP_P_COEFFICIENT 0.00005 ///> P term for dialIn pump control #define DIP_I_COEFFICIENT 0.00015 ///> I term for dialIn pump control -#define DIP_HOME_RATE 50 ///< target pump speed (in estimate mL/min) for homing. +#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). #define DIP_SPEED_CALC_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< interval (ms/task time) at which the dialysate inlet pump speed is calculated. #define DIP_HALL_EDGE_COUNTS_PER_REV 48 ///< number of hall sensor edge counts per motor revolution. +#define DIP_MAX_FLOW_VS_SPEED_DIFF_ML_MIN 50.0 ///< maximum difference between measured flow and flow implied by measured motor speed. +#define DIP_MAX_MOTOR_SPEED_WHILE_OFF_RPM 100.0 ///< maximum motor speed (RPM) while motor is commanded off. +#define DIP_MAX_ROTOR_VS_MOTOR_DIFF_RPM 5.0 ///< maximum difference in speed between motor and rotor (in rotor RPM). +#define DIP_MAX_MOTOR_SPEED_ERROR_RPM 300.0 ///< maximum difference in speed between measured and commanded RPM. +#define DIP_FLOW_VS_SPEED_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) for flow vs. motor speed error condition. +#define DIP_OFF_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) for motor off error condition. +#define DIP_MOTOR_SPEED_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) motor speed error condition. +#define DIP_ROTOR_SPEED_ERROR_PERSIST ((12 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) rotor speed error condition. + + #define DIP_MAX_CURR_WHEN_STOPPED_MA 150.0 ///> motor controller current should not exceed this when pump should be stopped #define DIP_MIN_CURR_WHEN_RUNNING_MA 150.0 ///> motor controller current should always exceed this when pump should be running #define DIP_MAX_CURR_WHEN_RUNNING_MA 1000.0 ///> motor controller current should not exceed this when pump should be running @@ -140,6 +150,11 @@ static MOTOR_DIR_T dipMotorDirectionFromHallSensors = MOTOR_DIR_FORWARD; ///< pump direction according to hall sensor count static U32 dipMotorSpeedCalcTimerCtr = 0; ///< counter determines interval for calculating dialysate inlet pump motor speed from hall sensor count. +static U32 errorDialInFlowVsMotorSpeedPersistTimerCtr = 0; ///< persistence timer counter for flow vs. motor speed error condition. +static U32 errorDialInMotorOffPersistTimerCtr = 0; ///< persistence timer counter for motor off check error condition. +static U32 errorDialInMotorSpeedPersistTimerCtr = 0; ///< persistence timer counter for motor speed error condition. +static U32 errorDialInRotorSpeedPersistTimerCtr = 0; ///< persistence timer counter for rotor speed error condition. + static F32 flowReadings[ SIZE_OF_ROLLING_AVG ]; ///< holds flow samples for a rolling average static U32 flowReadingsIdx = 0; ///< index for next sample in rolling average array static F32 flowReadingsTotal = 0.0; ///< rolling total - used to calc average @@ -353,18 +368,18 @@ // calculate dialysate inlet pump motor speed/direction from hall sensor count updateDialInPumpSpeedAndDirectionFromHallSensors(); - // check pump speeds and flow - checkDialInPumpSpeeds(); - checkDialInPumpFlowAgainstSpeed(); - - // check for home position, zero/low speed - checkDialInPumpRotor(); - // don't start enforcing checks until out of init/POST mode if ( getCurrentOperationMode() != MODE_INIT ) { + // check pump direction checkDialInPumpDirection(); + // check pump controller current checkDialInPumpMCCurrent(); + // check pump speeds and flow + checkDialInPumpSpeeds(); + checkDialInPumpFlowAgainstSpeed(); + // check for home position, zero/low speed + checkDialInPumpRotor(); } // publish dialIn flow data on interval @@ -911,19 +926,138 @@ dipMCDir = ( getMeasuredDialInPumpMCSpeed() >= 0.0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); if ( ( dialInPumpDirectionSet != dipMCDir ) || ( dialInPumpDirectionSet != dipMotorDirectionFromHallSensors ) ) { +#ifndef DISABLE_PUMP_DIRECTION_CHECKS SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DIAL_IN_PUMP_MC_DIRECTION_CHECK, (U32)dialInPumpDirectionSet, (U32)dipMotorDirectionFromHallSensors ) +#endif } } } +/*********************************************************************//** + * @brief + * The checkDialInPumpSpeeds function checks several aspects of the dialysate \n + * inlet pump speed. \n + * 1. while pump is commanded off, measured motor speed should be < limit. \n + * 2. while pump is controlling, measured motor speed should be within allowed range of commanded speed. \n + * 3. measured motor speed should be within allowed range of measured rotor speed. \n + * All 3 checks have a persistence time that must be met before an alarm is triggered. + * @details + * Inputs : targetDialInFlowRate, dialInPumpSpeedRPM, dialInPumpRotorSpeedRPM + * Outputs : alarm(s) may be triggered + * @return none + *************************************************************************/ static void checkDialInPumpSpeeds( void ) { + F32 measMotorSpeed = getMeasuredDialInPumpSpeed(); + S32 cmdRate = getTargetDialInFlowRate(); + // check for pump running while commanded off + if ( 0 == cmdRate ) + { + if ( measMotorSpeed > DIP_MAX_MOTOR_SPEED_WHILE_OFF_RPM ) + { + if ( ++errorDialInMotorOffPersistTimerCtr >= DIP_OFF_ERROR_PERSIST ) + { +#ifndef DISABLE_PUMP_SPEED_CHECKS + SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DIAL_IN_PUMP_OFF_CHECK, measMotorSpeed ); +#endif + } + } + else + { + errorDialInMotorOffPersistTimerCtr = 0; + } + } + else + { + errorDialInMotorOffPersistTimerCtr = 0; + } + + if ( DIAL_IN_PUMP_CONTROL_TO_TARGET_STATE == dialInPumpState ) + { + F32 cmdMotorSpeed = ( (F32)cmdRate / (F32)ML_PER_LITER ) * DIP_REV_PER_LITER * DIP_GEAR_RATIO; + F32 deltaMotorSpeed = FABS( measMotorSpeed - cmdMotorSpeed ); + F32 measRotorSpeed = getMeasuredDialInPumpRotorSpeed(); + F32 measMotorSpeedInRotorRPM = measMotorSpeed / DIP_GEAR_RATIO; + F32 deltaRotorSpeed = FABS( measRotorSpeed - measMotorSpeedInRotorRPM ); + + // check measured motor speed vs. commanded motor speed while controlling to target + if ( deltaMotorSpeed > DIP_MAX_MOTOR_SPEED_ERROR_RPM ) + { + if ( ++errorDialInMotorSpeedPersistTimerCtr >= DIP_MOTOR_SPEED_ERROR_PERSIST ) + { +#ifndef DISABLE_PUMP_SPEED_CHECKS + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DIAL_IN_PUMP_MOTOR_SPEED_CHECK, (F32)cmdRate, measMotorSpeed ); +#endif + } + } + else + { + errorDialInMotorSpeedPersistTimerCtr = 0; + } + + // 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 ) + { +#ifndef DISABLE_PUMP_SPEED_CHECKS + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DIAL_IN_PUMP_ROTOR_SPEED_CHECK, measRotorSpeed, measMotorSpeed ); +#endif + } + } + else + { + errorDialInRotorSpeedPersistTimerCtr = 0; + } + + } + else + { + errorDialInMotorSpeedPersistTimerCtr = 0; + errorDialInRotorSpeedPersistTimerCtr = 0; + } } +/*********************************************************************//** + * @brief + * The checkDialInPumpFlowAgainstSpeed function checks the measured dialysate flow \n + * against the implied flow of the measured pump speed when in treatment mode \n + * and controlling to target flow. If a sufficient difference persists, a \n + * flow vs. motor speed check error is triggered. + * @details + * Inputs : measuredDialInFlowRate, dialInPumpSpeedRPM, errorDialInFlowVsMotorSpeedPersistTimerCtr + * Outputs : alarm may be triggered + * @return none + *************************************************************************/ static void checkDialInPumpFlowAgainstSpeed( void ) { + // check only performed while in treatment mode and while we're in control to target state + if ( ( MODE_TREA == getCurrentOperationMode() ) && ( DIAL_IN_PUMP_CONTROL_TO_TARGET_STATE == dialInPumpState ) ) + { + F32 flow = getMeasuredDialInFlowRate(); + F32 speed = getMeasuredDialInPumpSpeed(); + F32 impliedFlow = ( ( speed / DIP_GEAR_RATIO ) / DIP_REV_PER_LITER ) * (F32)ML_PER_LITER; + F32 delta = FABS( flow - impliedFlow ); + if ( delta > DIP_MAX_FLOW_VS_SPEED_DIFF_ML_MIN ) + { + if ( ++errorDialInFlowVsMotorSpeedPersistTimerCtr >= DIP_FLOW_VS_SPEED_PERSIST ) + { +#ifndef DISABLE_PUMP_FLOW_CHECKS + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DIAL_IN_PUMP_FLOW_VS_MOTOR_SPEED_CHECK, flow, impliedFlow ); +#endif + } + } + else + { + errorDialInFlowVsMotorSpeedPersistTimerCtr = 0; + } + } + else + { + errorDialInFlowVsMotorSpeedPersistTimerCtr = 0; + } } /*********************************************************************//** @@ -948,7 +1082,7 @@ dipCurrErrorDurationCtr += TASK_PRIORITY_INTERVAL; if ( dipCurrErrorDurationCtr > DIP_MAX_CURR_ERROR_DURATION_MS ) { -#ifndef DISABLE_MOTOR_CURRENT_ERRORS +#ifndef DISABLE_MOTOR_CURRENT_CHECKS SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DIAL_IN_PUMP_MC_CURRENT_CHECK, getMeasuredDialInPumpMCCurrent() ); #endif } @@ -967,7 +1101,7 @@ dipCurrErrorDurationCtr += TASK_PRIORITY_INTERVAL; if ( dipCurrErrorDurationCtr > DIP_MAX_CURR_ERROR_DURATION_MS ) { -#ifndef DISABLE_MOTOR_CURRENT_ERRORS +#ifndef DISABLE_MOTOR_CURRENT_CHECKS SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DIAL_IN_PUMP_MC_CURRENT_CHECK, getMeasuredDialInPumpMCCurrent() ); #endif }