Index: firmware/App/Controllers/ConductivitySensors.c =================================================================== diff -u -r0ee5103ebceb698eadac7b18398471361811a151 -rfd89ed3ac616c0ee40e3ffc357d379cb2f4aa12a --- firmware/App/Controllers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 0ee5103ebceb698eadac7b18398471361811a151) +++ firmware/App/Controllers/ConductivitySensors.c (.../ConductivitySensors.c) (revision fd89ed3ac616c0ee40e3ffc357d379cb2f4aa12a) @@ -144,6 +144,7 @@ static EMSTAT_READ_T emstatBoardRead[ NUM_OF_EMSTAT_BOARDS ]; ///< EMSTAT board read. static COND_SENSOR_STATUS_T condSensorStatus[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Conductivity sensors status. static DG_COND_SENSORS_CAL_RECORD_T condSensorsCalRecord; ///< Conductivity sensors' calibration record. +static CAL_DATA_DG_COND_SENSORS_T condSensorCalTable[ NUM_OF_CONDUCTIVITY_SENSORS ]; ///< Conductivity sensors calibration table. // ********** private function prototypes ********** @@ -174,6 +175,32 @@ { memset( &condSensorStatus[ i ], 0x0, sizeof( COND_SENSOR_STATUS_T ) ); benignPolynomialCalRecord( &condSensorsCalRecord.condSensors[ i ] ); + + switch( i ) + { + case CONDUCTIVITYSENSORS_CPI_SENSOR: + condSensorCalTable[ i ] = CAL_DATA_CPI_COND_SENSOR; + break; + + case CONDUCTIVITYSENSORS_CPO_SENSOR: + condSensorCalTable[ i ] = CAL_DATA_CPO_COND_SENSOR; + break; + + case CONDUCTIVITYSENSORS_CD1_SENSOR: + condSensorCalTable[ i ] = CAL_DATA_CD1_COND_SENSOR; + break; + + case CONDUCTIVITYSENSORS_CD2_SENSOR: + condSensorCalTable[ i ] = CAL_DATA_CD2_COND_SENSOR; + break; + +#ifndef _VECTORCAST_ + default: + // This switch is in a for loop so VectorCAST cannot reach to default. + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_CONDUCTIVITY_SENSOR_ID, i ) + break; +#endif + } } // Reset all the read packages of the Emstat boards @@ -371,6 +398,36 @@ /*********************************************************************//** * @brief + * The setCondcutivitySensorCalTable function sets the calibration table to + * be use of the corresponding conductivity sensor. + * @details Inputs: none + * @details Outputs: condSensorCalTable + * @param sensor the conductivity sensor ID to use the calibration table for + * @param calTable the calibration table to be used for the selected conductivity + * sensor + * @return none + *************************************************************************/ +void setCondcutivitySensorCalTable( CONDUCTIVITY_SENSORS_T sensor, CAL_DATA_DG_COND_SENSORS_T calTable ) +{ + if ( sensor < NUM_OF_CONDUCTIVITY_SENSORS ) + { + if ( calTable < NUM_OF_CAL_DATA_COND_SENSORS ) + { + condSensorCalTable[ sensor ] = calTable; + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_DG_INVALID_COND_SNSNR_CAL_TABLE_SELECTED, calTable ) + } + } + else + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_CONDUCTIVITY_SENSOR_ID, sensor ) + } +} + +/*********************************************************************//** + * @brief * The getConductivityValue function gets the compensated conductivity * value for a given conductivity sensor id. * @details Inputs: compensatedConductivityValues[] @@ -411,7 +468,7 @@ static F32 calcCompensatedConductivity( F32 conductivity, F32 temperature ) { // EC = EC_25 * (1 + temp_coef * ( temperature - 25 )) - F32 compensatedCoef = ( 1.0F + ( COND_SENSOR_TEMPERATURE_COEF * ( temperature - COND_SENSOR_REFERENCE_TEMPERATURE ) ) ); + F32 compensatedCoef = ( 1.0F + ( COND_SENSOR_TEMPERATURE_COEF * ( temperature - COND_SENSOR_REFERENCE_TEMPERATURE ) ) ); return conductivity / compensatedCoef; } @@ -426,8 +483,8 @@ *************************************************************************/ static void calcRORejectionRatio( void ) { - F32 cpi = getConductivityValue( CONDUCTIVITYSENSORS_CPI_SENSOR ); - F32 cpo = getConductivityValue( CONDUCTIVITYSENSORS_CPO_SENSOR ); + F32 cpi = getConductivityValue( CONDUCTIVITYSENSORS_CPI_SENSOR ); + F32 cpo = getConductivityValue( CONDUCTIVITYSENSORS_CPO_SENSOR ); roRejectionRatio = RO_REJECTION_RATIO_OUT_OF_RANGE_VALUE; @@ -536,8 +593,8 @@ *************************************************************************/ static void processEmstatBoard( EMSTAT_BOARD_T board ) { - U08 emstatByte = 0; - U16 rxFifoCount = 0; + U08 emstatByte = 0; + U16 rxFifoCount = 0; switch ( board ) { @@ -633,7 +690,6 @@ *************************************************************************/ static void processEmstatMeasurementDataPackets( U08 boardSensorIndex, EMSTAT_READ_T* readPackage, EMSTAT_VARIABLE_T* receivedPackets ) { - CONDUCTIVITY_SENSORS_T sensorId = readPackage->sensors[ boardSensorIndex ].condSnsr; BOOL convStatus = hexStrToDec( (U08*)&receivedPackets->status, &condSensorStatus[ sensorId ].sensorStatus, sizeof( receivedPackets->status ) ); BOOL isSensorStatusBad = ( EMSTAT_PICO_STATUS_TIMING_NOT_MET == condSensorStatus[ sensorId ].sensorStatus ? TRUE : FALSE ); @@ -695,27 +751,14 @@ *************************************************************************/ static F32 getCalibrationAppliedConductivityValue( U32 sensorId, F32 compensatedValue ) { - CAL_DATA_DG_COND_SENSORS_T id = (CAL_DATA_DG_COND_SENSORS_T)sensorId; - F32 conductivity = 0.0F; + CAL_DATA_DG_COND_SENSORS_T calTableId = condSensorCalTable[ sensorId ]; + F32 conductivity = 0.0F; - if ( DG_MODE_CHEM == getCurrentOperationMode() ) - { - // If the mode is in chemical disinfect, use the chemical disinfect calibration data for CD1 and CD2 - if ( CAL_DATA_CD1_COND_SENSOR == id ) - { - id = CAL_DATA_CD1_CHEM_DIS_COND_SENSOR; - } - else if ( CAL_DATA_CD2_COND_SENSOR == id ) - { - id = CAL_DATA_CD2_CHEM_DIS_COND_SENSOR; - } - } - - conductivity = pow( compensatedValue, 4 ) * condSensorsCalRecord.condSensors[ id ].fourthOrderCoeff + - pow( compensatedValue, 3 ) * condSensorsCalRecord.condSensors[ id ].thirdOrderCoeff + - pow( compensatedValue, 2 ) * condSensorsCalRecord.condSensors[ id ].secondOrderCoeff + - compensatedValue * condSensorsCalRecord.condSensors[ id ].gain + - condSensorsCalRecord.condSensors[ id ].offset; + conductivity = pow( compensatedValue, 4 ) * condSensorsCalRecord.condSensors[ calTableId ].fourthOrderCoeff + + pow( compensatedValue, 3 ) * condSensorsCalRecord.condSensors[ calTableId ].thirdOrderCoeff + + pow( compensatedValue, 2 ) * condSensorsCalRecord.condSensors[ calTableId ].secondOrderCoeff + + compensatedValue * condSensorsCalRecord.condSensors[ calTableId ].gain + + condSensorsCalRecord.condSensors[ calTableId ].offset; return conductivity; }