Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -r0f7e24faee00439d8d212de3bda6f94dcca40855 -r6eb873c4bc96fb22e85ac23aeee1c37e5366d731 --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 0f7e24faee00439d8d212de3bda6f94dcca40855) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 6eb873c4bc96fb22e85ac23aeee1c37e5366d731) @@ -136,13 +136,15 @@ static F32 bloodFlowCalGain = 1.0; ///< blood flow calibration gain. static F32 bloodFlowCalOffset = 0.0; ///< blood flow calibration offset. -static OVERRIDE_U32_T bloodFlowDataPublishInterval = { BLOOD_FLOW_DATA_PUB_INTERVAL, BLOOD_FLOW_DATA_PUB_INTERVAL, BLOOD_FLOW_DATA_PUB_INTERVAL, 0 }; ///< Interval (in ms) at which to publish blood flow data to CAN bus -static OVERRIDE_S32_T targetBloodFlowRate = { 0, 0, 0, 0 }; ///< requested blood flow rate -static OVERRIDE_F32_T measuredBloodFlowRate = { 0.0, 0.0, 0.0, 0 }; ///< measured blood flow rate -static OVERRIDE_F32_T bloodPumpRotorSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< measured blood pump rotor speed -static OVERRIDE_F32_T bloodPumpSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< measured blood pump motor speed -static OVERRIDE_F32_T adcBloodPumpMCSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< measured blood pump motor controller speed -static OVERRIDE_F32_T adcBloodPumpMCCurrentmA = { 0.0, 0.0, 0.0, 0 }; ///< measured blood pump motor controller current +/// Interval (in task intervals) at which to publish blood flow data to CAN bus. +static OVERRIDE_U32_T bloodFlowDataPublishInterval = { BLOOD_FLOW_DATA_PUB_INTERVAL, BLOOD_FLOW_DATA_PUB_INTERVAL, BLOOD_FLOW_DATA_PUB_INTERVAL, 0 }; +static OVERRIDE_S32_T targetBloodFlowRate = { 0, 0, 0, 0 }; ///< requested blood flow rate (mL/min) +static OVERRIDE_F32_T measuredBloodFlowRate = { 0.0, 0.0, 0.0, 0 }; ///< measured blood flow rate (mL/min) +static OVERRIDE_F32_T bloodPumpRotorSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< measured blood pump rotor speed (RPM) +static OVERRIDE_F32_T bloodPumpSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< measured blood pump motor speed (RPM) +static OVERRIDE_F32_T adcBloodPumpMCSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< measured blood pump motor controller speed (RPM) +static OVERRIDE_F32_T adcBloodPumpMCCurrentmA = { 0.0, 0.0, 0.0, 0 }; ///< measured blood pump motor controller current (mA) +static OVERRIDE_F32_T bloodFlowSignalStrength = { 0.0, 0.0, 0.0, 0 }; ///< measured blood flow signal strength (%) static U32 bpControlTimerCounter = 0; ///< determines when to perform control on blood flow @@ -408,7 +410,8 @@ F32 bpFlow = ( ( getFPGABloodFlow() * -1.0 ) * bloodFlowCalGain ) + bloodFlowCalOffset; // blood flow sensor installed backwards on HD adcBloodPumpMCSpeedRPM.data = (F32)(SIGN_FROM_12_BIT_VALUE(bpRPM)) * BP_SPEED_ADC_TO_RPM_FACTOR; - adcBloodPumpMCCurrentmA.data = (F32)(SIGN_FROM_12_BIT_VALUE(bpmA)) * BP_CURRENT_ADC_TO_MA_FACTOR; + adcBloodPumpMCCurrentmA.data = (F32)(SIGN_FROM_12_BIT_VALUE(bpmA)) * BP_CURRENT_ADC_TO_MA_FACTOR; + bloodFlowSignalStrength.data = getFPGABloodFlowSignalStrength(); filterBloodFlowReadings( bpFlow ); @@ -753,6 +756,26 @@ return result; } +/*********************************************************************//** + * @brief + * The getMeasuredBloodFlowSignalStrength function gets the measured blood flow + * signal strength. + * @details Inputs: bloodFlowSignalStrength + * @details Outputs: none + * @return the current blood flow signal strength (in %). + *************************************************************************/ +F32 getMeasuredBloodFlowSignalStrength( void ) +{ + F32 result = bloodFlowSignalStrength.data; + + if ( OVERRIDE_KEY == bloodFlowSignalStrength.override ) + { + result = bloodFlowSignalStrength.ovData; + } + + return result; +} + /*********************************************************************//** * @brief * The getMeasuredBloodPumpRotorSpeed function gets the measured blood flow @@ -850,33 +873,19 @@ static void publishBloodFlowData( void ) { // publish blood flow data on interval -#ifndef FLOW_DEBUG if ( ++bloodFlowDataPublicationTimerCounter >= getPublishBloodFlowDataInterval() ) -#endif - { - S32 flowStPt = (S32)getTargetBloodFlowRate(); - F32 measFlow = getMeasuredBloodFlowRate(); - F32 measRotSpd = getMeasuredBloodPumpRotorSpeed(); - F32 measSpd = getMeasuredBloodPumpSpeed(); - F32 measMCSpd = getMeasuredBloodPumpMCSpeed(); - F32 measMCCurr = getMeasuredBloodPumpMCCurrent(); - F32 pumpPWMPctDutyCycle = bloodPumpPWMDutyCyclePctSet * FRACTION_TO_PERCENT_FACTOR; -#ifdef FLOW_DEBUG - // TODO - temporary debug code - remove later - char debugFlowStr[ 256 ]; - - F32 measFlowSig = getFPGABloodFlowSignalStrength() * 100.0; - F32 dialFlow = getMeasuredDialInFlowRate(); - F32 dialFlowSig = getFPGADialysateFlowSignalStrength() * 100.0; - F32 bldOccl = getMeasuredBloodPumpOcclusion(); - F32 dpiOccl = getMeasuredDialInPumpOcclusion(); - F32 dpoOccl = getMeasuredDialOutPumpOcclusion(); - - sprintf( debugFlowStr, "Blood: %5.1f, %6.1f, %6.1f Dial-I: %5.1f, %6.1f, %6.1f Dial-O: %6.1f\n", measFlowSig, measFlow, bldOccl, dialFlowSig, dialFlow, dpiOccl, dpoOccl ); - sendDebugData( (U08*)debugFlowStr, strlen(debugFlowStr) ); -#else - broadcastBloodFlowData( flowStPt, measFlow, measRotSpd, measSpd, measMCSpd, measMCCurr, pumpPWMPctDutyCycle ); -#endif + { + BLOOD_PUMP_STATUS_PAYLOAD_T payload; + + payload.setPoint = (S32)getTargetBloodFlowRate(); + payload.measFlow = getMeasuredBloodFlowRate(); + payload.measRotorSpd = getMeasuredBloodPumpRotorSpeed(); + payload.measPumpSpd = getMeasuredBloodPumpSpeed(); + payload.measMCSpd = getMeasuredBloodPumpMCSpeed(); + payload.measMCCurr = getMeasuredBloodPumpMCCurrent(); + payload.pwmDC = bloodPumpPWMDutyCyclePctSet * FRACTION_TO_PERCENT_FACTOR; + payload.flowSigStrength = getMeasuredBloodFlowSignalStrength() * 100.0; + broadcastBloodFlowData( payload ); bloodFlowDataPublicationTimerCounter = 0; } } @@ -1014,14 +1023,22 @@ if ( BLOOD_PUMP_CONTROL_TO_TARGET_STATE == bloodPumpState ) { - // check set direction vs. direction from hall sensors or sign of motor controller speed - bpMCDir = ( getMeasuredBloodPumpMCSpeed() >= 0.0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); - if ( ( bloodPumpDirectionSet != bpMCDir ) || ( bloodPumpDirectionSet != bpMotorDirectionFromHallSensors ) ) + bpMCDir = ( getMeasuredBloodPumpMCSpeed() >= 0.0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); + + // check set direction vs. direction from hall sensors + if ( bloodPumpDirectionSet != bpMotorDirectionFromHallSensors ) { #ifndef DISABLE_PUMP_DIRECTION_CHECKS SET_ALARM_WITH_2_U32_DATA( ALARM_ID_BLOOD_PUMP_MC_DIRECTION_CHECK, (U32)bloodPumpDirectionSet, (U32)bpMotorDirectionFromHallSensors ) #endif } + // check set direction vs. direction from sign of motor controller speed + if ( bloodPumpDirectionSet != bpMCDir ) + { +#ifndef DISABLE_PUMP_DIRECTION_CHECKS + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_BLOOD_PUMP_MC_DIRECTION_CHECK, (U32)bloodPumpDirectionSet, (U32)bpMCDir ) +#endif + } } } @@ -1040,7 +1057,7 @@ *************************************************************************/ static void checkBloodPumpSpeeds( void ) { - F32 measMotorSpeed = getMeasuredBloodPumpSpeed(); + F32 measMotorSpeed = fabs( getMeasuredBloodPumpSpeed() ); S32 cmdRate = getTargetBloodFlowRate(); // check for pump running while commanded off @@ -1651,5 +1668,50 @@ return result; } + +/*********************************************************************//** + * @brief + * The testSetMeasuredBloodFlowSignalStrengthOverride function overrides the measured + * blood flow signal strength. + * @details Inputs: none + * @details Outputs: bloodFlowSignalStrength + * @param value override measured blood flow signal strength (in %) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetMeasuredBloodFlowSignalStrengthOverride( F32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + bloodFlowSignalStrength.ovData = value / 100.0; + bloodFlowSignalStrength.override = OVERRIDE_KEY; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetMeasuredBloodFlowSignalStrengthOverride function resets the override + * of the measured blood flow signal strength. + * @details Inputs: none + * @details Outputs: bloodFlowSignalStrength + * @return TRUE if reset successful, FALSE if not + *************************************************************************/ +BOOL testResetMeasuredBloodFlowSignalStrengthOverride( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + bloodFlowSignalStrength.override = OVERRIDE_RESET; + bloodFlowSignalStrength.ovData = bloodFlowSignalStrength.ovInitData; + } + + return result; +} /**@}*/