Index: firmware/App/Monitors/Conductivity.c =================================================================== diff -u -r2869d16c34888bec55bded3b8aefd0203f56d3b0 -recb538c8bf67a7a62d11a1186a9ef5fe53cf9d9e --- firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision 2869d16c34888bec55bded3b8aefd0203f56d3b0) +++ firmware/App/Monitors/Conductivity.c (.../Conductivity.c) (revision ecb538c8bf67a7a62d11a1186a9ef5fe53cf9d9e) @@ -40,6 +40,7 @@ #define SIZE_OF_FLOW_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 300 ///< 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 +#define RO_RR_SAMPLE_COLLECTION_INTERVAL 10 ///< Collect RO rejection ratio sample for every 10th time in priority task /// Filter conductivity readings record. typedef struct @@ -79,6 +80,7 @@ static U32 roRRSamplesNextIndex; ///< RO rejection ratio sample next index number. 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. // ********** private function prototypes ********** @@ -115,6 +117,7 @@ roRRAvg.ovData = 0.0F; roRRAvg.ovInitData = 0.0F; roRRAvg.override = OVERRIDE_RESET; + roRRSampleIntervalCounter = 0; // Initialize override structures for each conductivity sensor for ( sensor = FIRST_DD_COND_SENSOR; sensor < NUM_OF_CONDUCTIVITY_SENSORS; sensor++ ) @@ -325,7 +328,7 @@ * The calcRORejectionRatio function calculates the RO rejection ratio using * the P9 sensor conductivity value and P18 sensor conductivity value. * @details Inputs: P9 sensor conductivity, P18 sensor conductivity - * @details Outputs: RO rejection ratio + * @details Outputs: RO rejection ratio, Tank fill RO rejection ratio * @return none *************************************************************************/ static void calcRORejectionRatio( void ) @@ -356,31 +359,37 @@ *************************************************************************/ static void filterRORejectionRatioReadings( void ) { - // Filter RO rejection ratio - if ( roRRCount >= RO_RR_MOVING_AVG_NUM_OF_SAMPLES ) + F32 roRR = 0.0F; + + // Moving average samples are collected for every 100 msec + if ( ++roRRSampleIntervalCounter >= RO_RR_SAMPLE_COLLECTION_INTERVAL ) { - roRRRunningSum -= roRRSamples[ roRRSamplesNextIndex ]; - } + // Filter RO rejection ratio + if ( roRRCount >= RO_RR_MOVING_AVG_NUM_OF_SAMPLES ) + { + roRRRunningSum -= roRRSamples[ roRRSamplesNextIndex ]; + } - F32 roRR = getRORejectonRatio(); - roRRSamples[ roRRSamplesNextIndex ] = roRR; - roRRRunningSum += roRR; - roRRSamplesNextIndex = INC_WRAP( roRRSamplesNextIndex, 0, RO_RR_MOVING_AVG_NUM_OF_SAMPLES - 1 ); - roRRCount = INC_CAP( roRRCount, RO_RR_MOVING_AVG_NUM_OF_SAMPLES ); - roRRAvg.data = roRRRunningSum / (F32)roRRCount; + roRR = getRORejectonRatio(); + roRRSamples[ roRRSamplesNextIndex ] = roRR; + roRRRunningSum += roRR; + roRRSamplesNextIndex = INC_WRAP( roRRSamplesNextIndex, 0, RO_RR_MOVING_AVG_NUM_OF_SAMPLES - 1 ); + roRRCount = INC_CAP( roRRCount, RO_RR_MOVING_AVG_NUM_OF_SAMPLES ); + roRRAvg.data = roRRRunningSum / (F32)roRRCount; + roRRSampleIntervalCounter = 0; - // Update the Filter RO rejection ratio during tank fill if the tank is filling - if ( getCurrentGenPermeateState() == FP_GENP_TANK_FILL_STATE ) - { -// roRRTankFillAvg = getRORRAverage(); - roRRTankFillAvg = roRRAvg.data; + // Update the Filter RO rejection ratio during tank fill if the tank is filling + if ( getCurrentGenPermeateState() == FP_GENP_TANK_FILL_STATE ) + { + roRRTankFillAvg = roRRAvg.data; + } } } /*********************************************************************//** * @brief * The getRORejectonRatio function returns the RO rejection ratio - * @details \b Inputs: none + * @details \b Inputs: roRejectionRatio * @details \b Outputs: none * @return the RO rejection ratio in percentage *************************************************************************/ @@ -393,7 +402,7 @@ * @brief * The getTankFillRORejectionRatio function returns the RO rejection ratio * during tank fill state - * @details \b Inputs: none + * @details \b Inputs: roRejectionRatioTankFill * @details \b Outputs: none * @return the tank fill RO rejection ratio in percentage *************************************************************************/ @@ -405,7 +414,7 @@ /*********************************************************************//** * @brief * The getRORRAverage function returns the average RO rejection ratio - * @details \b Inputs: none + * @details \b Inputs: roRRAvg * @details \b Outputs: none * @return the average RO rejection ratio in percentage *************************************************************************/ @@ -420,7 +429,7 @@ * @brief * The getTankFillRORRAverage function returns the average RO rejection ratio * during tank fill state - * @details \b Inputs: none + * @details \b Inputs: roRRTankFillAvg * @details \b Outputs: none * @return the average tank fill RO rejection ratio in percentage *************************************************************************/ @@ -433,8 +442,10 @@ * @brief * The publishConductivitySensorsData function publishes DD conductivity data * at a set interval. - * @details \b Inputs: conductivityPublishTimerCounter - * @details \b Outputs: conductivityPublishTimerCounter + * @details \b Inputs: ddconductivityPublishTimerCounter, fpConductivityPublishTimerCounter, + * roRRPublishTimerCounter + * @details \b Outputs: ddconductivityPublishTimerCounter, fpConductivityPublishTimerCounter, + * roRRPublishTimerCounter, DD, FP, RO data broadcast message sent * @details \b Message \b Sent: MSG_ID_DD_CONDUCTIVITY_DATA to publish DD conductivity data. * @details \b Message \b Sent: MSG_ID_FP_CONDUCTIVITY_DATA to publish FP conductivity data. * @return none