Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -rae4a44c74291d5891ef2a7f45320158e73fecbbc -rbe1f6ba8f58abfe098865c85ebca070eb0dde6ce --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision ae4a44c74291d5891ef2a7f45320158e73fecbbc) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision be1f6ba8f58abfe098865c85ebca070eb0dde6ce) @@ -92,6 +92,9 @@ #define SIZE_OF_ROLLING_AVG 20 ///< Number of pump speed samples in rolling average. +#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 + /// Enumeration of blood pump controller states. typedef enum BloodPump_States { @@ -131,6 +134,7 @@ static OVERRIDE_F32_T measuredBloodFlowRate; ///< Measured (calculated now) blood flow rate. static OVERRIDE_F32_T bloodPumpRotorSpeedRPM; ///< Measured blood pump rotor speed. static OVERRIDE_F32_T bloodPumpSpeedRPM; ///< Measured blood pump motor speed. +static OVERRIDE_F32_T bloodPumpTorquemNm; ///< Measured blood pump torque in mNm. static F32 rpmReadings[ SIZE_OF_ROLLING_AVG ]; ///< Holds RPM samples for a rolling average. static U32 rpmReadingsIdx; ///< Index for next sample in rolling average array. @@ -167,6 +171,7 @@ static F32 getBPFlowWearBTerm( void ); static void resetBloodPumpRPMMovingAverage( void ); static void filterBloodPumpRPMReadings( F32 rpm ); +static F32 calcBloodPumpTorque( void ); static void publishBloodFlowData( void ); @@ -219,6 +224,10 @@ bloodPumpRotorCounter.ovData = 0; bloodPumpRotorCounter.ovInitData = 0; bloodPumpRotorCounter.override = OVERRIDE_RESET; + bloodPumpTorquemNm.data = 0.0F; + bloodPumpTorquemNm.ovData = 0.0F; + bloodPumpTorquemNm.ovInitData = 0.0F; + bloodPumpTorquemNm.override = OVERRIDE_RESET; bpFlowAlphaYIntercept.data = BP_FLOW_ALPHA_Y_INTERCEPT; bpFlowAlphaYIntercept.ovData = BP_FLOW_ALPHA_Y_INTERCEPT; bpFlowAlphaYIntercept.ovInitData = BP_FLOW_ALPHA_Y_INTERCEPT; @@ -382,7 +391,7 @@ bloodPumpSetSpeedRPM = 0; isBloodPumpOn = FALSE; bpControlTimerCounter = 0; - setPeristalticPumpSetSpeed( bloodPumpSetSpeedRPM ); + setPeristalticPumpHardStop(); resetPIController( PI_CONTROLLER_ID_BLOOD_FLOW, 0.0F, 0.0F ); } @@ -468,7 +477,7 @@ { bloodPumpRotorCounter.data = 0; - if ( TRUE == getTestConfigStatus( TEST_CONFIG_USE_WORN_CARTRIDGE ) ) +// if ( TRUE == getTestConfigStatus( TEST_CONFIG_USE_WORN_CARTRIDGE ) ) { bloodPumpRotorCounter.data = BP_MAX_ROTOR_COUNT_FOR_WEAR; } @@ -501,6 +510,7 @@ bloodPumpSpeedRPM.data = filteredBloodPumpSpeed; bloodPumpDirection = ( getMeasuredBloodPumpSpeed() < 0.0F ? MOTOR_DIR_REVERSE : MOTOR_DIR_FORWARD ); measuredBloodFlowRate.data = calcBloodFlow(); + bloodPumpTorquemNm.data = calcBloodPumpTorque(); // Do not start enforcing checks until out of init/POST mode TODO-add checks later // if ( opMode != MODE_INIT ) @@ -803,6 +813,21 @@ /*********************************************************************//** * @brief + * The getMeasuredBloodPumpTorque function gets the measured blood pump + * torque in mN.m. + * @details \b Inputs: bloodPumpTorquemNm + * @details \b Outputs: none + * @return the current blood pump torque (in mN.m). + *************************************************************************/ +F32 getMeasuredBloodPumpTorque( void ) +{ + F32 result = getF32OverrideValue( &bloodPumpTorquemNm ); + + return result; +} + +/*********************************************************************//** + * @brief * The getBPFlowAlphaYIntercept function gets the blood pump flow alpha * intercept for blood flow estimation. * @details \b Inputs: bpFlowAlphaYIntercept @@ -865,13 +890,13 @@ TD_OP_MODE_T opMode = getCurrentOperationMode(); U32 hallSensor = 0; // TODO gioGetBit( hetPORT1, BP_ROTOR_HALL_SENSOR_NHET_ID ); - payload.h4SetFlowRate = targetBloodFlowRate; - payload.h4MeasFlow = getMeasuredBloodFlowRate(); - payload.h4MeasRotorSpd = getMeasuredBloodPumpRotorSpeed(); - payload.h4MeasPumpSpd = getMeasuredBloodPumpSpeed(); - payload.h4MeasCurr = 0.0F; // TODO getMeasuredBloodPumpMCCurrent(); - payload.h4SetRPM = bloodPumpSetSpeedRPM; - payload.h4RotorCount = getBloodPumpRotorCount(); + payload.h4SetFlowRate = targetBloodFlowRate; + payload.h4MeasFlow = getMeasuredBloodFlowRate(); + payload.h4MeasRotorSpd = getMeasuredBloodPumpRotorSpeed(); + payload.h4MeasPumpSpd = getMeasuredBloodPumpSpeed(); + payload.h4MeasTorquemNm = getMeasuredBloodPumpTorque(); + payload.h4SetRPM = bloodPumpSetSpeedRPM; + payload.h4RotorCount = getBloodPumpRotorCount(); if ( ( MODE_PRET == opMode ) || ( MODE_TREA == opMode ) || ( MODE_POST == opMode ) ) { // prescribed flow only available in treatment modes payload.h4PresFlow = getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ); @@ -928,6 +953,25 @@ /*********************************************************************//** * @brief + * The calcBloodPumpTorque function calculates the blood pump's torque from + * the resolution count. + * @details \b Inputs: none + * @details \b Outputs: none + * @return calculated blood pump torque (mN.m) + *************************************************************************/ +static F32 calcBloodPumpTorque( void ) +{ + F32 torqueResolutionUS = (F32)getH4TorqueCount() * BP_TORQUE_PERIOD_RESOLUTION_US; + F32 torqueResolutionS = torqueResolutionUS / (F32)US_PER_SECOND; + F32 frequencyHz = 1.0F / torqueResolutionS; + F32 frequencyKHz = frequencyHz / (F32)HZ_PER_KHZ; + F32 torquemNm = frequencyKHz * BP_1KHZ_TO_TORQUE_CONVERSION_MNM; + + return torquemNm; +} + +/*********************************************************************//** + * @brief * The checkBloodPumpRotor function checks the rotor for the blood * pump. If pump is off or running very slowly, rotor speed will be set to zero. * @details \b Alarm: ALARM_ID_HD_BLOOD_PUMP_ROTOR_SPEED_TOO_HIGH if rotor speed @@ -1319,6 +1363,27 @@ /*********************************************************************//** * @brief + * The testHardStopBloodPump function hard stops the blood pump. + * @details \b Inputs: none + * @details \b Outputs: none + * @param message BP home command message from Dialin. + * @return TRUE if command successful, FALSE if not + *************************************************************************/ +BOOL testHardStopBloodPump( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( 0 == message->hdr.payloadLen ) + { + result = TRUE; + signalBloodPumpHardStop(); + } + + return result; +} + +/*********************************************************************//** + * @brief * The testBPFlowAlphaYInterceptOverride function overrides the Alpha Y * intercept of the blood flow estimation equation. * @details \b Inputs: none