Index: firmware/App/Controllers/SyringePump.c =================================================================== diff -u -rae552ee28c425dccf069b1d80ce7f93a34c06063 -rf0c16ca7223ad48b7bdb86b8f010b74b550c0051 --- firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision ae552ee28c425dccf069b1d80ce7f93a34c06063) +++ firmware/App/Controllers/SyringePump.c (.../SyringePump.c) (revision f0c16ca7223ad48b7bdb86b8f010b74b550c0051) @@ -7,8 +7,8 @@ * * @file SyringePump.c * -* @author (last) Darren Cox -* @date (last) 01-May-2023 +* @author (last) Sean Nash +* @date (last) 16-Aug-2023 * * @author (original) Sean Nash * @date (original) 04-Mar-2021 @@ -69,7 +69,8 @@ #define SYRINGE_PUMP_DIR_ALARM_PERSISTENCE 3000 ///< Alarm persistence period (in ms) for syringe pump direction check alarms. #define SYRINGE_PUMP_OFF_ALARM_PERSISTENCE 1000 ///< Alarm persistence period (in ms) for syringe pump off check alarms. #define SYRINGE_PUMP_OFF_ERROR_MAX_CNT 10 ///< Maximum number of syringe pump not stopped errors within time window before alarm triggered. Do not exceed MAX_TIME_WINDOWED_COUNT. -#define SYRINGE_PUMP_OFF_ERROR_TIME_WIN_MS (1 * MS_PER_SECOND) ///< Time window for Syringe Pump not stopped error. +#define SYRINGE_PUMP_OFF_ERROR_TIME_WIN_MS ( 1 * MS_PER_SECOND ) ///< Time window for Syringe Pump not stopped error. +#define SYRINGE_PUMP_PRIMING_TIMEOUT_MS ( 5 * MS_PER_SECOND ) ///< Timeout for syringe pump prime operation. #define STEPS_TO_MICROSTEPS( s ) ( (s) * 32.0F ) ///< Macro conversion from steps to microsteps. #define MICROSTEPS_TO_STEPS( m ) ( (m) / 32.0F ) ///< Macro conversion from microsteps to steps. @@ -235,6 +236,7 @@ static BOOL syringeVolumeAdequate; ///< Flag indicates whether Heparin volume is sufficient to complete treatment. static BOOL syringePumpPrimeCompleted; ///< Flag indicates prime operation was completed. static BOOL syringePumpPreLoadCompleted; ///< Flag indicates preload operation was completed. +static U32 syringePumpStateStartTime; ///< Time current syringe pump state started. static BOOL syringePumpDACVrefWriteInProgress; ///< Flag indicates DAC Vref write is in progress. static F32 syringePumpDACVref; ///< DAC Vref setting for force sensor. @@ -314,6 +316,7 @@ syringePumpSpeedCalcTimerCounter = 0; syringePumpRampTimerCtr = 0; syringePumpSafetyVolumeDelivered = 0.0; + syringePumpStateStartTime = getMSTimerCount(); syringePumpPositionKnown = FALSE; syringePumpPlungerFound = FALSE; @@ -1113,6 +1116,7 @@ syringePumpPosition.data = encPosition - syringePumpHomePositionOffset; // Calculate volume delivered from position syringePumpVolumeDelivered.data = (F32)( syringePumpPosition.data - syringePumpVolumeStartPosition ) / SYRINGE_ENCODER_COUNTS_PER_ML; + syringePumpVolumeDelivered.data = MAX( syringePumpVolumeDelivered.data, 0.0F ); calcSafetyVolumeDelivered(); // Calculate measured rate (mL/hr) calcMeasRate(); @@ -1361,6 +1365,7 @@ // If we are starting an active pump state, set direction and calculate target toggle time to achieve desired rate if ( ( result != SYRINGE_PUMP_OFF_STATE ) && ( result != SYRINGE_PUMP_CONFIG_FORCE_SENSOR_STATE ) ) { + syringePumpStateStartTime = getMSTimerCount(); if ( SYRINGE_PUMP_RETRACT_STATE == result ) { // Set fpga direction to reverse @@ -1577,7 +1582,7 @@ * @brief * The handleSyringePumpPrimeState function handles the prime state * of the syringe pump control state machine. - * @details Inputs: syringePumpVolumeDelivered.data + * @details Inputs: syringePumpVolumeDelivered, syringePumpStateStartTime * @details Outputs: Syringe pump ramped up to prime rate, alarm conditions checked * @return next state *************************************************************************/ @@ -1599,6 +1604,16 @@ syringePumpVolumeStartPosition = syringePumpPosition.data; } + // Check for timeout + if ( TRUE == didTimeout( syringePumpStateStartTime, SYRINGE_PUMP_PRIMING_TIMEOUT_MS ) ) + { + stopPump = TRUE; + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_SYRINGE_PUMP_OCCLUSION, (F32)SYRINGE_PUMP_PRIMING_TIMEOUT_MS, 0.0F ) + } + + // Check for stall + stopPump = checkForStall( stopPump ); + // Has syringe been removed? stopPump = checkSyringeRemoved( stopPump ); @@ -1871,6 +1886,10 @@ SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_SYRINGE_PUMP_OCCLUSION, forceAtEndOfSeek, currentForceV ) result = TRUE; } + else + { + clearAlarmCondition( ALARM_ID_HD_SYRINGE_PUMP_OCCLUSION ); + } } // Check with persistence during continuous state @@ -2013,30 +2032,30 @@ 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 (by increasing time between steps) - syringePumpRampTimerCtr = 0; // restart ramp - syringePumpRampUpToggleTime = SYRINGE_PUMP_START_RAMP_SPEED; - syringePumpStallCtr = 0; // reset stall counter - } - else - { - result = TRUE; - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SYRINGE_PUMP_STALL, (U32)getSyringePumpPosition(), (U32)syringePumpState ); - } - } - } - else - { + 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 (by increasing time between steps) + syringePumpRampTimerCtr = 0; // restart ramp + syringePumpRampUpToggleTime = SYRINGE_PUMP_START_RAMP_SPEED; + syringePumpStallCtr = 0; // reset stall counter + } + else + { + result = TRUE; + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SYRINGE_PUMP_STALL, (U32)getSyringePumpPosition(), (U32)syringePumpState ); + } + } + } + else + { syringePumpStallCtr = 0; - } + } - return result; + return result; } /*********************************************************************//**