Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -re64816def7cd98e7dcb6d133b3a56c9fea835af3 -rb9eccdfcf1727112664b85977a16a18811b9fde7 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision e64816def7cd98e7dcb6d133b3a56c9fea835af3) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision b9eccdfcf1727112664b85977a16a18811b9fde7) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2021 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * -* @file DialInFlow.c +* @file DialInFlow.c * -* @author (last) Sean Nash -* @date (last) 13-Oct-2020 +* @author (last) Dara Navaei +* @date (last) 06-Nov-2021 * -* @author (original) Sean -* @date (original) 16-Dec-2019 +* @author (original) Sean +* @date (original) 16-Dec-2019 * ***************************************************************************/ @@ -29,7 +29,8 @@ #include "PersistentAlarm.h" #include "PIControllers.h" #include "SafetyShutdown.h" -#include "SystemCommMessages.h" +#include "SystemCommMessages.h" +#include "SystemComm.h" #include "TaskGeneral.h" #include "TaskPriority.h" #include "Timers.h" @@ -65,7 +66,7 @@ #define DIP_MAX_FLOW_RATE 1320.0 ///< Maximum measured BP flow rate allowed. #define DIP_MIN_FLOW_RATE -1320.0 ///< Minimum measured BP flow rate allowed. -#define DIP_MAX_FLOW_VS_SPEED_DIFF_RPM 200.0 ///< Maximum difference between measured motor speed and speed implied by measured flow. +#define DIP_MAX_FLOW_VS_SPEED_DIFF_RPM 200.0 ///< Maximum difference between measured motor speed and speed implied by measured flow. #define DIP_MAX_MOTOR_SPEED_WHILE_OFF_RPM 100.0 ///< Maximum motor speed (RPM) while motor is commanded off. #define DIP_MAX_ROTOR_VS_MOTOR_DIFF_RPM 5.0 ///< Maximum difference in speed between motor and rotor (in rotor RPM). #define DIP_MAX_MOTOR_SPEED_ERROR_RPM 300.0 ///< Maximum difference in speed between measured and commanded RPM. @@ -82,6 +83,8 @@ static const U32 DIP_DIRECTION_ERROR_PERSIST = (250 / TASK_PRIORITY_INTERVAL); /// Persist time (task intervals) dialysate flow rate out of range error condition. static const U32 DIP_MAX_FLOW_RATE_OUT_OF_RANGE_PERSIST = ((1 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); +/// Time threshold to trigger an alarm if Dialysate flow data has not arrived within 3 seconds +static const U32 DIP_DIALYSATE_FLOW_DATA_ALARM_THRESHOLD = ((3 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); #define DIP_MAX_CURR_WHEN_STOPPED_MA 150.0 ///< Motor controller current should not exceed this when pump should be stopped. #define DIP_MAX_CURR_WHEN_RUNNING_MA 2000.0 ///< Motor controller current should not exceed this when pump should be running. @@ -91,13 +94,13 @@ #define DIP_MOTOR_RPM_TO_PWM_DC_FACTOR 0.000193 ///< ~52 BP motor RPM = 1% PWM duty cycle #define DIP_CURRENT_ADC_TO_MA_FACTOR 3.002 ///< Conversion factor from ADC counts to mA for dialIn pump motor. -#define DIP_REV_PER_LITER 150.0 ///< Rotor revolutions per liter. +#define DIP_REV_PER_LITER 146.84 ///< Rotor revolutions per liter. /// Macro converts flow rate to motor RPM. #define DIP_ML_PER_MIN_TO_PUMP_RPM_FACTOR ( DIP_REV_PER_LITER / ML_PER_LITER ) #define DIP_GEAR_RATIO 32.0 ///< DialIn pump motor to dialIn pump gear ratio. #define DIP_PWM_ZERO_OFFSET 0.1 ///< 10% PWM duty cycle = zero speed. -/// Macro converts flow rate to estimate PWM needed to achieve it. -#define DIP_PWM_FROM_ML_PER_MIN(rate) ( (rate) * DIP_ML_PER_MIN_TO_PUMP_RPM_FACTOR * DIP_GEAR_RATIO * DIP_MOTOR_RPM_TO_PWM_DC_FACTOR + DIP_PWM_ZERO_OFFSET ) +/// Macro converts flow rate to estimate PWM needed to achieve it. // TODO - I added 1.2 gain based on empirical data +#define DIP_PWM_FROM_ML_PER_MIN(rate) ( (rate) * DIP_ML_PER_MIN_TO_PUMP_RPM_FACTOR * DIP_GEAR_RATIO * DIP_MOTOR_RPM_TO_PWM_DC_FACTOR * 1.2 + DIP_PWM_ZERO_OFFSET ) /// Conversion from PWM duty cycle % to commanded pump motor speed. #define DIP_PWM_TO_MOTOR_SPEED_RPM(pwm) ( ((pwm) - DIP_PWM_ZERO_OFFSET) * 4000.0 ) @@ -107,22 +110,8 @@ #define SIGN_FROM_12_BIT_VALUE(v) ( (S16)(v) - (S16)DIAL_IN_PUMP_ADC_ZERO ) /// Measured dialIn flow is filtered w/ moving average. -#define SIZE_OF_ROLLING_AVG ( ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) * DIP_CONTROL_INTERVAL_SEC ) +#define SIZE_OF_ROLLING_AVG 10 -/// Dialysate flow sensor signal strength low alarm persistence. -#define FLOW_SIG_STRGTH_ALARM_PERSIST ( 5 * MS_PER_SECOND ) -#define MIN_FLOW_SIG_STRENGTH 0.9 ///< Minimum flow sensor signal strength (90%). - -/// Dialysate flow fast read timeout alarm persistence. -#define DIALYSATE_FLOW_FAST_READ_TO_PERSIST 100 -/// Dialysate flow slow read timeout alarm persistence. -#define DIALYSATE_FLOW_SLOW_READ_TO_PERSIST ( MS_PER_SECOND * 3 ) -/// Blood flow comm error persistence. -#define DIALYSATE_FLOW_COMM_ERROR_PERSIST MS_PER_SECOND - -#define DFM_SENSOR_CONNECTED_STATUS 0x00 ///< Dialysate flow meter connected status. -#define DFM_SENSOR_PARAM_CORRUPT_STATUS 0x07 ///< Dialysate flow meter NVM parameter corrupt status. - #define PUMP_DIR_ERROR_COUNT_MASK 0x3F ///< Bit mask for pump direction error counter. /// Enumeration of dialysate inlet pump states. @@ -166,14 +155,16 @@ static PUMP_CONTROL_MODE_T dialInPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP;///< Currently set dialIn pump control mode. /// Interval (in ms) at which to publish dialIn flow data to CAN bus -static OVERRIDE_U32_T dialInFlowDataPublishInterval = { DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, 0 }; +static OVERRIDE_U32_T dialInFlowDataPublishInterval = { DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, 0 }; +static U32 dialysateFlowDataFreshStatusCounter = 0; ///< Counter use to trigger alarm if no fresh dialysate flow data is received static S32 targetDialInFlowRate = 0; ///< Requested dialIn flow rate static OVERRIDE_F32_T measuredDialInFlowRate = { 0.0, 0.0, 0.0, 0 }; ///< Measured dialysate inlet flow rate static OVERRIDE_F32_T dialInPumpRotorSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< Measured dialysate inlet pump rotor speed static OVERRIDE_F32_T dialInPumpSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< Measured dialysate inlet pump motor speed static OVERRIDE_F32_T adcDialInPumpMCSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< Measured dialysate inlet pump motor controller speed static OVERRIDE_F32_T adcDialInPumpMCCurrentmA = { 0.0, 0.0, 0.0, 0 }; ///< Measured dialysate inlet pump motor controller current -static OVERRIDE_F32_T dialInFlowSignalStrength = { 0.0, 0.0, 0.0, 0 }; ///< Measured dialysate flow signal strength (%) + +static U08 lastDialInPumpDirectionCount = 0; ///< Previous pump direction error count reported by FPGA. static U32 dipControlTimerCounter = 0; ///< Determines when to perform control on dialIn flow @@ -191,18 +182,12 @@ static U32 errorDialInRotorSpeedPersistTimerCtr = 0; ///< Persistence timer counter for rotor speed error condition. static U32 errorDialInPumpDirectionPersistTimerCtr = 0; ///< Persistence timer counter for pump direction error condition. -static F32 flowReadings[ SIZE_OF_ROLLING_AVG ]; ///< Holds flow samples for a rolling average. +static F64 flowReadings[ SIZE_OF_ROLLING_AVG ]; ///< Holds flow samples for a rolling average. static U32 flowReadingsIdx = 0; ///< Index for next sample in rolling average array. -static F32 flowReadingsTotal = 0.0; ///< Rolling total - used to calc average. +static F64 flowReadingsTotal = 0.0; ///< Rolling total - used to calc average. static U32 flowReadingsCount = 0; ///< Number of samples in flow rolling average buffer. static U32 dipCurrErrorDurationCtr = 0; ///< Used for tracking persistence of dip current errors. - -static U08 lastDialysateFlowFastPacketReadCtr = 0; ///< Previous read counter for the dialysate flow fast packets. -static U08 lastDialysateFlowSlowPacketReadCtr = 0; ///< Previous read counter for the dialysate flow slow packets. -static U08 lastDialInPumpDirectionCount = 0; ///< Previous pump direction error count reported by FPGA. -static U08 lastDialysateFlowCommErrorCount = 0; ///< Previous DPi flow sensor comm error count. -static HD_FLOW_SENSORS_CAL_RECORD_T dialysateFlowCalRecord; ///< Dialysate flow sensor calibration record. // ********** private function prototypes ********** @@ -215,16 +200,14 @@ static void releaseDialInPumpStop( void ); static void setDialInPumpDirection( MOTOR_DIR_T dir ); static void publishDialInFlowData( void ); -static void resetDialInFlowMovingAverage( void ); -static void filterDialInFlowReadings( F32 flow ); +static void resetDialInFlowMovingAverage( void ); +static void filterDialInFlowReadings( F64 flow ); static void updateDialInPumpSpeedAndDirectionFromHallSensors( void ); static void checkDialInPumpRotor( void ); static void checkDialInPumpDirection( void ); static void checkDialInPumpSpeeds( void ); -static void checkDialInPumpFlowAgainstSpeed( void ); static void checkDialInPumpMCCurrent( void ); -static void checkDialInFlowSensorSignalStrength( void ); -static BOOL processCalibrationData( void ); +static void checkDialInPumpFlowRate( void ); /*********************************************************************//** * @brief @@ -256,10 +239,6 @@ MIN_DIAL_IN_PUMP_PWM_DUTY_CYCLE, MAX_DIAL_IN_PUMP_PWM_DUTY_CYCLE ); // Initialize persistent alarm for flow sensor signal strength too low - initPersistentAlarm( ALARM_ID_DIALYSATE_FLOW_SIGNAL_STRENGTH_TOO_LOW, FLOW_SIG_STRGTH_ALARM_PERSIST, FLOW_SIG_STRGTH_ALARM_PERSIST ); - initPersistentAlarm( ALARM_ID_HD_DP_FLOW_READ_TIMEOUT_ERROR, 0, DIALYSATE_FLOW_FAST_READ_TO_PERSIST ); - initPersistentAlarm( ALARM_ID_HD_DP_FLOW_SLOW_READ_TIMEOUT_ERROR, 0, DIALYSATE_FLOW_SLOW_READ_TO_PERSIST ); - initPersistentAlarm( ALARM_ID_HD_DP_FLOW_SENSOR_ERROR, 0, DIALYSATE_FLOW_COMM_ERROR_PERSIST ); initPersistentAlarm( ALARM_ID_HD_DIAL_IN_FLOW_OUT_OF_RANGE, 0, DIP_MAX_FLOW_RATE_OUT_OF_RANGE_PERSIST ); } @@ -420,62 +399,34 @@ *************************************************************************/ void execDialInFlowMonitor( void ) { - // Check if a new calibration is available - if ( TRUE == isNewCalibrationRecordAvailable() ) - { - // Get the new calibration data and check its validity - processCalibrationData(); - } - HD_OP_MODE_T opMode = getCurrentOperationMode(); U16 dipRPM = getIntADCReading( INT_ADC_DIAL_IN_PUMP_SPEED ); U16 dipmA = getIntADCReading( INT_ADC_DIAL_IN_PUMP_MOTOR_CURRENT ); - U08 fpReadCtr = getFPGADialysateFlowFastPacketReadCounter(); - U08 spReadCtr = getFPGADialysateFlowSlowPacketReadCounter(); - U08 flowErrorCtr = getFPGADialysateFlowErrorCounter(); - U08 flowStatus = getFPGADialysateFlowMeterStatus(); + F64 dipFlow; - F32 fpgaDialysateFlow = getFPGADialysateFlow(); - F32 dipFlow = pow(fpgaDialysateFlow, 4) * dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].fourthOrderCoeff + - pow(fpgaDialysateFlow, 3) * dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].thirdOrderCoeff + - pow(fpgaDialysateFlow, 2) * dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].secondOrderCoeff + - fpgaDialysateFlow * dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].gain + - dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].offset; - -#ifndef DISABLE_PUMP_FLOW_CHECKS - if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_DP_FLOW_SENSOR_ERROR, ( flowErrorCtr != lastDialysateFlowCommErrorCount ) ) ) + // Process new dialysate flow readings + if ( TRUE == getDialysateFlowDataFreshFlag() ) { - activateAlarmNoData( ALARM_ID_HD_DP_FLOW_SENSOR_ERROR ); + dipFlow = getDGDialysateFlowRateLMin() * (F64)ML_PER_LITER; // convert rate to mL/min + filterDialInFlowReadings( dipFlow ); // process the fresh dialysate flow data + dialysateFlowDataFreshStatusCounter = 0; // reset counter } - if ( flowStatus != DFM_SENSOR_CONNECTED_STATUS ) - { - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_DIALYSATE_FLOW_STATUS_SELF_TEST_FAILURE, (U32)flowStatus ); + else + { // Alarm if not receiving new dialysate flow readings in timely manner + if ( ++dialysateFlowDataFreshStatusCounter > DIP_DIALYSATE_FLOW_DATA_ALARM_THRESHOLD ) + { + filterDialInFlowReadings( 0.0 ); + if ( TRUE == isDGCommunicating() ) + { + activateAlarmNoData( ALARM_ID_HD_DIALYSATE_FLOW_DATA_NOT_RECEIVE ); + } + } } - lastDialysateFlowCommErrorCount = flowErrorCtr; -#endif -#ifndef DISABLE_FPGA_COUNTER_CHECKS - // Check for stale flow reading - if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_DP_FLOW_READ_TIMEOUT_ERROR, ( fpReadCtr == lastDialysateFlowFastPacketReadCtr ) ) ) - { - activateAlarmNoData( ALARM_ID_HD_DP_FLOW_READ_TIMEOUT_ERROR ); - } - if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_DP_FLOW_SLOW_READ_TIMEOUT_ERROR, ( spReadCtr == lastDialysateFlowSlowPacketReadCtr ) ) ) - { - activateAlarmNoData( ALARM_ID_HD_DP_FLOW_SLOW_READ_TIMEOUT_ERROR ); - } -#endif - - // Record flow read counters for next time around - lastDialysateFlowFastPacketReadCtr = fpReadCtr; - lastDialysateFlowSlowPacketReadCtr = spReadCtr; - + // Get latest pump speed and current from motor controller adcDialInPumpMCSpeedRPM.data = (F32)(SIGN_FROM_12_BIT_VALUE(dipRPM)) * DIP_SPEED_ADC_TO_RPM_FACTOR; adcDialInPumpMCCurrentmA.data = (F32)(SIGN_FROM_12_BIT_VALUE(dipmA)) * DIP_CURRENT_ADC_TO_MA_FACTOR; - dialInFlowSignalStrength.data = getFPGADialysateFlowSignalStrength(); - - filterDialInFlowReadings( dipFlow ); - + // Calculate dialysate inlet pump motor speed/direction from hall sensor count updateDialInPumpSpeedAndDirectionFromHallSensors(); @@ -488,13 +439,11 @@ checkDialInPumpMCCurrent(); // Check pump speeds and flow checkDialInPumpSpeeds(); - checkDialInPumpFlowAgainstSpeed(); + checkDialInPumpFlowRate(); // Check for home position, zero/low speed checkDialInPumpRotor(); - // Check flow sensor signal strength - checkDialInFlowSensorSignalStrength(); - } - + } + // Publish dialIn flow data on interval publishDialInFlowData(); } @@ -743,52 +692,6 @@ /*********************************************************************//** * @brief - * The processCalibrationData function gets the calibration data and makes - * sure it is valid by checking the calibration date. The calibration date - * should not be 0. - * @details Inputs: none - * @details Outputs: dialysateFlowCalRecord - * @return TRUE if the calibration record is valid, otherwise FALSE - *************************************************************************/ -static BOOL processCalibrationData( void ) -{ - BOOL status = TRUE; - - // Get the calibration record from NVDataMgmt - HD_FLOW_SENSORS_CAL_RECORD_T calData = getHDFlowSensorsCalibrationRecord(); - - // Check if the calibration data that was received from NVDataMgmt is legitimate - // The calibration date item should not be zero. If the calibration date is 0, - // then the dialysate flow sensors data is not stored in the NV memory or it was corrupted. - if ( 0 == calData.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].calibrationTime ) - { -#ifndef SKIP_CAL_CHECK - activateAlarmNoData( ALARM_ID_HD_DIALYSATE_FLOW_INVALID_CAL_RECORD ); - status = FALSE; -#endif - } - - // The calibration data was valid, update the local copy - dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].fourthOrderCoeff = - calData.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].fourthOrderCoeff; - - dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].thirdOrderCoeff = - calData.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].thirdOrderCoeff; - - dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].secondOrderCoeff = - calData.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].secondOrderCoeff; - - dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].gain = - calData.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].gain; - - dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].offset = - calData.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].offset; - - return status; -} - -/*********************************************************************//** - * @brief * The getTargetDialInFlowRate function gets the current target dialIn flow * rate. * @details Inputs: targetDialInFlowRate @@ -820,26 +723,6 @@ return result; } -/*********************************************************************//** - * @brief - * The getMeasuredDialInFlowSignalStrength function gets the measured dialIn flow - * signal strength. - * @details Inputs: dialInFlowSignalStrength - * @details Outputs: none - * @return the current dialIn flow signal strength (in %). - *************************************************************************/ -F32 getMeasuredDialInFlowSignalStrength( void ) -{ - F32 result = dialInFlowSignalStrength.data; - - if ( OVERRIDE_KEY == dialInFlowSignalStrength.override ) - { - result = dialInFlowSignalStrength.ovData; - } - - return result; -} - /*********************************************************************//** * @brief * The getMeasuredDialInPumpRotorSpeed function gets the measured dialIn flow @@ -926,11 +809,19 @@ * PWM duty cycle percentage. * @details Inputs: dialInPumpPWMDutyCyclePctSet * @details Outputs: none + * @param init Flag indicates whether or not initial PWM duty cycle is wanted * @return the current dialIn pump PWM duty cycle percentage (0..1). *************************************************************************/ -F32 getDialInPumpPWMDutyCyclePct( void ) +F32 getDialInPumpPWMDutyCyclePct( BOOL init ) { - return dialInPumpPWMDutyCyclePctSet; + F32 result = dialInPumpPWMDutyCyclePctSet; + + if ( TRUE == init ) + { + result = dialInPumpPWMDutyCyclePct; + } + + return result; } /*********************************************************************//** @@ -956,8 +847,8 @@ payload.measMCSpd = getMeasuredDialInPumpMCSpeed(); payload.measMCCurr = getMeasuredDialInPumpMCCurrent(); payload.pwmDC = dialInPumpPWMDutyCyclePctSet * FRACTION_TO_PERCENT_FACTOR; - payload.flowSigStrength = getMeasuredDialInFlowSignalStrength() * FRACTION_TO_PERCENT_FACTOR; - broadcastDialInFlowData( &payload ); + payload.flowSigStrength = 0.0; + broadcastData( MSG_ID_DIALYSATE_FLOW_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&payload, sizeof( DIALIN_PUMP_STATUS_PAYLOAD_T ) ); dialInFlowDataPublicationTimerCounter = 0; } } @@ -985,9 +876,8 @@ * @details Outputs: flowReadings[], flowReadingsIdx, flowReadingsCount, flowReadingsTotal * @return none *************************************************************************/ -static void filterDialInFlowReadings( F32 flow ) +void filterDialInFlowReadings( F64 flow ) { -#ifndef RAW_FLOW_SENSOR_DATA if ( flowReadingsCount >= SIZE_OF_ROLLING_AVG ) { flowReadingsTotal -= flowReadings[ flowReadingsIdx ]; @@ -996,10 +886,7 @@ flowReadingsTotal += flow; flowReadingsIdx = INC_WRAP( flowReadingsIdx, 0, SIZE_OF_ROLLING_AVG - 1 ); flowReadingsCount = INC_CAP( flowReadingsCount, SIZE_OF_ROLLING_AVG ); - measuredDialInFlowRate.data = flowReadingsTotal / (F32)flowReadingsCount; -#else - measuredDialInFlowRate.data = flow; -#endif + measuredDialInFlowRate.data = (F32)( flowReadingsTotal / (F64)flowReadingsCount ); } /*********************************************************************//** @@ -1083,12 +970,14 @@ MOTOR_DIR_T dipMCDir, dipDir; U08 dirErrorCnt = getFPGADialInPumpHallSensorStatus() & PUMP_DIR_ERROR_COUNT_MASK; +#ifndef DISABLE_PUMP_DIRECTION_CHECKS // Check pump direction error count if ( lastDialInPumpDirectionCount != dirErrorCnt ) { lastDialInPumpDirectionCount = dirErrorCnt; SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_PUMP_DIRECTION_STATUS_ERROR, (U32)HD_PUMP_DIALYSATE_INLET_PUMP ) } +#endif dipMCDir = ( getMeasuredDialInPumpMCSpeed() >= 0.0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); dipDir = ( getMeasuredDialInPumpSpeed() >= 0.0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); @@ -1214,15 +1103,13 @@ /*********************************************************************//** * @brief - * The checkDialInPumpFlowAgainstSpeed function checks the measured dialysate flow - * against the implied flow of the measured pump speed when in treatment mode - * and controlling to target flow. If a sufficient difference persists, a - * flow vs. motor speed check error is triggered. - * @details Inputs: measuredDialInFlowRate, dialInPumpSpeedRPM, errorDialInFlowVsMotorSpeedPersistTimerCtr + * The checkDialInPumpFlowRate function checks the measured dialysate flow + * rate is in range. + * @details Inputs: measuredDialInFlowRate * @details Outputs: alarm may be triggered * @return none *************************************************************************/ -static void checkDialInPumpFlowAgainstSpeed( void ) +static void checkDialInPumpFlowRate( void ) { F32 flow = getMeasuredDialInFlowRate(); @@ -1237,7 +1124,7 @@ // Check only performed while in treatment mode and while we are in control to target state if ( ( MODE_TREA == getCurrentOperationMode() ) && ( DIAL_IN_PUMP_CONTROL_TO_TARGET_STATE == dialInPumpState ) ) { - F32 flow = getMeasuredDialInFlowRate(); + F32 flow = (F32)targetDialInFlowRate; F32 speed = getMeasuredDialInPumpSpeed(); F32 impliedSpeed = ( flow / (F32)ML_PER_LITER ) * DIP_REV_PER_LITER * DIP_GEAR_RATIO; F32 delta = fabs( speed - impliedSpeed ); @@ -1259,7 +1146,7 @@ else { errorDialInFlowVsMotorSpeedPersistTimerCtr = 0; - } + } } /*********************************************************************//** @@ -1314,33 +1201,6 @@ } } -/*********************************************************************//** - * @brief - * The checkDialInFlowSensorSignalStrength function checks the measured - * dialysate flow sensor signal strength is sufficient for accurate flow sensing. - * @details Inputs: - * @details Outputs: - * @return none - *************************************************************************/ -static void checkDialInFlowSensorSignalStrength( void ) -{ -#ifndef DISABLE_PUMP_FLOW_CHECKS - HD_OP_MODE_T opMode = getCurrentOperationMode(); - - // Check flow sensor signal strength when appropriate TODO - in pre-treatment, must be far enough along for fluid to be in tubing - if ( MODE_TREA == opMode || ( MODE_PRET == opMode && FALSE ) ) - { - F32 sigStrength = getMeasuredDialInFlowSignalStrength(); - BOOL outOfRange = ( sigStrength < MIN_FLOW_SIG_STRENGTH ? TRUE : FALSE ); - - if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_DIALYSATE_FLOW_SIGNAL_STRENGTH_TOO_LOW, outOfRange ) ) - { - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DIALYSATE_FLOW_SIGNAL_STRENGTH_TOO_LOW, sigStrength, MIN_FLOW_SIG_STRENGTH ); - } - } -#endif -} - /*********************************************************************//** * @brief * The execDialInFlowTest function executes the state machine for the @@ -1351,27 +1211,8 @@ *************************************************************************/ SELF_TEST_STATUS_T execDialInFlowTest( void ) { - SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; - U08 const dfmStatus = getFPGADialysateFlowMeterStatus(); + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_PASSED; - if ( DFM_SENSOR_PARAM_CORRUPT_STATUS != dfmStatus ) - { - BOOL calStatus = processCalibrationData(); - - if ( TRUE == calStatus ) - { - result = SELF_TEST_STATUS_PASSED; - } - else - { - result = SELF_TEST_STATUS_FAILED; - } - } - else - { - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_DIALYSATE_FLOW_STATUS_SELF_TEST_FAILURE, (U32)dfmStatus ); - } - return result; } @@ -1689,49 +1530,4 @@ return result; } -/*********************************************************************//** - * @brief - * The testSetMeasuredDialInFlowSignalStrengthOverride function overrides the measured - * dialysate flow signal strength. - * @details Inputs: none - * @details Outputs: dialInFlowSignalStrength - * @param value override measured dialysate flow signal strength (in %) - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testSetMeasuredDialInFlowSignalStrengthOverride( F32 value ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - dialInFlowSignalStrength.ovData = value / 100.0; - dialInFlowSignalStrength.override = OVERRIDE_KEY; - } - - return result; -} - -/*********************************************************************//** - * @brief - * The testResetMeasuredDialInFlowSignalStrengthOverride function resets the override - * of the measured dialysate flow signal strength. - * @details Inputs: none - * @details Outputs: dialInFlowSignalStrength - * @return TRUE if reset successful, FALSE if not - *************************************************************************/ -BOOL testResetMeasuredDialInFlowSignalStrengthOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - dialInFlowSignalStrength.override = OVERRIDE_RESET; - dialInFlowSignalStrength.ovData = dialInFlowSignalStrength.ovInitData; - } - - return result; -} - /**@}*/