Index: firmware/App/Controllers/DialysateFlow.c =================================================================== diff -u -r41f49a0643c7cfa35c9c99fb9ac4e6410c968dc5 -r834620c604c7aaea0a123e4fb558d31e43ac5bf3 --- firmware/App/Controllers/DialysateFlow.c (.../DialysateFlow.c) (revision 41f49a0643c7cfa35c9c99fb9ac4e6410c968dc5) +++ firmware/App/Controllers/DialysateFlow.c (.../DialysateFlow.c) (revision 834620c604c7aaea0a123e4fb558d31e43ac5bf3) @@ -16,17 +16,14 @@ ***************************************************************************/ #include + #include "FPGA.h" #include "NVDataMgmt.h" #include "PersistentAlarm.h" #include "DialysateFlow.h" -//#include "SafetyShutdown.h" #include "SystemCommMessages.h" -#include "TaskGeneral.h" #include "TaskPriority.h" -//#include "Timers.h" - /** * @addtogroup DialysateFlow * @{ @@ -44,7 +41,6 @@ #define DIALYSATE_FLOW_ADC_TO_LPM_FACTOR 5555 ///< Conversion factor from pulse period (2us units) to flow rate (L/min) for dialysate flow rate (divide this by pulse period). #define FLOW_OUT_OF_RANGE_PERSISTENT_INTERVAL ( 12 * MS_PER_SECOND ) ///< Flow out of range time out in counts. - // ********** private data ********** static U32 dialysateFlowDataPublicationTimerCounter = 0; ///< Used to schedule Dialysate flow data publication to CAN bus. @@ -67,9 +63,9 @@ /*********************************************************************//** * @brief * The initDialysateFlowMeter function initializes the Dialysate flow module. - * @details Inputs: measuredFlowReadingsSum, flowFilterCounter, + * @details Inputs: none + * @details Outputs: measuredFlowReadingsSum, flowFilterCounter, * dialysateFlowDataPublicationTimerCounter - * @details Outputs: none * @return none *************************************************************************/ void initDialysateFlowMeter( void ) @@ -102,29 +98,30 @@ // Update sum for flow average calculation measuredFlowReadingsSum += (S32)dialysateFlowReading; +#if 0 // TODO - implement calibration // Check if a new calibration is available if ( TRUE == isNewCalibrationRecordAvailable() ) { // Get the new calibration data and check its validity processCalibrationData(); } +#endif // Read flow at the control set if ( ++flowFilterCounter >= FLOW_SAMPLES_TO_AVERAGE ) { - //U32 sensor; F32 flow = DIALYSATE_FLOW_ADC_TO_LPM_FACTOR / ( (F32)measuredFlowReadingsSum * FLOW_AVERAGE_MULTIPLIER ); // Convert flow sensor period to L/min - +#if 0 // TODO - implement calibration // Apply calibration to flow sensor reading -/* measuredROFlowRateLPM.data = pow(flow, 4) * flowSensorsCalRecord.flowSensors[ CAL_DATA_RO_PUMP_FLOW_SENSOR ].fourthOrderCoeff + - pow(flow, 3) * flowSensorsCalRecord.flowSensors[ CAL_DATA_RO_PUMP_FLOW_SENSOR ].thirdOrderCoeff + - pow(flow, 2) * flowSensorsCalRecord.flowSensors[ CAL_DATA_RO_PUMP_FLOW_SENSOR ].secondOrderCoeff + - flow * flowSensorsCalRecord.flowSensors[ CAL_DATA_RO_PUMP_FLOW_SENSOR ].gain + - flowSensorsCalRecord.flowSensors[ CAL_DATA_RO_PUMP_FLOW_SENSOR ].offset; */ - + measuredDialysateFlowRateLPM.data = pow(flow, 4) * flowSensorsCalRecord.flowSensors[ CAL_DATA_RO_PUMP_FLOW_SENSOR ].fourthOrderCoeff + + pow(flow, 3) * flowSensorsCalRecord.flowSensors[ CAL_DATA_RO_PUMP_FLOW_SENSOR ].thirdOrderCoeff + + pow(flow, 2) * flowSensorsCalRecord.flowSensors[ CAL_DATA_RO_PUMP_FLOW_SENSOR ].secondOrderCoeff + + flow * flowSensorsCalRecord.flowSensors[ CAL_DATA_RO_PUMP_FLOW_SENSOR ].gain + + flowSensorsCalRecord.flowSensors[ CAL_DATA_RO_PUMP_FLOW_SENSOR ].offset; +#else // Calibration of the dialysate flow sensor will be implemented later measuredDialysateFlowRateLPM.data = flow; - +#endif // If the flow is less than a certain value, FPGA will return 0xFFFF meaning that the flow is 0. if ( FLOW_SENSOR_ZERO_READING == dialysateFlowReading ) { @@ -151,33 +148,9 @@ static BOOL processCalibrationData( void ) { BOOL status = TRUE; - U32 sensor; - // Get the calibration record from NVDataMgmt - DG_FLOW_SENSORS_CAL_RECORD_T calData = getDGFlowSensorsCalibrationRecord(); + // TODO - implement calibration for this sensor - for ( sensor = 0; sensor < NUM_OF_CAL_DATA_FLOW_SENSORS; sensor++ ) - { -#ifndef SKIP_CAL_CHECK - // 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 flow sensors data is not stored in the NV memory or it was corrupted. - if ( 0 == calData.flowSensors[ sensor ].calibrationTime ) - { - - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_FLOW_SENSORS_INVALID_CAL_RECORD, (U32)sensor ); - status = FALSE; - } -#endif - - // The calibration data was valid, update the local copy -/* flowSensorsCalRecord.flowSensors[ sensor ].fourthOrderCoeff = calData.flowSensors[ sensor ].fourthOrderCoeff; - flowSensorsCalRecord.flowSensors[ sensor ].thirdOrderCoeff = calData.flowSensors[ sensor ].thirdOrderCoeff; - flowSensorsCalRecord.flowSensors[ sensor ].secondOrderCoeff = calData.flowSensors[ sensor ].secondOrderCoeff; - flowSensorsCalRecord.flowSensors[ sensor ].gain = calData.flowSensors[ sensor ].gain; - flowSensorsCalRecord.flowSensors[ sensor ].offset = calData.flowSensors[ sensor ].offset; */ - } - return status; } @@ -194,10 +167,9 @@ if ( ++dialysateFlowDataPublicationTimerCounter >= getU32OverrideValue( &dialysateFlowDataPublishInterval ) ) { DIALYSATE_FLOW_METER_DATA_T dialysateFlowData; - dialysateFlowData.measuredDialysateFlowRate = getMeasuredDialysateFlowRate(); + dialysateFlowData.measuredDialysateFlowRate = getMeasuredDialysateFlowRate(); broadcastDialysateFlowData( &dialysateFlowData ); - dialysateFlowDataPublicationTimerCounter = 0; } } @@ -214,6 +186,7 @@ return getF32OverrideValue( &measuredDialysateFlowRateLPM ); } + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/