Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -rf5d4fecd7b937ddf8e8b4ef3372541e79c7a44fc -r337374e4cfef2474a50c58c5db783b349c661fad --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision f5d4fecd7b937ddf8e8b4ef3372541e79c7a44fc) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 337374e4cfef2474a50c58c5db783b349c661fad) @@ -73,6 +73,7 @@ #define BP_SPEED_CALC_BUFFER_LEN ( MS_PER_SECOND / BP_SPEED_CALC_INTERVAL / TASK_PRIORITY_INTERVAL ) #define BP_MAX_ROTOR_SPEED_RPM 100.0F ///< Maximum rotor speed allowed for blood pump. +#define BP_MIN_ROTOR_PULSES_FOR_MAX_SPEED 2 ///< Minimum rotor pulses indicating excessive speed required for alarm. #define BP_MAX_FLOW_RATE 1320.0F ///< Maximum measured BP flow rate allowed. #define BP_MIN_FLOW_RATE -1320.0F ///< Minimum measured BP flow rate allowed. @@ -195,16 +196,17 @@ static U32 rpmReadingsCount = 0; ///< Number of samples in RPM rolling average buffer. static F32 filteredBloodPumpSpeed = 0.0; ///< Filtered blood pump speed used in blood flow estimation. -static U32 bpControlTimerCounter = 0; ///< Determines when to perform control on blood flow +static U32 bpControlTimerCounter = 0; ///< Determines when to perform control on blood flow. -static U32 bpRotorRevStartTime = 0; ///< Blood pump rotor rotation start time (in ms) -static OVERRIDE_U32_T bloodPumpRotorCounter = { 0, 0, 0, 0 }; ///< Running counter for blood pump rotor revolutions -static BOOL bpStopAtHomePosition = FALSE; ///< Stop blood pump at next home position -static U32 bpHomeStartTime = 0; ///< When did blood pump home command begin? (in ms) +static U32 bpRotorRevStartTime = 0; ///< Blood pump rotor rotation start time (in ms). +static OVERRIDE_U32_T bloodPumpRotorCounter = { 0, 0, 0, 0 }; ///< Running counter for blood pump rotor revolutions. +static U32 bpRotorSpeedTooFastPulseCount; ///< Counter for rotor pulses indicating RPM > 100. +static BOOL bpStopAtHomePosition = FALSE; ///< Stop blood pump at next home position. +static U32 bpHomeStartTime = 0; ///< When did blood pump home command begin? (in ms). -static U32 bloodPumpMotorEdgeCount = 0; ///< Running counter for blood pump motor revolutions -static U16 bpLastMotorHallSensorCounts[ BP_SPEED_CALC_BUFFER_LEN ]; ///< Last hall sensor readings for the blood pump motor -static U32 bpMotorSpeedCalcIdx = 0; ///< Index into 1 second buffer of motor speed hall sensor counts +static U32 bloodPumpMotorEdgeCount = 0; ///< Running counter for blood pump motor revolutions. +static U16 bpLastMotorHallSensorCounts[ BP_SPEED_CALC_BUFFER_LEN ]; ///< Last hall sensor readings for the blood pump motor. +static U32 bpMotorSpeedCalcIdx = 0; ///< Index into 1 second buffer of motor speed hall sensor counts. static U32 bpMotorSpeedCalcTimerCtr = 0; ///< Counter determines interval for calculating blood pump motor speed from hall sensor count. static HD_PUMPS_CAL_RECORD_T bloodPumpCalRecord; ///< Blood pump calibration record. @@ -241,6 +243,7 @@ U32 i; bloodFlowDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; + bpRotorSpeedTooFastPulseCount = 0; signalBloodPumpHardStop(); setBloodPumpDirection( MOTOR_DIR_FORWARD ); @@ -440,14 +443,25 @@ *************************************************************************/ void signalBloodPumpRotorHallSensor( void ) { - U32 rotTime = getMSTimerCount(); + U32 rotTime = getMSTimerCount(); U32 deltaTime = calcTimeBetween( bpRotorRevStartTime, rotTime ); + F32 rotSpeed = ( 1.0F / (F32)deltaTime ) * (F32)MS_PER_SECOND * (F32)SEC_PER_MIN; // calculate rotor speed indicating by time between this and previous pulse // Increment rotor counter bloodPumpRotorCounter.data++; + // Count pulses indicating rotor speed too fast + if ( getMeasuredBloodPumpRotorSpeed() > BP_MAX_ROTOR_SPEED_RPM ) + { + bpRotorSpeedTooFastPulseCount++; + } + else + { + bpRotorSpeedTooFastPulseCount = 0; + } + // Calculate rotor speed (in RPM) - bloodPumpRotorSpeedRPM.data = ( 1.0F / (F32)deltaTime ) * (F32)MS_PER_SECOND * (F32)SEC_PER_MIN; + bloodPumpRotorSpeedRPM.data = rotSpeed; bpRotorRevStartTime = rotTime; // If we are supposed to stop pump at home position, stop pump now. @@ -1088,8 +1102,10 @@ * The checkBloodPumpRotor function checks the rotor for the blood * pump. If homing, this function will stop when hall sensor detected. If pump * is off or running very slowly, rotor speed will be set to zero. - * @details Inputs: bpStopAtHomePosition, bpHomeStartTime, bpRotorRevStartTime - * @details Outputs: pump may be stopped if homing, bloodPumpRotorSpeedRPM may be set to zero. + * @details Inputs: bpStopAtHomePosition, bpHomeStartTime, bpRotorRevStartTime, + * bpRotorSpeedTooFastPulseCount + * @details Outputs: pump may be stopped if homing, bloodPumpRotorSpeedRPM may be + * set to zero if too long since last pulse. * @return none *************************************************************************/ static void checkBloodPumpRotor( void ) @@ -1101,11 +1117,10 @@ { signalBloodPumpHardStop(); bpStopAtHomePosition = FALSE; - // TODO - alarm??? } // Ensure rotor speed below maximum - if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_BLOOD_PUMP_ROTOR_SPEED_TOO_HIGH, rotorSpeed > BP_MAX_ROTOR_SPEED_RPM ) ) + if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_BLOOD_PUMP_ROTOR_SPEED_TOO_HIGH, bpRotorSpeedTooFastPulseCount >= BP_MIN_ROTOR_PULSES_FOR_MAX_SPEED ) ) { SET_ALARM_WITH_1_F32_DATA( ALARM_ID_HD_BLOOD_PUMP_ROTOR_SPEED_TOO_HIGH, rotorSpeed ) } @@ -1461,6 +1476,11 @@ result = TRUE; bloodPumpRotorSpeedRPM.ovData = value; bloodPumpRotorSpeedRPM.override = OVERRIDE_KEY; + // since override may occur while pump is actually stopped, may not get pulses to reach min pulse count for alarm + if ( value > BP_MAX_ROTOR_SPEED_RPM ) + { + bpRotorSpeedTooFastPulseCount = BP_MIN_ROTOR_PULSES_FOR_MAX_SPEED; + } } return result;