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.