Index: firmware/App/Controllers/SyringePump.c =================================================================== diff -u -r9720002e46be11657ecdda735446c3f80165413b -rc9462de242e2d13fcc744817f24d7b6c141871bf --- firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision 9720002e46be11657ecdda735446c3f80165413b) +++ firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision c9462de242e2d13fcc744817f24d7b6c141871bf) @@ -83,7 +83,7 @@ #define SYRINGE_FORCE_PLUNGER_THRESHOLD_V 0.25F ///< Force sensor threshold (in V) above which we have engaged with plunger. #define SYRINGE_PUMP_SYRINGE_DETECT_THRESHOLD_V 2.0F ///< Syringe pump syringe detected threshold (in V). #define SYRINGE_PUMP_HOME_DETECT_THRESHOLD_V 0.25F ///< Syringe pump home detected threshold (in V). -#define SYRINGE_PUMP_PRIME_VOLUME_ML 0.353F ///< Target syringe prime volume (in mL). +#define SYRINGE_PUMP_EMPTY_THRESHOLD_V 2.5F ///< Syringe pump empty detected threshold (in V). #define SYRINGE_PUMP_PRELOAD_MARGIN_VOLUME_ML 1.0F ///< Target syringe preload margin volume (in mL). Total to deliver plus this give syringe load position. #define SYRINGE_PUMP_PRELOAD_MAX_VOLUME_ML 10.0F ///< Target syringe preload max volume (in mL). Leave at home position above this value. #define SYRINGE_PUMP_MAX_VOL_ERROR_ML 0.1F ///< Maximum Heparin volume error (in mL). @@ -93,6 +93,10 @@ #define SYRINGE_PUMP_DAC_VOLTAGE_MAX_ERROR 0.05F ///< Force sensor POST check for DAC voltage - max delta. #define MIN_SYRINGE_PUMP_RATE_FOR_DIR_ALARM 0.5F ///< Minimum measured rate (in mL/hr) required before enforcing direction alarm. +/// HW volume variance in the syringe pump in mL. +#define SYRINGE_PUMP_HW_TOLERANCE_ML 0.65F +/// HW volume variance in the syringe pump in encoder counts. +#define SYRINGE_PUMP_HW_TOLERANCE_POS ( SYRINGE_ENCODER_COUNTS_PER_ML * SYRINGE_PUMP_HW_TOLERANCE_ML ) /// Expected position of empty in relation to home position. #define SYRINGE_PUMP_EMPTY_POS ( SYRINGE_ENCODER_COUNTS_PER_ML * 11.0F ) /// Over-travel (past empty) allowance for alarm. @@ -158,8 +162,12 @@ #define SYRINGE_PUMP_STALL_SPEED_THRESHOLD 0.05F ///< Minimum syringe pump speed to be considered not stalled. #define SYRINGE_PUMP_ADC_FPGA_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Syringe pump ADC FPGA error timeout in milliseconds. + #define SYRINGE_PUMP_DAC_MAX_RETRIES 5 ///< Syringe pump DAC retries to write. #define SYRINGE_PUMP_DAC_TIMER ( 200 / TASK_PRIORITY_INTERVAL ) ///< Syringe pump DAC timer between retries. +#define SYRINGE_PUMP_OCCLUSION_PERSISTENCE 50 ///< Syringe pump occlusion persistence timer. +#define SYRINGE_PUMP_EMPTY_FORCE_COUNT 5 ///< Syringe pump empty force voltage count persistence. + /// Defined states for the syringe pump control state machine. typedef enum SyringePump_States { @@ -240,6 +248,8 @@ static U32 syringePumpDACRetryCount; static U32 syringePumpDACRetryTimer; +static U32 syringePumpEmptyForceCount; + // ********** private function prototypes ********** static void resetSyringePumpRequestFlags( void ); @@ -313,7 +323,7 @@ syringePumpPrimeCompleted = FALSE; syringePumpPreLoadCompleted = FALSE; syringePumpRampUpPct = 0.0; - + syringePumpEmptyForceCount = 0; // Zero pump position counts buffer syringePumpMotorSpeedCalcIdx = 0; for ( i = 0; i < SYRINGE_PUMP_SPEED_CALC_BUFFER_LEN; i++ ) @@ -331,6 +341,7 @@ initPersistentAlarm( ALARM_ID_HD_SYRINGE_PUMP_CONTROLLER_DIRECTION_ERROR, 0, SYRINGE_PUMP_DIR_ALARM_PERSISTENCE ); initPersistentAlarm( ALARM_ID_HD_SYRINGE_PUMP_RUNNING_WHILE_BP_OFF_ERROR, 0, SYRINGE_PUMP_OFF_ALARM_PERSISTENCE ); initPersistentAlarm( ALARM_ID_HD_SYRINGE_PUMP_SPEED_ERROR, 0, SYRINGE_PUMP_RATE_ALARM_PERSISTENCE ); + initPersistentAlarm( ALARM_ID_HD_SYRINGE_PUMP_OCCLUSION, 0, SYRINGE_PUMP_OCCLUSION_PERSISTENCE); initTimeWindowedCount( TIME_WINDOWED_COUNT_SYRINGE_PUMP_OFF_ERROR, SYRINGE_PUMP_OFF_ERROR_MAX_CNT, SYRINGE_PUMP_OFF_ERROR_TIME_WIN_MS ); initFPGAPersistentAlarm( FPGA_PERS_ERROR_SYRINGE_PUMP_ADC, ALARM_ID_HD_SYRINGE_PUMP_FPGA_ADC_FAULT, @@ -1459,8 +1470,8 @@ F32 txVolumeReq = SYRINGE_PUMP_PRIME_VOLUME_ML + bolusVol + ( hepDurHr * contRate ); F32 syringeVol = ( SYRINGE_PUMP_EMPTY_POS - (F32)pos ) / SYRINGE_ENCODER_COUNTS_PER_ML; - syringePumpVolumeRequired = txVolumeReq; - txVolumeReq = txVolumeReq + SYRINGE_PUMP_PRELOAD_MARGIN_VOLUME_ML; + syringePumpVolumeRequired = txVolumeReq + SYRINGE_PUMP_FILL_VOLUME_OFFSET_ML; + txVolumeReq = txVolumeReq + SYRINGE_PUMP_FILL_VOLUME_OFFSET_ML + SYRINGE_PUMP_PRELOAD_MARGIN_VOLUME_ML; // Handle ramp up rampSyringePump(); @@ -1680,6 +1691,8 @@ // Has syringe been removed? stopPump = checkSyringeRemoved( stopPump ); + stopPump = checkForSyringeOcclusion(); + // Check for syringe pump empty stopPump = checkSyringeEmpty( stopPump ); @@ -1813,8 +1826,18 @@ F32 force = getSyringePumpForceV(); S32 pos = getSyringePumpPosition(); + if ( force >= SYRINGE_PUMP_EMPTY_THRESHOLD_V ) + { + syringePumpEmptyForceCount++; + } + else + { + syringePumpEmptyForceCount = 0; + } // If near empty position, assume syringe is empty - if ( pos >= SYRINGE_PUMP_EMPTY_POS ) + // Check for force threshold over some time and within SYRINGE_PUMP_HW_TOLERANCE_POS of empty + if ( ( pos >= SYRINGE_PUMP_EMPTY_POS ) || + ( ( syringePumpEmptyForceCount >= SYRINGE_PUMP_EMPTY_FORCE_COUNT ) && ( pos >= ( SYRINGE_PUMP_EMPTY_POS - SYRINGE_PUMP_HW_TOLERANCE_POS ) ) ) ) { heparinDeliveryState = HEPARIN_STATE_EMPTY; SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_SYRINGE_PUMP_SYRINGE_EMPTY, (F32)pos, force ) @@ -1832,19 +1855,29 @@ * @details Outputs: alarm triggered if max force detected * @return TRUE if pump should be stopped, FALSE if not *************************************************************************/ -BOOL checkForPrimeOcclusion( void ) +BOOL checkForSyringeOcclusion( void ) { BOOL result = FALSE; // Return FALSE if no occlusion is detected F32 forceAtEndOfPriming = getSyringePumpForceV(); // Read the force sensor at the end of the priming F32 forceDelta = forceAtEndOfPriming - forceAtEndOfSeek; // Occlusion is detected if force at end of prime is > than force at end of seek by 0.5 volts or more BOOL occlusionDetected = ( forceDelta >= SYRINGE_FORCE_OCCLUSION_DIFF_V ? TRUE : FALSE ); - if ( TRUE == occlusionDetected ) + // Checking for occlusion in dry self tests without persistence + if ( MODE_PRET == getCurrentOperationMode() ) { - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_SYRINGE_PUMP_OCCLUSION, forceAtEndOfSeek, forceAtEndOfPriming ) - result = TRUE; + if ( TRUE == occlusionDetected ) + { + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_SYRINGE_PUMP_OCCLUSION, forceAtEndOfSeek, forceAtEndOfPriming ) + result = TRUE; + } } + // Check with persistence during continuous state + if ( SYRINGE_PUMP_OP_CONTINUOUS == syringePumpState ) + { + checkPersistentAlarm( ALARM_ID_HD_SYRINGE_PUMP_OCCLUSION, occlusionDetected, forceAtEndOfSeek, forceAtEndOfPriming ); + } + return result; }