Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -r5545719a6bde1e93991c25918d975024b44c1b43 -r056ef172979282cacadfe7a58842821ea431cc50 --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 5545719a6bde1e93991c25918d975024b44c1b43) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 056ef172979282cacadfe7a58842821ea431cc50) @@ -59,7 +59,7 @@ /// Interval (ms/task time) at which the blood pump speed is calculated (every 40 ms). #define BP_SPEED_CALC_INTERVAL ( 40 / TASK_PRIORITY_INTERVAL ) /// Number of hall sensor counts kept in buffer to hold last 1 second of count data. -#define BP_SPEED_CALC_BUFFER_LEN ( 1000 / BP_SPEED_CALC_INTERVAL / TASK_PRIORITY_INTERVAL ) +#define BP_SPEED_CALC_BUFFER_LEN ( MS_PER_SECOND / BP_SPEED_CALC_INTERVAL / TASK_PRIORITY_INTERVAL ) #define BP_MAX_ROTOR_SPEED_RPM 100.0 ///< Maximum rotor speed allowed for blood pump. #define BP_MAX_FLOW_VS_SPEED_DIFF_RPM 200.0 ///< Maximum difference between measured speed and speed implied by measured flow. Index: firmware/App/Controllers/SyringePump.c =================================================================== diff -u -r8d1ae378f26055b881c2b06b7163997d858b1342 -r056ef172979282cacadfe7a58842821ea431cc50 --- firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision 8d1ae378f26055b881c2b06b7163997d858b1342) +++ firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision 056ef172979282cacadfe7a58842821ea431cc50) @@ -35,8 +35,6 @@ /// Default publication interval for syringe pump data. #define SYRINGE_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) -/// Speed check interval. -#define SYRINGE_PUMP_SPEED_CHECK_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) #define BD_SYRINGE_ID_RADIUS_CM ( 1.402 / 2.0 ) ///< Radius from inner diameter (in cm) of supported BD syringe. /// Milliliters per mm of syringe plunger travel. @@ -71,7 +69,7 @@ #define SYRINGE_PUMP_PRIME_RATE 635.0 ///< Prime rate is 0.5 mm ^ 2 x PI x 450 mm = 0.353 mL / 2s = 635 mL/hr. #define SYRINGE_PUMP_MAX_RATE 11000.0 ///< Maximum rate of the syringe pump (in mL/hr). -#define SYRINGE_PUMP_RATE_ALARM_PERSISTENCE 3000 ///< Alarm persistence period (in ms) for syringe pump speed check alarms. +#define SYRINGE_PUMP_RATE_ALARM_PERSISTENCE 1000 ///< Alarm persistence period (in ms) for syringe pump speed check alarms. #define SYRINGE_PUMP_DIR_ALARM_PERSISTENCE 1000 ///< Alarm persistence period (in ms) for syringe pump direction check alarms. #define SYRINGE_PUMP_OFF_ALARM_PERSISTENCE 500 ///< Alarm persistence period (in ms) for syringe pump off check alarms. #define SYRINGE_PUMP_OCCLUSION_ALARM_PERSISTENCE 30 ///< Alarm persistence period (in ms) for syringe pump occlusion alarms. @@ -147,7 +145,12 @@ #define SYRINGE_PUMP_ENCODER_DIRECTION_ERROR_BITS 0x3F ///< Syringe pump encoder direction error counter bits in FPGA register. #define SYRINGE_PUMP_ENCODER_DIRECTION_BIT 0x80 ///< Syringe pump encoder direction bit in FPGA register. -#define SYRINGE_PUMP_RAMP_STALL_TIME ( 1500 / TASK_PRIORITY_INTERVAL ) ///< Syringe pump ramp stall timeout. +/// Interval (ms/task time) at which the syringe pump speed is calculated (every 40 ms). +#define SYRINGE_PUMP_SPEED_CALC_INTERVAL ( 40 / TASK_PRIORITY_INTERVAL ) +/// Number of syringe pump encoder positions kept in buffer to hold last 1 second of position data. +#define SYRINGE_PUMP_SPEED_CALC_BUFFER_LEN ( MS_PER_SECOND / SYRINGE_PUMP_SPEED_CALC_INTERVAL / TASK_PRIORITY_INTERVAL ) + +#define SYRINGE_PUMP_RAMP_STALL_TIME ( 500 / TASK_PRIORITY_INTERVAL ) ///< Syringe pump ramp stall timeout. #define SYRINGE_PUMP_RAMP_STALL_RETRIES 3 ///< Syringe pump ramp stall retries allowed. #define SYRINGE_PUMP_STALL_SPEED_THRESHOLD 0.05 ///< Minimum syringe pump speed to be considered not stalled. @@ -169,7 +172,6 @@ static SYRINGE_PUMP_STATE_T syringePumpState; ///< Current state of syringe pump control state machine. static U32 syringePumpDataPublicationTimerCounter; ///< Used to schedule syringe pump data publication to CAN bus. -static U32 syringePumpSpeedCalcTimerCounter; ///< Used to calculate measured rate from change in position over time. static U32 syringePumpRampTimerCtr; ///< Used to track ramp up time. static HEPARIN_STATE_T heparinDeliveryState; ///< Current state of Heparin delivery. @@ -193,7 +195,9 @@ static S32 syringePumpVolumeStartPosition; ///< Start position for the current volume calculation. static S32 syringePumpHomePositionOffset; ///< FPGA reported position when at home postion. static S32 syringePumpLastPosition; ///< Position previously recorded. -static S32 syringePumpPosition1SecAgo; ///< Position recorded at last 1 Hz speed check. +static S32 syringePumpLastPositions[ SYRINGE_PUMP_SPEED_CALC_BUFFER_LEN ]; ///< Last encoder positions for the syringe pump. +static U32 syringePumpMotorSpeedCalcIdx; ///< Index into 1 second buffer of syringe pump encoder positions. +static U32 syringePumpSpeedCalcTimerCounter; ///< Used to calculate measured rate from change in position over time. static MOTOR_DIR_T syringePumpControllerMeasuredDirection; ///< Measured direction of syringe pump per controller. static MOTOR_DIR_T syringePumpEncoderMeasuredDirection; ///< Measured direction of syringe pump per encoder position relative to previous. @@ -261,6 +265,8 @@ *************************************************************************/ void initSyringePump( void ) { + U32 i; + syringePumpState = SYRINGE_PUMP_INIT_STATE; heparinDeliveryState = HEPARIN_STATE_OFF; @@ -270,7 +276,6 @@ syringePumpVolumeStartPosition = 0; syringePumpHomePositionOffset = 0; syringePumpLastPosition = 0; - syringePumpPosition1SecAgo = 0; syringePumpControllerMeasuredDirection = MOTOR_DIR_FORWARD; syringePumpEncoderMeasuredDirection = MOTOR_DIR_FORWARD; @@ -285,6 +290,13 @@ lastSyringePumpADCReadCtr = 0; + // Zero pump position counts buffer + syringePumpMotorSpeedCalcIdx = 0; + for ( i = 0; i < SYRINGE_PUMP_SPEED_CALC_BUFFER_LEN; i++ ) + { + syringePumpLastPositions[ i ] = 0; + } + syringePumpStallCtr = 0; syringePumpStallRetryCount = 0; @@ -1630,23 +1642,35 @@ return result; } +/*********************************************************************//** + * @brief + * The checkForStall function checks whether the syringe pump has stalled. + * If stall detected, the ramp up will be restarted up to 3 times. + * If cannot resolve the stall within 3 retries, a stall fault is triggered. + * @details Inputs: syringePumpMeasRate.data, syringePumpStallCtr, syringePumpStallRetryCount + * @details Outputs: syringePumpStallCtr, syringePumpStallRetryCount + * @param stopPump flag passed in by caller indicating whether pump should be stopped + * @return TRUE if pump should be stopped, FALSE if not +*************************************************************************/ static BOOL checkForStall( BOOL stopPump ) { + BOOL result = stopPump; + // Check for stall if ( fabs( getSyringePumpMeasRate() ) < SYRINGE_PUMP_STALL_SPEED_THRESHOLD ) { if ( ++syringePumpStallCtr > SYRINGE_PUMP_RAMP_STALL_TIME ) { if ( ++syringePumpStallRetryCount <= SYRINGE_PUMP_RAMP_STALL_RETRIES ) { - syringePumpSetToggleTime++; // lower target rate + syringePumpSetToggleTime++; // lower target rate (by increasing time between steps) syringePumpRampTimerCtr = 0; // restart ramp syringePumpRampUpToggleTime = SYRINGE_PUMP_START_RAMP_SPEED; syringePumpStallCtr = 0; // reset stall counter } else { - stopPump = TRUE; + result = TRUE; SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SYRINGE_PUMP_STALL, (U32)getSyringePumpPosition(), (U32)syringePumpState ); } } @@ -1655,6 +1679,8 @@ { syringePumpStallCtr = 0; } + + return result; } /*********************************************************************//** @@ -1715,21 +1741,27 @@ /*********************************************************************//** * @brief * The calcMeasRate function calculates the measured rate from a given delta - * position in last 10 ms. - * @details Inputs: syringePumpPosition1SecAgo, syringePumpSpeedCalcTimerCounter + * position in last 1 sedond. + * @details Inputs: syringePumpLastPositions[], syringePumpSpeedCalcTimerCounter * @details Outputs: syringePumpMeasRate, syringePumpSpeedCalcTimerCounter * @return none *************************************************************************/ static void calcMeasRate( void ) { - if ( ++syringePumpSpeedCalcTimerCounter > SYRINGE_PUMP_SPEED_CHECK_INTERVAL ) + if ( ++syringePumpSpeedCalcTimerCounter > SYRINGE_PUMP_SPEED_CALC_INTERVAL ) { - S32 countsPerSec = syringePumpPosition.data - syringePumpPosition1SecAgo; + S32 pos = getSyringePumpPosition(); + U32 nextIdx = INC_WRAP( syringePumpMotorSpeedCalcIdx, 0, SYRINGE_PUMP_SPEED_CALC_BUFFER_LEN - 1 ); + S32 countsPerSec = pos - syringePumpLastPositions[ nextIdx ]; // Calc delta between pos 1 second ago and pos now S32 countsPerHr = countsPerSec * ( MIN_PER_HOUR * SEC_PER_MIN); F32 mLPerHr = (F32)countsPerHr / SYRINGE_ENCODER_COUNTS_PER_ML; + // Set latest measured rate syringePumpMeasRate.data = mLPerHr; - syringePumpPosition1SecAgo = syringePumpPosition.data; + + // Update last position for next time + syringePumpLastPositions[ nextIdx ] = pos; + syringePumpMotorSpeedCalcIdx = nextIdx; syringePumpSpeedCalcTimerCounter = 0; } } Index: firmware/App/HDCommon.h =================================================================== diff -u -r3250a641e46b5338671a5b830189ffb3694d1284 -r056ef172979282cacadfe7a58842821ea431cc50 --- firmware/App/HDCommon.h (.../HDCommon.h) (revision 3250a641e46b5338671a5b830189ffb3694d1284) +++ firmware/App/HDCommon.h (.../HDCommon.h) (revision 056ef172979282cacadfe7a58842821ea431cc50) @@ -25,7 +25,7 @@ #define HD_VERSION_MAJOR 0 #define HD_VERSION_MINOR 5 #define HD_VERSION_MICRO 0 -#define HD_VERSION_BUILD 9033 +#define HD_VERSION_BUILD 9036 // ********** development build switches ********** @@ -77,7 +77,7 @@ #define DISABLE_FPGA_COUNTER_CHECKS 1 // Disable alarms associated with FPGA read/error counters #define DISABLE_VOLTAGE_MONITOR 1 // Disable voltage monitoring/alarms #define ALLOW_1_MIN_TREATMENT_DURATION 1 // Allow user to change treatment duration to as low as 1 minute - #define SLOW_SYRINGE_RETRACT 1 // Slow retract speed to reduce chance of stall +// #define SLOW_SYRINGE_RETRACT 1 // Slow retract speed to reduce chance of stall #define DISABLE_SYRINGE_PUMP_ALARMS 1 // Disable some syringe pump alarms that are triggering intermittently #include