Index: firmware/App/Modes/BloodPrime.c =================================================================== diff -u -r6b870cd0699bb3ee22b93981d51373a6c2d56162 -r44a100f8e5210a02c23b8fcc4527d8e96d577381 --- firmware/App/Modes/BloodPrime.c (.../BloodPrime.c) (revision 6b870cd0699bb3ee22b93981d51373a6c2d56162) +++ firmware/App/Modes/BloodPrime.c (.../BloodPrime.c) (revision 44a100f8e5210a02c23b8fcc4527d8e96d577381) @@ -23,6 +23,7 @@ #include "ModeTreatment.h" #include "ModeTreatmentParams.h" #include "OperationModes.h" +#include "SyringePump.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" #include "Utilities.h" @@ -38,10 +39,13 @@ // TODO - get from Systems when available #define TARGET_BLOOD_PRIME_VOLUME_ML 300.0 ///< Target blood prime volume to prime the blood side circuit (in mL). #define MIN_RAMP_TIME_SEC 60 ///< Minimum ramp time for blood prime (in seconds). + +#ifndef DISABLE_PUMP_FLOW_CHECKS /// Maximum blood prime volume measured by independent means (as % of target). static const F32 MAX_BLOOD_PRIME_SAFETY_VOLUME_ML = ( TARGET_BLOOD_PRIME_VOLUME_ML * 1.2 ); /// Minimum blood prime volume measured by independent means (as % of target). static const F32 MIN_BLOOD_PRIME_SAFETY_VOLUME_ML = ( TARGET_BLOOD_PRIME_VOLUME_ML * 0.8 ); +#endif /// Initial flow rate for blood pump when starting blood prime operation. #define BLOOD_PRIME_INIT_BP_FLOW_RATE_ML_MIN 100 @@ -66,7 +70,7 @@ static U32 bloodPrimePublishTimerCtr; ///< Timer counter for determining interval for blood prime status to be published. static F32 cumulativeBloodPrimeVolume_mL; ///< Total cumulative blood prime volume (in mL). -static U32 bloodPrimeMotorCount; ///< The cumulative sum of BP motor encoder counts used for independent blood prime volume check. +static S32 bloodPrimeMotorCount; ///< The cumulative sum of BP motor encoder counts used for independent blood prime volume check. static U32 bloodPrimeLastMotorCount; ///< The last BP motor encoder count read for independent blood prime volume check. static F32 bloodPrimeVolumeDelivered_Safety; ///< The cumulative independent blood prime volume (in mL) calculated so far. @@ -150,7 +154,8 @@ // Ensure dialysate outlet and Heparin pumps are stopped signalDialOutPumpHardStop(); - // TODO - stop Heparin pump + stopSyringePump(); + // start blood and dialysate inlet pumps setBloodPumpTargetFlowRate( BLOOD_PRIME_INIT_BP_FLOW_RATE_ML_MIN, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); setDialInPumpTargetFlowRate( DIALYSATE_FLOW_RATE_FOR_RECIRC, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); @@ -203,14 +208,11 @@ static BLOOD_PRIME_STATE_T handleBloodPrimeRampState( void ) { BLOOD_PRIME_STATE_T result = BLOOD_PRIME_RAMP_STATE; - U32 bldPumpMotorCount = getBloodPumpMotorCount(); - U32 bldPumpMotorDelta = u32DiffWithWrap( bloodPrimeLastMotorCount, bldPumpMotorCount ); - // update blood prime volume delivered so far + // Update blood prime volume delivered so far cumulativeBloodPrimeVolume_mL += ( getMeasuredBloodFlowRate() * BLOOD_PRIME_FLOW_INTEGRATOR ); - // update independent calculated safety volume delivered so far - bloodPrimeMotorCount += bldPumpMotorDelta; - bloodPrimeLastMotorCount = bldPumpMotorCount; + // Update independent calculated safety volume delivered so far + bloodPrimeMotorCount = u32BiDiffWithWrap( bloodPrimeLastMotorCount, getBloodPumpMotorCount() ) / BP_HALL_EDGE_COUNTS_PER_REV; bloodPrimeVolumeDelivered_Safety = ( (F32)bloodPrimeMotorCount * VOLUME_PER_BP_MOTOR_REV_ML ); // TODO - include upstream pressure compensation to this calc // Has blood prime completed? @@ -241,9 +243,14 @@ // ramp blood pump on ramp interval if ( ++bloodPrimeRampControlTimerCtr >= BLOOD_PRIME_RAMPING_INTERVAL ) { + U32 setBPRate = getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ); + bloodPrimeRampControlTimerCtr = 0; - bloodPrimeRampFlowRate_mL_min += bloodPrimeRampStep_mL; - setBloodPumpTargetFlowRate( (U32)bloodPrimeRampFlowRate_mL_min, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + if ( bloodPrimeRampFlowRate_mL_min < (F32)setBPRate ) + { + bloodPrimeRampFlowRate_mL_min += bloodPrimeRampStep_mL; + setBloodPumpTargetFlowRate( (U32)bloodPrimeRampFlowRate_mL_min, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); + } } }