Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -rcc83f1a731c6e5d149bd2822dc0ae45463295c5a -rbfbe825bef1c8544c37c20bbeaf61c0c27356096 --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision cc83f1a731c6e5d149bd2822dc0ae45463295c5a) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision bfbe825bef1c8544c37c20bbeaf61c0c27356096) @@ -94,6 +94,9 @@ #define BP_TORQUE_PERIOD_RESOLUTION_US 1.0F ///< Blood pump torque period resolution in microseconds (1 us). #define BP_1KHZ_TO_TORQUE_CONVERSION_MNM 10.0F ///< Blood pump 1kHz to torque conversion in milli-newtonmeter +#define BP_ZERO_SPEED_THRESHOLD_RPM 0.01F ///< Blood pump threshold in rpm +#define BP_ZERO_FLOW_THRESHOLD_ML_MIN 0.01F ///< Blood pump zero flow threshold in ml. + /// Enumeration of blood pump controller states. typedef enum BloodPump_States { @@ -519,8 +522,24 @@ filterBloodPumpRPMReadings( getPeristalticPumpMeasSpeed() ); bloodPumpSpeedRPM.data = filteredBloodPumpSpeed; + + // Remove small floating point residuals when the pump is stopped. + if ( fabs( bloodPumpSpeedRPM.data ) < BP_ZERO_SPEED_THRESHOLD_RPM ) + { + bloodPumpSpeedRPM.data = 0.0F; + } bloodPumpDirection = ( getMeasuredBloodPumpSpeed() < 0.0F ? MOTOR_DIR_REVERSE : MOTOR_DIR_FORWARD ); + + // Update calculated blood-flow rate. measuredBloodFlowRate.data = calcBloodFlow(); + + // Remove small floating-point residuals from calculated flow. + if ( fabs( measuredBloodFlowRate.data ) < BP_ZERO_FLOW_THRESHOLD_ML_MIN ) + { + measuredBloodFlowRate.data = 0.0F; + } + + // Update measured torque. bloodPumpTorquemNm.data = calcBloodPumpTorque(); // Do not start enforcing checks until out of init/POST mode TODO-add checks later @@ -539,6 +558,7 @@ // } } + /*********************************************************************//** * @brief * The execBloodFlowController function executes the blood flow controller. Index: firmware/App/Drivers/PeristalticPump.c =================================================================== diff -u -r2bf661ae63145fbf02329d96fecb32b0aa7dbb44 -rbfbe825bef1c8544c37c20bbeaf61c0c27356096 --- firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision 2bf661ae63145fbf02329d96fecb32b0aa7dbb44) +++ firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision bfbe825bef1c8544c37c20bbeaf61c0c27356096) @@ -100,7 +100,7 @@ U16 rotorRevsNow = getH4RotorRevsCounter(); // Update measured pump motor speed. - if ( ( H4_ZERO_SPEED_PERIOD == period ) || ( H4_INVALID_SPEED_PERIOD == period ) ) + if ( ( 0 == period ) || ( H4_INVALID_SPEED_PERIOD == period ) || ( H4_ZERO_SPEED_PERIOD == period ) ) { pumpMeasSpeedRPM = 0.0F; }