Index: firmware/App/Drivers/ConductivitySensors.c =================================================================== diff -u -rd47b9bcbd4796a8c51d9e87436422c5868292ac6 -r75f32cd59369b07708e2d1118ea3695872484e31 --- firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision d47b9bcbd4796a8c51d9e87436422c5868292ac6) +++ firmware/App/Drivers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 75f32cd59369b07708e2d1118ea3695872484e31) @@ -52,7 +52,7 @@ #define MAX_CONDUCTIVITY_SENSOR_FAILURES 2 ///< Number of failures before alarming in timed window count. #define MAX_CONDUCTIVITY_SENSOR_FAILURE_WINDOW_MS ( 60 * MS_PER_SECOND ) ///< Set time for timed window count. -#define MAX_ALLOWED_UNCHANGED_CONDUCTIVITY_READS ( 500 / TASK_PRIORITY_INTERVAL ) ///< New reading every 333ms, expect to get valid new reading in 500ms. +#define MAX_ALLOWED_UNCHANGED_CONDUCTIVITY_READS ( 800 / TASK_PRIORITY_INTERVAL ) ///< New reading every 333ms, expect to get valid new reading in 500ms. #define COND_SENSORS_FPGA_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Conductivity sensors FPGA error timeout in milliseconds. #define COND_SENSORS_READ_ERR_MAX_CNT 255 ///< Conductivity sensors read and error count max value. @@ -140,7 +140,6 @@ *************************************************************************/ void initConductivitySensors( void ) { - /// TODO: Revert back to init state. currentConductivityState = CONDUCTIVITY_INIT_STATE; CONDUCTIVITY_SENSORS_T sensor; @@ -216,6 +215,7 @@ initFPGAPersistentAlarm( FPGA_PERS_ERROR_D74_COND_SENSOR, ALARM_ID_DD_D74_COND_SENSOR_FPGA_FAULT, COND_SENSORS_FPGA_ERROR_TIMEOUT_MS, COND_SENSORS_FPGA_ERROR_TIMEOUT_MS ); initFPGAPersistentAlarm( FPGA_PERS_ERROR_P9_COND_SENSOR, ALARM_ID_FP_P9_COND_SENSOR_FPGA_FAULT, COND_SENSORS_FPGA_ERROR_TIMEOUT_MS, COND_SENSORS_FPGA_ERROR_TIMEOUT_MS ); initFPGAPersistentAlarm( FPGA_PERS_ERROR_P18_COND_SENSOR, ALARM_ID_FP_P18_COND_SENSOR_FPGA_FAULT, COND_SENSORS_FPGA_ERROR_TIMEOUT_MS, COND_SENSORS_FPGA_ERROR_TIMEOUT_MS ); + } /*********************************************************************//** @@ -1095,6 +1095,7 @@ break; } } + calculateResistance( sensorNum, isFPSensor ); calculateTemperature( sensorNum ); @@ -1410,4 +1411,5 @@ return result; } + /**@}*/ Index: firmware/App/Monitors/Conductivity.c =================================================================== diff -u -rd47b9bcbd4796a8c51d9e87436422c5868292ac6 -r75f32cd59369b07708e2d1118ea3695872484e31 --- firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision d47b9bcbd4796a8c51d9e87436422c5868292ac6) +++ firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision 75f32cd59369b07708e2d1118ea3695872484e31) @@ -17,12 +17,14 @@ #include // Used for calculating the polynomial calibration equation. #include // For memcpy +#include "BalancingChamber.h" #include "Conductivity.h" #include "MessageSupport.h" #include "Messaging.h" #include "ModeGenPermeate.h" #include "OperationModes.h" #include "TaskPriority.h" +#include "TDInterface.h" #include "Utilities.h" /** @@ -38,9 +40,9 @@ #define FP_CONDUCTIVITY_DATA_PUBLISH_COUNTER_START_COUNT 41 ///< FP Conductivity data publish counter start count. #define RO_DATA_PUBLISH_COUNTER_START_COUNT 42 ///< FP RO Data publish counter start count. #define RESISTANCE_DATA_PUBLISH_COUNTER_START_COUNT 43 ///< DD Resistance data publish counter start count. -#define CONDUCTIVITY_SAMPLE_FILTER_MS ( 210 ) ///< Filter conductivity data for given time. Currently set to have 5 samples over 3.5s ( 700ms sample rate ) +#define CONDUCTIVITY_MAX_FILTER_SIZE_MULTIPLIER ( 252 ) ///< Maximum conductivity filter sample count. #define CONDUCTIVITY_TEMP_SAMPLE_FILTER_MS ( 30 ) ///< Filter conductivity temperature data for given time. Currently set to have 5 samples over 3.5s ( 700ms sample rate ) -#define SIZE_OF_COND_ROLLING_AVG ( CONDUCTIVITY_SAMPLE_FILTER_MS / TASK_PRIORITY_INTERVAL ) ///< Filtered conductivity moving average sample count. +#define FILTER_SIZE_MULTIPLIER ( 7 ) ///< Conductivity filter size multiplier. #define SIZE_OF_COND_TEMP_ROLLING_AVG ( CONDUCTIVITY_TEMP_SAMPLE_FILTER_MS / TASK_PRIORITY_INTERVAL ) ///< Filtered conductivity temprature moving average sample count. #define RO_RR_MOVING_AVG_NUM_OF_SAMPLES 30 ///< RO rejection ratio moving average number of samples. #define FRACTION_TO_PERCENT_CONVERSION_FACTOR 100.0F ///< RO rejection ratio factor to percentage conversion factor value @@ -49,7 +51,7 @@ /// Filter conductivity readings record. typedef struct { - F32 conductivityReadings[ SIZE_OF_COND_ROLLING_AVG ]; ///< Holds conductivity sample rolling average. + F32 conductivityReadings[ CONDUCTIVITY_MAX_FILTER_SIZE_MULTIPLIER ]; ///< Holds conductivity sample rolling average. U32 conductivityReadingsIdx; ///< Index for next sample in rolling average array. F32 conductivityReadingsTotal; ///< Rolling total - used to calc average. U32 conductivityReadingsCount; ///< Number of samples in rolling average buffer @@ -89,6 +91,7 @@ static U32 roRRCount; ///< RO rejection ratio Number of samples in average buffer. static F32 roRRTankFillAvg; ///< Average RO rejection ratio during permeate tank fill state. static U32 roRRSampleIntervalCounter; ///< RO rejection ratio sample collection timer counter. +static U32 conductivityFilterSize; ///< Active conductivity filter sample count. // ********** private function prototypes ********** @@ -98,6 +101,8 @@ static void filterConductivitySensorTemperatureReadings( void ); static void calcRORejectionRatio( void ); static void filterRORejectionRatioReadings( void ); +static U32 getConductivityFilterSize( void ); +static void resetConductivityFilterReadings( void ); /*********************************************************************//** * @brief @@ -127,6 +132,7 @@ roRRAvg.ovInitData = 0.0F; roRRAvg.override = OVERRIDE_RESET; roRRSampleIntervalCounter = 0; + conductivityFilterSize = FILTER_SIZE_MULTIPLIER; memset( &roRRSamples, 0, sizeof( roRRSamples ) ); @@ -290,8 +296,15 @@ CONDUCTIVITY_SENSORS_T sensor; F32 calculatedConductivity = 0.0F; F32 uncompenstatedConductivity = 0.0F; + U32 activeFilterSize = getConductivityFilterSize(); BOOL freshData = FALSE; + if ( conductivityFilterSize != activeFilterSize ) + { + conductivityFilterSize = activeFilterSize; + resetConductivityFilterReadings(); + } + for ( sensor = FIRST_DD_COND_SENSOR; sensor < NUM_OF_CONDUCTIVITY_SENSORS; sensor++ ) { if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_9_HW ) == TRUE ) @@ -324,24 +337,24 @@ { freshData = FALSE; // TODO - calibrate - if ( filteredConductivityReadings[ sensor ].conductivityReadingsCount >= SIZE_OF_COND_ROLLING_AVG ) + if ( filteredConductivityReadings[ sensor ].conductivityReadingsCount >= conductivityFilterSize ) { filteredConductivityReadings[ sensor ].conductivityReadingsTotal -= filteredConductivityReadings[ sensor ].conductivityReadings[ filteredConductivityReadings[ sensor ].conductivityReadingsIdx ]; } filteredConductivityReadings[ sensor ].conductivityReadings[ filteredConductivityReadings[ sensor ].conductivityReadingsIdx ] = calculatedConductivity; filteredConductivityReadings[ sensor ].conductivityReadingsTotal += calculatedConductivity; - filteredConductivityReadings[ sensor ].conductivityReadingsIdx = INC_WRAP( filteredConductivityReadings[ sensor ].conductivityReadingsIdx, 0, SIZE_OF_COND_ROLLING_AVG - 1 ); - filteredConductivityReadings[ sensor ].conductivityReadingsCount = INC_CAP( filteredConductivityReadings[ sensor ].conductivityReadingsCount, SIZE_OF_COND_ROLLING_AVG ); + filteredConductivityReadings[ sensor ].conductivityReadingsIdx = INC_WRAP( filteredConductivityReadings[ sensor ].conductivityReadingsIdx, 0, conductivityFilterSize - 1 ); + filteredConductivityReadings[ sensor ].conductivityReadingsCount = INC_CAP( filteredConductivityReadings[ sensor ].conductivityReadingsCount, conductivityFilterSize ); filteredcurrentConductivityReadings[ sensor ].data = filteredConductivityReadings[ sensor ].conductivityReadingsTotal / (F32)filteredConductivityReadings[ sensor ].conductivityReadingsCount; - if ( filteredUConductivityReadings[ sensor ].conductivityReadingsCount >= SIZE_OF_COND_ROLLING_AVG ) + if ( filteredUConductivityReadings[ sensor ].conductivityReadingsCount >= conductivityFilterSize ) { filteredUConductivityReadings[ sensor ].conductivityReadingsTotal -= filteredUConductivityReadings[ sensor ].conductivityReadings[ filteredUConductivityReadings[ sensor ].conductivityReadingsIdx ]; } filteredUConductivityReadings[ sensor ].conductivityReadings[ filteredUConductivityReadings[ sensor ].conductivityReadingsIdx ] = uncompenstatedConductivity; filteredUConductivityReadings[ sensor ].conductivityReadingsTotal += uncompenstatedConductivity; - filteredUConductivityReadings[ sensor ].conductivityReadingsIdx = INC_WRAP( filteredUConductivityReadings[ sensor ].conductivityReadingsIdx, 0, SIZE_OF_COND_ROLLING_AVG - 1 ); - filteredUConductivityReadings[ sensor ].conductivityReadingsCount = INC_CAP( filteredUConductivityReadings[ sensor ].conductivityReadingsCount, SIZE_OF_COND_ROLLING_AVG ); + filteredUConductivityReadings[ sensor ].conductivityReadingsIdx = INC_WRAP( filteredUConductivityReadings[ sensor ].conductivityReadingsIdx, 0, conductivityFilterSize - 1 ); + filteredUConductivityReadings[ sensor ].conductivityReadingsCount = INC_CAP( filteredUConductivityReadings[ sensor ].conductivityReadingsCount, conductivityFilterSize ); filteredcurrentUConductivityReadings[ sensor ].data = filteredUConductivityReadings[ sensor ].conductivityReadingsTotal / (F32)filteredUConductivityReadings[ sensor ].conductivityReadingsCount; } @@ -350,6 +363,75 @@ /*********************************************************************//** * @brief + * The getConductivityFilterSize function gets the active conductivity filter + * sample count based on the Qd balancing chamber switching period. + * @details \b Inputs: TD dialysate flow rate + * @details \b Outputs: none + * @return active conductivity filter sample count. + *************************************************************************/ +static U32 getConductivityFilterSize( void ) +{ + F32 tdDialysateFlowRate = getTDDialysateFlowrate(); + U32 result = FILTER_SIZE_MULTIPLIER; + + if ( tdDialysateFlowRate > NEARLY_ZERO ) + { + F32 balChamberSwitchingFreq = tdDialysateFlowRate / BAL_CHAMBER_FILL_VOLUME_ML; + F32 balChamberSwitchingPeriod = (F32)SEC_PER_MIN / balChamberSwitchingFreq; + + result = (U32)( (F32)FILTER_SIZE_MULTIPLIER * balChamberSwitchingPeriod ); + } + + return result; +} + +/*********************************************************************//** + * @brief + * The resetConductivityFilterReadings function clears conductivity rolling + * average data when the active filter window changes. + * @details \b Inputs: none + * @details \b Outputs: filteredConductivityReadings + * @return none + *************************************************************************/ +static void resetConductivityFilterReadings( void ) +{ + CONDUCTIVITY_SENSORS_T sensor; + + for ( sensor = FIRST_DD_COND_SENSOR; sensor < NUM_OF_CONDUCTIVITY_SENSORS; sensor++ ) + { + U32 readingIndex; + + F32 seedConductivity = filteredcurrentConductivityReadings[ sensor ].data; + BOOL hasPreviousSamples = ( filteredConductivityReadings[ sensor ].conductivityReadingsCount > 0 ); + + for ( readingIndex = 0; readingIndex < CONDUCTIVITY_MAX_FILTER_SIZE_MULTIPLIER; readingIndex++ ) + { + if ( ( TRUE == hasPreviousSamples ) && ( readingIndex < conductivityFilterSize ) ) + { + filteredConductivityReadings[ sensor ].conductivityReadings[ readingIndex ] = seedConductivity; + } + else + { + filteredConductivityReadings[ sensor ].conductivityReadings[ readingIndex ] = 0.0F; + } + } + + filteredConductivityReadings[ sensor ].conductivityReadingsIdx = 0; + if ( TRUE == hasPreviousSamples ) + { + filteredConductivityReadings[ sensor ].conductivityReadingsTotal = seedConductivity * (F32)conductivityFilterSize; + filteredConductivityReadings[ sensor ].conductivityReadingsCount = conductivityFilterSize; + } + else + { + filteredConductivityReadings[ sensor ].conductivityReadingsTotal = 0.0F; + filteredConductivityReadings[ sensor ].conductivityReadingsCount = 0; + } + } +} + +/*********************************************************************//** + * @brief * The getFilteredConductivitySensorTemperature function gets the filtered * temperature (in C) for a given conductivity sensor. * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT if given sensor is invalid. Index: firmware/App/Services/FpgaDD.c =================================================================== diff -u -rd47b9bcbd4796a8c51d9e87436422c5868292ac6 -r75f32cd59369b07708e2d1118ea3695872484e31 --- firmware/App/Services/FpgaDD.c (.../FpgaDD.c) (revision d47b9bcbd4796a8c51d9e87436422c5868292ac6) +++ firmware/App/Services/FpgaDD.c (.../FpgaDD.c) (revision 75f32cd59369b07708e2d1118ea3695872484e31) @@ -57,7 +57,6 @@ /// Macro to clear the FPGA actuator bits based on HW type #define CLEAR_FPGA_ACTUATOR_BITS(field, bits) (getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_9_HW ) != TRUE ? ( fpgaActuatorSetPoints.field &= bits ) : ( fpgaBeta19ActuatorSetPoints.field &= bits )) -//#define CLEAR_FPGA_ACTUATOR_BITS(field, bits) (fpgaActuatorSetPoints.field &= bits) #define FPGA_EXPECTED_ID 0x06 ///< FPGA expected ID for Beta 2 systems. //TODO: Remove once Beta 1.9 is obsolete @@ -1114,6 +1113,7 @@ SET_FPGA_ACTUATOR_FIELD( fpgaD12PumpSpeed, currentSpeed ); } + /*********************************************************************//** * @brief * The setFPGAD48PumpControl function sets the controls for Index: firmware/App/Tasks/TaskGeneral.c =================================================================== diff -u -rd47b9bcbd4796a8c51d9e87436422c5868292ac6 -r75f32cd59369b07708e2d1118ea3695872484e31 --- firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision d47b9bcbd4796a8c51d9e87436422c5868292ac6) +++ firmware/App/Tasks/TaskGeneral.c (.../TaskGeneral.c) (revision 75f32cd59369b07708e2d1118ea3695872484e31) @@ -31,6 +31,7 @@ #include "PermeateTank.h" #include "RinsePump.h" #include "ROPump.h" +#include "SubstitutionPump.h" #include "SystemCommDD.h" #include "TaskGeneral.h" #include "WatchdogMgmt.h" @@ -106,6 +107,9 @@ execDryBicart(); } + // Control Substitution pump + execSubstitutionPumpController(); + // Control closed loop mixing of bicarb and acid execMixingControl();