Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -rb14efe97c6baf3cca79d9199fd0575768262eb9f -r38b5b0408730290c3ad591711ba1613e85045cd5 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision b14efe97c6baf3cca79d9199fd0575768262eb9f) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 38b5b0408730290c3ad591711ba1613e85045cd5) @@ -65,7 +65,9 @@ #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. +#ifdef USE_FMD_FLOW_SENSOR +#define DIP_MAX_FLOW_VS_SPEED_DIFF_RPM 200.0 ///< Maximum difference between measured motor speed and speed implied by measured flow. +#endif #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. @@ -109,6 +111,7 @@ /// Measured dialIn flow is filtered w/ moving average. #define SIZE_OF_ROLLING_AVG ( ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) * DIP_CONTROL_INTERVAL_SEC ) +#ifdef USE_FMD_FLOW_SENSOR /// 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%). @@ -122,6 +125,7 @@ #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. +#endif #define PUMP_DIR_ERROR_COUNT_MASK 0x3F ///< Bit mask for pump direction error counter. @@ -173,7 +177,18 @@ 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 +#ifdef USE_FMD_FLOW_SENSOR static OVERRIDE_F32_T dialInFlowSignalStrength = { 0.0, 0.0, 0.0, 0 }; ///< Measured dialysate flow signal strength (%) + +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. +#ifndef DISABLE_PUMP_FLOW_CHECKS +static U08 lastDialysateFlowCommErrorCount = 0; ///< Previous DPi flow sensor comm error count. +#endif +static HD_FLOW_SENSORS_CAL_RECORD_T dialysateFlowCalRecord; ///< Dialysate flow sensor calibration record. +#endif + +static U08 lastDialInPumpDirectionCount = 0; ///< Previous pump direction error count reported by FPGA. static U32 dipControlTimerCounter = 0; ///< Determines when to perform control on dialIn flow @@ -197,14 +212,6 @@ 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. -#ifndef DISABLE_PUMP_FLOW_CHECKS -static U08 lastDialysateFlowCommErrorCount = 0; ///< Previous DPi flow sensor comm error count. -#endif -static HD_FLOW_SENSORS_CAL_RECORD_T dialysateFlowCalRecord; ///< Dialysate flow sensor calibration record. // ********** private function prototypes ********** @@ -223,10 +230,12 @@ static void checkDialInPumpRotor( void ); static void checkDialInPumpDirection( void ); static void checkDialInPumpSpeeds( void ); -static void checkDialInPumpFlowAgainstSpeed( void ); static void checkDialInPumpMCCurrent( void ); +static void checkDialInPumpFlowRate( void ); +#ifdef USE_FMD_FLOW_SENSOR static void checkDialInFlowSensorSignalStrength( void ); static BOOL processCalibrationData( void ); +#endif /*********************************************************************//** * @brief @@ -258,10 +267,12 @@ MIN_DIAL_IN_PUMP_PWM_DUTY_CYCLE, MAX_DIAL_IN_PUMP_PWM_DUTY_CYCLE ); // Initialize persistent alarm for flow sensor signal strength too low +#ifdef USE_FMD_FLOW_SENSOR 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 ); +#endif initPersistentAlarm( ALARM_ID_HD_DIAL_IN_FLOW_OUT_OF_RANGE, 0, DIP_MAX_FLOW_RATE_OUT_OF_RANGE_PERSIST ); } @@ -422,27 +433,28 @@ *************************************************************************/ 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(); + F32 dipFlow; +#ifdef USE_FMD_FLOW_SENSOR + F32 dpFlow = getFPGADialysateFlow(); - 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; + // Check if a new calibration is available + if ( TRUE == isNewCalibrationRecordAvailable() ) + { + // Get the new calibration data and check its validity + processCalibrationData(); + } + dipFlow = pow(dpFlow, 4) * dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].fourthOrderCoeff + + pow(dpFlow, 3) * dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].thirdOrderCoeff + + pow(dpFlow, 2) * dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].secondOrderCoeff + + dpFlow * 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 ) ) ) @@ -471,10 +483,14 @@ // Record flow read counters for next time around lastDialysateFlowFastPacketReadCtr = fpReadCtr; lastDialysateFlowSlowPacketReadCtr = spReadCtr; + + dialInFlowSignalStrength.data = getFPGADialysateFlowSignalStrength(); +#else + dipFlow = 0.0; // TODO - get dialysate flow from DG +#endif 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 ); @@ -490,11 +506,12 @@ checkDialInPumpMCCurrent(); // Check pump speeds and flow checkDialInPumpSpeeds(); - checkDialInPumpFlowAgainstSpeed(); + checkDialInPumpFlowRate(); +#ifdef USE_FMD_FLOW_SENSOR + checkDialInFlowSensorSignalStrength(); +#endif // Check for home position, zero/low speed checkDialInPumpRotor(); - // Check flow sensor signal strength - checkDialInFlowSensorSignalStrength(); } // Publish dialIn flow data on interval @@ -743,6 +760,7 @@ } } +#ifdef USE_FMD_FLOW_SENSOR /*********************************************************************//** * @brief * The processCalibrationData function gets the calibration data and makes @@ -788,6 +806,7 @@ return status; } +#endif /*********************************************************************//** * @brief @@ -822,6 +841,7 @@ return result; } +#ifdef USE_FMD_FLOW_SENSOR /*********************************************************************//** * @brief * The getMeasuredDialInFlowSignalStrength function gets the measured dialIn flow @@ -841,6 +861,7 @@ return result; } +#endif /*********************************************************************//** * @brief @@ -966,7 +987,11 @@ payload.measMCSpd = getMeasuredDialInPumpMCSpeed(); payload.measMCCurr = getMeasuredDialInPumpMCCurrent(); payload.pwmDC = dialInPumpPWMDutyCyclePctSet * FRACTION_TO_PERCENT_FACTOR; +#ifdef USE_FMD_FLOW_SENSOR payload.flowSigStrength = getMeasuredDialInFlowSignalStrength() * FRACTION_TO_PERCENT_FACTOR; +#else + payload.flowSigStrength = 0.0; +#endif broadcastData( MSG_ID_DIALYSATE_FLOW_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&payload, sizeof( DIALIN_PUMP_STATUS_PAYLOAD_T ) ); dialInFlowDataPublicationTimerCounter = 0; } @@ -1226,15 +1251,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(); @@ -1246,6 +1269,7 @@ } #endif +#ifdef USE_FMD_FLOW_SENSOR // 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 ) ) { @@ -1271,7 +1295,8 @@ else { errorDialInFlowVsMotorSpeedPersistTimerCtr = 0; - } + } +#endif } /*********************************************************************//** @@ -1326,6 +1351,7 @@ } } +#ifdef USE_FMD_FLOW_SENSOR /*********************************************************************//** * @brief * The checkDialInFlowSensorSignalStrength function checks the measured @@ -1352,6 +1378,7 @@ } #endif } +#endif /*********************************************************************//** * @brief @@ -1363,6 +1390,7 @@ *************************************************************************/ SELF_TEST_STATUS_T execDialInFlowTest( void ) { +#ifdef USE_FMD_FLOW_SENSOR SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; U08 const dfmStatus = getFPGADialysateFlowMeterStatus(); @@ -1383,6 +1411,9 @@ { SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_DIALYSATE_FLOW_STATUS_SELF_TEST_FAILURE, (U32)dfmStatus ); } +#else + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_PASSED; +#endif return result; } @@ -1701,6 +1732,7 @@ return result; } +#ifdef USE_FMD_FLOW_SENSOR /*********************************************************************//** * @brief * The testSetMeasuredDialInFlowSignalStrengthOverride function overrides the measured @@ -1745,5 +1777,6 @@ return result; } +#endif /**@}*/