Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -r8377b4e6ed494cbfc5dfc2bd9ad3c89b85b333cd -r93a439cf9d1b347e23b84d1156417380ee01efaa --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 8377b4e6ed494cbfc5dfc2bd9ad3c89b85b333cd) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 93a439cf9d1b347e23b84d1156417380ee01efaa) @@ -48,11 +48,20 @@ #define BP_P_COEFFICIENT 0.00005 ///< P term for blood pump control #define BP_I_COEFFICIENT 0.00015 ///< I term for blood pump control -#define BP_HOME_RATE 50 ///< target pump speed (in estimate mL/min) for homing. +#define BP_HOME_RATE 100 ///< target pump speed (in estimate mL/min) for homing. #define BP_HOME_TIMEOUT_MS 10000 ///< maximum time allowed for homing to complete (in ms). #define BP_SPEED_CALC_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< interval (ms/task time) at which the blood pump speed is calculated. #define BP_HALL_EDGE_COUNTS_PER_REV 48 ///< number of hall sensor edge counts per motor revolution. +#define BP_MAX_FLOW_VS_SPEED_DIFF_ML_MIN 50.0 ///< maximum difference between measured flow and flow implied by measured motor speed. +#define BP_MAX_MOTOR_SPEED_WHILE_OFF_RPM 100.0 ///< maximum motor speed (RPM) while motor is commanded off. +#define BP_MAX_ROTOR_VS_MOTOR_DIFF_RPM 5.0 ///< maximum difference in speed between motor and rotor (in rotor RPM). +#define BP_MAX_MOTOR_SPEED_ERROR_RPM 300.0 ///< maximum difference in speed between measured and commanded RPM. +#define BP_FLOW_VS_SPEED_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) for flow vs. motor speed error condition. +#define BP_OFF_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) for motor off error condition. +#define BP_MOTOR_SPEED_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) motor speed error condition. +#define BP_ROTOR_SPEED_ERROR_PERSIST ((12 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) rotor speed error condition. + #define BP_MAX_CURR_WHEN_STOPPED_MA 150.0 ///< motor controller current should not exceed this when pump should be stopped #define BP_MIN_CURR_WHEN_RUNNING_MA 150.0 ///< motor controller current should always exceed this when pump should be running #define BP_MAX_CURR_WHEN_RUNNING_MA 1000.0 ///< motor controller current should not exceed this when pump should be running @@ -139,6 +148,11 @@ static MOTOR_DIR_T bpMotorDirectionFromHallSensors = MOTOR_DIR_FORWARD; ///< pump direction according to hall sensor count static U32 bpMotorSpeedCalcTimerCtr = 0; ///< counter determines interval for calculating blood pump motor speed from hall sensor count. +static U32 errorBloodFlowVsMotorSpeedPersistTimerCtr = 0; ///< persistence timer counter for flow vs. motor speed error condition. +static U32 errorBloodMotorOffPersistTimerCtr = 0; ///< persistence timer counter for motor off check error condition. +static U32 errorBloodMotorSpeedPersistTimerCtr = 0; ///< persistence timer counter for motor speed error condition. +static U32 errorBloodRotorSpeedPersistTimerCtr = 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 @@ -352,18 +366,18 @@ // calculate blood pump motor speed/direction from hall sensor count updateBloodPumpSpeedAndDirectionFromHallSensors(); - // check pump speeds and flow - checkBloodPumpSpeeds(); - checkBloodPumpFlowAgainstSpeed(); - - // check for home position, zero/low speed - checkBloodPumpRotor(); - // don't start enforcing checks until out of init/POST mode if ( getCurrentOperationMode() != MODE_INIT ) { + // check pump direction checkBloodPumpDirection(); + // check pump controller current checkBloodPumpMCCurrent(); + // check pump speeds and flow + checkBloodPumpSpeeds(); + checkBloodPumpFlowAgainstSpeed(); + // check for home position, zero/low speed + checkBloodPumpRotor(); } // publish blood flow data on interval @@ -990,24 +1004,139 @@ bpMCDir = ( getMeasuredBloodPumpMCSpeed() >= 0.0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); if ( ( bloodPumpDirectionSet != bpMCDir ) || ( bloodPumpDirectionSet != bpMotorDirectionFromHallSensors ) ) { +#ifndef DISABLE_PUMP_DIRECTION_CHECKS SET_ALARM_WITH_2_U32_DATA( ALARM_ID_BLOOD_PUMP_MC_DIRECTION_CHECK, (U32)bloodPumpDirectionSet, (U32)bpMotorDirectionFromHallSensors ) +#endif } } } +/*********************************************************************//** + * @brief + * The checkBloodPumpSpeeds function checks several aspects of the blood pump \n + * 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 : targetBloodFlowRate, bloodPumpSpeedRPM, bloodPumpRotorSpeedRPM + * Outputs : alarm(s) may be triggered + * @return none + *************************************************************************/ static void checkBloodPumpSpeeds( void ) { + F32 measMotorSpeed = getMeasuredBloodPumpSpeed(); + S32 cmdRate = getTargetBloodFlowRate(); + // check for pump running while commanded off + if ( 0 == cmdRate ) + { + if ( measMotorSpeed > BP_MAX_MOTOR_SPEED_WHILE_OFF_RPM ) + { + if ( ++errorBloodMotorOffPersistTimerCtr >= BP_OFF_ERROR_PERSIST ) + { +#ifndef DISABLE_PUMP_SPEED_CHECKS + SET_ALARM_WITH_1_F32_DATA( ALARM_ID_BLOOD_PUMP_OFF_CHECK, measMotorSpeed ); +#endif + } + } + else + { + errorBloodMotorOffPersistTimerCtr = 0; + } + } + else + { + errorBloodMotorOffPersistTimerCtr = 0; + } + + if ( BLOOD_PUMP_CONTROL_TO_TARGET_STATE == bloodPumpState ) + { + F32 cmdMotorSpeed = ( (F32)cmdRate / (F32)ML_PER_LITER ) * BP_REV_PER_LITER * BP_GEAR_RATIO; + F32 deltaMotorSpeed = FABS( measMotorSpeed - cmdMotorSpeed ); + F32 measRotorSpeed = getMeasuredBloodPumpRotorSpeed(); + F32 measMotorSpeedInRotorRPM = measMotorSpeed / BP_GEAR_RATIO; + F32 deltaRotorSpeed = FABS( measRotorSpeed - measMotorSpeedInRotorRPM ); + + // check measured motor speed vs. commanded motor speed while controlling to target + if ( deltaMotorSpeed > BP_MAX_MOTOR_SPEED_ERROR_RPM ) + { + if ( ++errorBloodMotorSpeedPersistTimerCtr >= BP_MOTOR_SPEED_ERROR_PERSIST ) + { +#ifndef DISABLE_PUMP_SPEED_CHECKS + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_BLOOD_PUMP_MOTOR_SPEED_CHECK, (F32)cmdRate, measMotorSpeed ); +#endif + } + } + else + { + errorBloodMotorSpeedPersistTimerCtr = 0; + } + + // check measured rotor speed vs. measured motor speed while controlling to target + if ( deltaRotorSpeed > BP_MAX_ROTOR_VS_MOTOR_DIFF_RPM ) + { + if ( ++errorBloodRotorSpeedPersistTimerCtr >= BP_ROTOR_SPEED_ERROR_PERSIST ) + { +#ifndef DISABLE_PUMP_SPEED_CHECKS + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_BLOOD_PUMP_ROTOR_SPEED_CHECK, measRotorSpeed, measMotorSpeed ); +#endif + } + } + else + { + errorBloodRotorSpeedPersistTimerCtr = 0; + } + + } + else + { + errorBloodMotorSpeedPersistTimerCtr = 0; + errorBloodRotorSpeedPersistTimerCtr = 0; + } } +/*********************************************************************//** + * @brief + * The checkBloodPumpFlowAgainstSpeed function checks the measured blood 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 : measuredBloodFlowRate, bloodPumpSpeedRPM, errorBloodFlowVsMotorSpeedPersistTimerCtr + * Outputs : alarm may be triggered + * @return none + *************************************************************************/ static void checkBloodPumpFlowAgainstSpeed( void ) { + // check only performed while in treatment mode and while we're in control to target state + if ( ( MODE_TREA == getCurrentOperationMode() ) && ( BLOOD_PUMP_CONTROL_TO_TARGET_STATE == bloodPumpState ) ) + { + F32 flow = getMeasuredBloodFlowRate(); + F32 speed = getMeasuredBloodPumpSpeed(); + F32 impliedFlow = ( ( speed / BP_GEAR_RATIO ) / BP_REV_PER_LITER ) * (F32)ML_PER_LITER; + F32 delta = FABS( flow - impliedFlow ); + if ( delta > BP_MAX_FLOW_VS_SPEED_DIFF_ML_MIN ) + { + if ( ++errorBloodFlowVsMotorSpeedPersistTimerCtr >= BP_FLOW_VS_SPEED_PERSIST ) + { +#ifndef DISABLE_PUMP_FLOW_CHECKS + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_BLOOD_PUMP_FLOW_VS_MOTOR_SPEED_CHECK, flow, impliedFlow ); +#endif + } + } + else + { + errorBloodFlowVsMotorSpeedPersistTimerCtr = 0; + } + } + else + { + errorBloodFlowVsMotorSpeedPersistTimerCtr = 0; + } } -//ALARM_ID_BLOOD_PUMP_OFF_CHECK = 7, ///< Blood pump failed motor controller off check. -//ALARM_ID_BLOOD_PUMP_ROTOR_SPEED_CHECK = 9, ///< Blood pump failed rotor speed check. Mismatch with rotor and motor speeds. -//ALARM_ID_BLOOD_PUMP_FLOW_VS_MOTOR_SPEED_CHECK = 51, ///< Blood pump failed flow vs. motor speed check. Mismatch with flow rate and rate implied by motor speed. -//ALARM_ID_BLOOD_PUMP_MOTOR_SPEED_CHECK = 54, ///< Blood pump failed motor speed check. Measured vs. commanded. /*********************************************************************//** * @brief @@ -1031,7 +1160,7 @@ bpCurrErrorDurationCtr += TASK_PRIORITY_INTERVAL; if ( bpCurrErrorDurationCtr > BP_MAX_CURR_ERROR_DURATION_MS ) { -#ifndef DISABLE_MOTOR_CURRENT_ERRORS +#ifndef DISABLE_MOTOR_CURRENT_CHECKS SET_ALARM_WITH_1_F32_DATA( ALARM_ID_BLOOD_PUMP_MC_CURRENT_CHECK, getMeasuredBloodPumpMCCurrent() ); #endif } @@ -1050,7 +1179,7 @@ bpCurrErrorDurationCtr += TASK_PRIORITY_INTERVAL; if ( bpCurrErrorDurationCtr > BP_MAX_CURR_ERROR_DURATION_MS ) { -#ifndef DISABLE_MOTOR_CURRENT_ERRORS +#ifndef DISABLE_MOTOR_CURRENT_CHECKS SET_ALARM_WITH_1_F32_DATA( ALARM_ID_BLOOD_PUMP_MC_CURRENT_CHECK, getMeasuredBloodPumpMCCurrent() ); #endif }