Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -re45524455c005d4fa1734efcbaf7ed0499302670 -r46c538cc5b7b40ddc8227e2ad1c77bab93716571 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision e45524455c005d4fa1734efcbaf7ed0499302670) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 46c538cc5b7b40ddc8227e2ad1c77bab93716571) @@ -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" @@ -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. @@ -152,7 +155,8 @@ 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 @@ -196,7 +200,8 @@ static void releaseDialInPumpStop( void ); static void setDialInPumpDirection( MOTOR_DIR_T dir ); static void publishDialInFlowData( void ); -static void resetDialInFlowMovingAverage( void ); +static void resetDialInFlowMovingAverage( void ); +static void filterDialInFlowReadings( F32 flow ); static void updateDialInPumpSpeedAndDirectionFromHallSensors( void ); static void checkDialInPumpRotor( void ); static void checkDialInPumpDirection( void ); @@ -235,6 +240,7 @@ // Initialize persistent alarm for flow sensor signal strength too low initPersistentAlarm( ALARM_ID_HD_DIAL_IN_FLOW_OUT_OF_RANGE, 0, DIP_MAX_FLOW_RATE_OUT_OF_RANGE_PERSIST ); + initPersistentAlarm( ALARM_ID_HD_DIALYSATE_FLOW_DATA_NOT_RECEIVE, 0, 0 ); } /*********************************************************************//** @@ -401,10 +407,78 @@ U08 spReadCtr = getFPGADialysateFlowSlowPacketReadCounter(); U08 flowErrorCtr = getFPGADialysateFlowErrorCounter(); U08 flowStatus = getFPGADialysateFlowMeterStatus(); +<<<<<<< HEAD + F32 dipFlow; +#ifdef USE_FMD_FLOW_SENSOR + F32 dpFlow = getFPGADialysateFlow(); + + // 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 ) ) ) + { + activateAlarmNoData( ALARM_ID_HD_DP_FLOW_SENSOR_ERROR ); + } + if ( flowStatus != DFM_SENSOR_CONNECTED_STATUS ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_DIALYSATE_FLOW_STATUS_SELF_TEST_FAILURE, (U32)flowStatus ); + } + 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; + + dialInFlowSignalStrength.data = getFPGADialysateFlowSignalStrength(); +#else + if ( TRUE == getDialysateFlowDataFreshFlag() ) + { + dialysateFlowDataFreshStatusCounter = 0; // reset counter + dipFlow = getDGDialysateFlowRateMlMin() * (F32)ML_PER_LITER; + filterDialInFlowReadings( dipFlow ); // process the fresh dialysate flow data + setDialysateFlowDataFreshFlag( FALSE ); + } + else + { // dialysate flow data is a stale data + if ( ++dialysateFlowDataFreshStatusCounter > DIP_DIALYSATE_FLOW_DATA_ALARM_THRESHOLD ) + { + filterDialInFlowReadings( 0.0 ); + if ( TRUE == isDGCommunicating() ) + { + activateAlarmNoData( ALARM_ID_HD_DIALYSATE_FLOW_DATA_NOT_RECEIVE ); + } + } + } +#endif +======= +>>>>>>> 954107454f4c5d4cfbdfaefda5cc1cd15b1e18ac 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; - + // Calculate dialysate inlet pump motor speed/direction from hall sensor count updateDialInPumpSpeedAndDirectionFromHallSensors();