Index: firmware/App/Controllers/ConductivitySensors.c =================================================================== diff -u -r318d977d9d47b1860f09b93f06cc5885723f3e77 -r43fcf6140ca7b3ec665067653a7d64dce65d71d4 --- firmware/App/Controllers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 318d977d9d47b1860f09b93f06cc5885723f3e77) +++ firmware/App/Controllers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 43fcf6140ca7b3ec665067653a7d64dce65d71d4) @@ -34,31 +34,33 @@ #define COND_SENSOR_REFERENCE_TEMPERATURE 25 ///< Reference temperature for conductivity sensor #define COND_SENSOR_REPORT_PERIOD (1000 / TASK_PRIORITY_INTERVAL) ///< Broadcast conductivity values message every 1000 ms. -#define COND_SENSOR_CPI_CPO_MAX_VALUE 2000 ///< TBD -#define COND_SENSOR_CPI_CPO_MIN_VALUE 100 ///< TBD +#define COND_SENSOR_CPI_CPO_MAX_VALUE 2000 ///< Maximum inlet water conductivity +#define COND_SENSOR_CPI_CPO_MIN_VALUE 100 ///< Minimum inlet water conductivity #define MAX_ALLOWED_UNCHANGED_CONDUCTIVITY_READS 100 ///< New reading every 640 ms, expect to get new reading in 1s // ********** private data ********** +/// Conductivity sensors' associated temperature sensors static U32 associateTempSensor[ NUM_OF_CONDUCTIVITY_SENSORS ] = { - TEMPSENSORS_INLET_PRIMARY_HEATER_TEMP_SENSOR, - TEMPSENSORS_OUTLET_PRIMARY_HEATER_TEMP_SENSOR, - TEMPSENSORS_CONDUCTIVITY_SENSOR_1_TEMP_SENSOR, - TEMPSENSORS_CONDUCTIVITY_SENSOR_2_TEMP_SENSOR, + TEMPSENSORS_INLET_PRIMARY_HEATER_TEMP_SENSOR, ///< Inlet temperature sensor + TEMPSENSORS_OUTLET_PRIMARY_HEATER_TEMP_SENSOR, ///< Outlet temperature sensor + TEMPSENSORS_CONDUCTIVITY_SENSOR_1_TEMP_SENSOR, ///< Conductivity sensor 1 temperature sensor + TEMPSENSORS_CONDUCTIVITY_SENSOR_2_TEMP_SENSOR, ///< Conductivity sensor 2 temperature sensor }; -static U32 readCount[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Read count for conductivity readings. -static U32 internalErrorCount[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Internal error count for conductivity readings. -static OVERRIDE_F32_T compensatedConductivityValues[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Latest conductivity values. +static U08 readCount[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Read count for conductivity readings. +static U32 internalErrorCount[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Internal error count for conductivity readings. +static OVERRIDE_F32_T compensatedConductivityValues[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Latest conductivity values. -static OVERRIDE_U32_T conductivityDataPublishInterval = { COND_SENSOR_REPORT_PERIOD, COND_SENSOR_REPORT_PERIOD, 0, 0 }; -static U32 conductivityDataPublicationTimerCounter = 0; +static OVERRIDE_U32_T conductivityDataPublishInterval = { COND_SENSOR_REPORT_PERIOD, + COND_SENSOR_REPORT_PERIOD, 0, 0 }; ///< Conductivity sensors publish time interval override +static U32 conductivityDataPublicationTimerCounter = 0; ///< Conductivity sensors data publish timer counter // ********** private function prototypes ********** static void processCPiCPoSensorRead( U32 sensorId, U32 fgpaRead, U08 fpgaReadCount, U08 fpgaErrorCount ); -static F32 getCompensatedConductivity( U32 conductivity, F32 temperature); +static F32 calcCompensatedConductivity( U32 conductivity, F32 temperature); static DATA_GET_PROTOTYPE( U32, getConductivityDataPublishInterval ); @@ -91,15 +93,15 @@ /************************************************************************* * @brief - * The execConductivitySensors function gets conductivity sensors' data from FPGA and advertises them over CAN. + * The execConductivitySensors function gets conductivity sensors' latest + * readings from FPGA and advertises them over CAN. * @details * Inputs : none - * Outputs : Advertising conductivity sensors' data. + * Outputs : Advertising conductivity sensors' latest readings. * @return none *************************************************************************/ void execConductivitySensors( void ) { - processCPiCPoSensorRead( CONDUCTIVITYSENSORS_CPI_SENSOR, getFPGACPi(), getFPGACPiReadCount(), getFPGACPiErrorCount() ); processCPiCPoSensorRead( CONDUCTIVITYSENSORS_CPO_SENSOR, getFPGACPi(), getFPGACPoReadCount(), getFPGACPoErrorCount() ); @@ -109,21 +111,22 @@ broadcastConductivityData( getConductivityValue(CONDUCTIVITYSENSORS_CPI_SENSOR), getConductivityValue(CONDUCTIVITYSENSORS_CPO_SENSOR), 0, - 0); + 0 ); } } /************************************************************************* * @brief - * The checkWaterConductivity function checks conductivity value + * The checkInletWaterConductivity function checks conductivity value * @details * Inputs : none * Outputs : Trigger alarms when conductivity is out of allowed range * @param state : Operational state of DG * @return none *************************************************************************/ -void checkWaterConductivity( F32 conductivity, U32 state ) +void checkInletWaterConductivity( U32 state ) { + F32 const conductivity = getConductivityValue(CONDUCTIVITYSENSORS_CPI_SENSOR); if ( conductivity > COND_SENSOR_CPI_CPO_MAX_VALUE ) { SET_ALARM_WITH_2_F32_DATA( ALARM_ID_INLET_WATER_HIGH_CONDUCTIVITY, conductivity, state ); @@ -168,19 +171,19 @@ return result; } - /************************************************************************* * @brief - * The getCompensatedConductivity function calculates the compensated + * The calcCompensatedConductivity function calculates the compensated * conductivity based on given temperature and conductivity taken at * reference temperature of 25 Celcius. * @details * Inputs : temperature * Outputs : none - * @param conductivity, temperature + * @param conductivity : Conductivity value + * @param temperature : Temperature to compensate conductivity with * @return compensated conductivity based on temperature *************************************************************************/ -static F32 getCompensatedConductivity( U32 conductivity, F32 temperature) +static F32 calcCompensatedConductivity( U32 conductivity, F32 temperature) { // EC = EC_25 * (1 + temp_coef * (temperature - 25)) F32 const compensatedCoef = ( 1 + ( COND_SENSOR_TEMPERATURE_COEF * (temperature - COND_SENSOR_REFERENCE_TEMPERATURE) ) ); @@ -196,19 +199,23 @@ * @details * Inputs : none * Outputs : none - * @param sensorId, fgpaRead, fpgaReadCount, fpgaErrorCount + * @param sensorId : Conductivity sensor id to process + * @param fgpaRead : FPGA conductivity reading value + * @param fpgaReadCount : FPGA read count + * @param fpgaErrorCount : FPGA error count * @return none *************************************************************************/ static void processCPiCPoSensorRead( U32 sensorId, U32 fgpaRead, U08 fpgaReadCount, U08 fpgaErrorCount ) { if ( fpgaErrorCount == 0 ) { - if ( (readCount[ sensorId ] < fpgaReadCount) || ( readCount[ sensorId ] > fpgaReadCount )) { + if ( (readCount[ sensorId ] != fpgaReadCount) ) + { F32 const temperature = getTemperatureValue( associateTempSensor[ sensorId ] ); F32 const conductivity = ( (F32)( fgpaRead ) / COND_SENSOR_DECIMAL_CONVERSION ); readCount[ sensorId ] = fpgaReadCount; internalErrorCount[ sensorId ] = 0; - compensatedConductivityValues[ sensorId ].data = getCompensatedConductivity( conductivity, temperature ); + compensatedConductivityValues[ sensorId ].data = calcCompensatedConductivity( conductivity, temperature ); } else {