Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -r0bb9cd0b4e437097ae2fe188f98a4a70723d2642 -re94e190c01863afb7fc43cf746f59ded8ae6c362 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 0bb9cd0b4e437097ae2fe188f98a4a70723d2642) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision e94e190c01863afb7fc43cf746f59ded8ae6c362) @@ -88,44 +88,45 @@ NUM_OF_TEMPSENSORS_EXEC_STATES, ///< Total number of exec states } TEMPSENSORS_EXEC_STATES_T; +/// Temperature sensor struct typedef struct { - F32 gain; - F32 refResistance; - F32 twoTempConversionCoef; - F32 zeroDegreeResistance; + F32 gain; ///< ADC gain + F32 refResistance; ///< ADC reference resistance + F32 conversionCoef; ///< ADC conversion coefficient + F32 zeroDegreeResistance; ///< ADC degree resistance - S32 rawADCReads[ MAX_NUM_OF_RAW_ADC_SAMPLES ]; - S32 adcNextIndex; - S32 adcRunningSum; + S32 rawADCReads[ MAX_NUM_OF_RAW_ADC_SAMPLES ]; ///< Raw ADC reads array + S32 adcNextIndex; ///< Next ADC read index + S32 adcRunningSum; ///< ADC running sum - U32 readCount; - U32 internalErrorCount; + U32 readCount; ///< Read counts from FGPA + U32 internalErrorCount; ///< Internal error counts - OVERRIDE_F32_T temperatureValues; + OVERRIDE_F32_T temperatureValues; ///< Temperature values array } TEMP_SENSOR_T; // ********** private data ********** -static SELF_TEST_STATUS_T tempSensorsSelfTestResult; ///< Self test result of the TemperatureSensors module -static TEMPSENSORS_SELF_TEST_STATES_T tempSensorsSelfTestState; ///< TemperatureSensor self test state -static TEMPSENSORS_EXEC_STATES_T tempSensorsExecState; ///< TemperatureSensor exec state -static TEMP_SENSOR_T tempSensors [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors' data structure +static SELF_TEST_STATUS_T tempSensorsSelfTestResult; ///< Self test result of the TemperatureSensors module +static TEMPSENSORS_SELF_TEST_STATES_T tempSensorsSelfTestState; ///< TemperatureSensor self test state +static TEMPSENSORS_EXEC_STATES_T tempSensorsExecState; ///< TemperatureSensor exec state +static TEMP_SENSOR_T tempSensors [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors' data structure -static U32 elapsedTime; ///< Elapsed time variable -static U32 internalHeatersConversionTimer; +static U32 elapsedTime; ///< Elapsed time variable +static U32 internalHeatersConversionTimer; ///< Conversion timer variable to calculate the heaters internal temperature -static U32 inletWaterTempOutOfRangeCounter; -static U32 inletWaterTempInRangeCounter; +static U32 inletWaterTempOutOfRangeCounter; ///< Temperature out of range persistence counter +static U32 inletWaterTempInRangeCounter; ///< Temperature in range persistence counter -static F32 tempValuesForPublication [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors data publication array -static U32 dataPublicationTimerCounter; ///< Temperature sensors data publish timer counter +static F32 tempValuesForPublication [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors data publication array +static U32 dataPublicationTimerCounter; ///< Temperature sensors data publish timer counter static OVERRIDE_U32_T tempSensorsPublishInterval = { TEMP_SENSORS_DATA_PUBLISH_INTERVAL, - TEMP_SENSORS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Temperature sensors publish time interval override + TEMP_SENSORS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Temperature sensors publish time interval override -static const F32 positiveTCExpA0 = 0.118597600000E0; ///< K TC positive temperature exponent coefficient A0 -static const F32 positiveTCExpA1 = -0.118343200000E-3; ///< K TC positive temperature exponent coefficient A1 -static const F32 positiveTCExpA2 = 0.126968600000E3; ///< K TC positive temperature exponent coefficient A2 +static const F32 positiveTCExpA0 = 0.118597600000E0; ///< K TC positive temperature exponent coefficient A0 +static const F32 positiveTCExpA1 = -0.118343200000E-3; ///< K TC positive temperature exponent coefficient A1 +static const F32 positiveTCExpA2 = 0.126968600000E3; ///< K TC positive temperature exponent coefficient A2 /// Thermocouple correction coefficients for positive cold junction temperature static const F32 positiveTCCoeffs [ SIZE_OF_THERMOCOUPLE_COEFFICIENTS ] = { @@ -225,12 +226,12 @@ tempSensors [ TEMPSENSORS_INLET_DIALYSATE ].zeroDegreeResistance = TRIMMER_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; // Initialize the heaters internal thermocouples constants - tempSensors [ TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE ].twoTempConversionCoef = HEATERS_INTERNAL_TC_ADC_TO_TEMP_CONVERSION_COEFF; - tempSensors [ TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE ].twoTempConversionCoef = HEATERS_INTERNAL_TC_ADC_TO_TEMP_CONVERSION_COEFF; + tempSensors [ TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE ].conversionCoef = HEATERS_INTERNAL_TC_ADC_TO_TEMP_CONVERSION_COEFF; + tempSensors [ TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE ].conversionCoef = HEATERS_INTERNAL_TC_ADC_TO_TEMP_CONVERSION_COEFF; // Initialize the heaters cold junction constants - tempSensors [ TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ].twoTempConversionCoef = HEATERS_COLD_JUNCTION_ADC_TO_TEMP_CONVERSION_COEFF; - tempSensors [ TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ].twoTempConversionCoef = HEATERS_COLD_JUNCTION_ADC_TO_TEMP_CONVERSION_COEFF; + tempSensors [ TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ].conversionCoef = HEATERS_COLD_JUNCTION_ADC_TO_TEMP_CONVERSION_COEFF; + tempSensors [ TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ].conversionCoef = HEATERS_COLD_JUNCTION_ADC_TO_TEMP_CONVERSION_COEFF; // Initialize the heaters calculated internal temperature sensors. The constants are zero since they will not be used for conversion } @@ -367,7 +368,7 @@ return temperature; } -// Private functions +// ********** Private functions ********** /************************************************************************* * @brief @@ -589,7 +590,7 @@ (U32)tempSensors [ sensorIndex ].gain, (U32)tempSensors [ sensorIndex ].refResistance, (U32)tempSensors [ sensorIndex ].zeroDegreeResistance, - tempSensors [ sensorIndex ].twoTempConversionCoef ); + tempSensors [ sensorIndex ].conversionCoef ); tempSensors[ sensorIndex ].temperatureValues.data = temperature; } @@ -653,14 +654,14 @@ (U32) tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].gain, (U32) tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].refResistance, (U32) tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].zeroDegreeResistance, - tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].twoTempConversionCoef ); + tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].conversionCoef ); S32 const tpoConvertedADC = ( (S32)getFPGATPoTemp() & MASK_OFF_U32_MSB ); F32 const tpoTemperature = getADC2TempConversion( tpoConvertedADC, (U32) tempSensors[ TEMPSENSORS_OUTLET_PRIMARY_HEATER ].gain, (U32) tempSensors[ TEMPSENSORS_OUTLET_PRIMARY_HEATER ].refResistance, (U32) tempSensors[ TEMPSENSORS_OUTLET_PRIMARY_HEATER ].zeroDegreeResistance, - tempSensors[ TEMPSENSORS_OUTLET_PRIMARY_HEATER ].twoTempConversionCoef ); + tempSensors[ TEMPSENSORS_OUTLET_PRIMARY_HEATER ].conversionCoef ); F32 const tempDiff = fabs(tpiTemperature - tpoTemperature); if ( tempDiff > MAX_ALLOWED_TEMP_DELTA_BETWEEN_SENSORS ) {