Index: firmware/App/Controllers/Thermistors.c =================================================================== diff -u -rf9b3862d01ce6c64bd05b8649e69b44fa155b8e0 -r1510aec1871295f04541f1b932211d4ac621cc48 --- firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision f9b3862d01ce6c64bd05b8649e69b44fa155b8e0) +++ firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision 1510aec1871295f04541f1b932211d4ac621cc48) @@ -16,16 +16,16 @@ #define THERMISTORS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Thermistors publish data time interval. #define THERMISTORS_ADC_READ_INTERVAL ( MS_PER_SECOND / ( 2 * TASK_GENERAL_INTERVAL ) ) ///< Thermistors ADC read time interval. -#define ADC_FPGA_READ_DELAY_COUNT 1.0 ///< FGPA read delay upon startup. -#define ONBOARD_THERMISTOR_SOURCE_VOLTAGE 3.0 ///< Onboard thermistor source voltage. -#define ONBOARD_THERMISTOR_REFERENCE_RESISTOR 10000.0 ///< Onboard thermistor reference resistor. -#define ONBOARD_THERMISTOR_BETA_VALUE 3380.0 ///< Onboard thermistor beta value. -#define ONBOARD_THERMISTOR_REFERENCE_TEMPERATURE 298.0 ///< Onboard thermistor reference temperature. +#define ADC_FPGA_READ_DELAY_COUNT 1.0 ///< FGPA read delay upon startup. #define TWELVE_BIT_RESOLUTION 4096.0 ///< 12 bit resolution conversion. +#define THERMISTOR_REFERENCE_VOLTAGE 3.0 ///< Thermistors source voltage. +#define THERMISTOR_REFERENCE_RESISTOR_AT_25 10000.0 ///< Thermistors reference resistor in ohms. +#define THERMISTOR_REFERENCE_TEMPERATURE 298.0 ///< Thermistors reference temperature in kelvin. +#define ONBOARD_THERMISTOR_BETA_VALUE 3380.0 ///< Onboard thermistor beta value. +#define POWER_SUPPLY_THERMISTOR_BETA_VALUE 3345.0 ///< Power supply beta value. #define CELSIUS_TO_KELVIN_CONVERSION 273.15 ///< Celsius to Kelvin temperature conversion. -#define ADC_TEMP_SENSORS_CONVERSION_CONST 272.5 ///< ADC temperature sensors conversion constant. -#define MIN_ALLOWED_TEMPERATURE 0 ///< Thermistors/sensors minimum allowed temperature reading. -#define MAX_ALLOWED_TEMPERATURE 70 ///< Thermistors/sensors maximum allowed temperature reading. +#define MIN_ALLOWED_TEMPERATURE 5.0 ///< Thermistors/sensors minimum allowed temperature reading. +#define MAX_ALLOWED_TEMPERATURE 70.0 ///< Thermistors/sensors maximum allowed temperature reading. #define MAX_ALLOWED_TEMP_OUT_OF_RANGE_COUNT ( MS_PER_SECOND / ( 4 * TASK_GENERAL_INTERVAL ) ) ///< Thermistors/sensors maximum allowed temperature out of range count. /// Thermistors self test states @@ -61,12 +61,9 @@ static U32 dataPublishCounter; ///< Thermistors data publish timer counter static U32 adcReadCounter; ///< Thermistors ADC read counter -static const F32 fpgaBoardTempSensorConvCoeff = 503.975 / TWELVE_BIT_RESOLUTION; ///< FPGA board temperature sensor conversion coefficient -static const F32 adcTempSensorsConversionCoeff1 = 1.0 / 13584.0; ///< ADC temperature sensors conversion coefficient 1 -static const F32 adcTempSensorsConversionCoeff2 = 0x800000 / 13584; ///< ADC temperature sensors conversion coefficient 2 -static const F32 onBoardThermistorVoltageConvCoeff = ONBOARD_THERMISTOR_SOURCE_VOLTAGE / TWELVE_BIT_RESOLUTION; ///< On board thermistor ADC to voltage conversion coefficient -static const F32 onBoardThermistorBetaValueInv = 1 / ONBOARD_THERMISTOR_BETA_VALUE; ///< On board thermistor beta value inverse -static const F32 onBoardThermistorRefTempInv = 1 / ONBOARD_THERMISTOR_REFERENCE_TEMPERATURE; ///< On board thermistor reference inverse +static const F32 thermistorVoltageConvCoeff = THERMISTOR_REFERENCE_VOLTAGE + / TWELVE_BIT_RESOLUTION; ///< On board thermistor ADC to voltage conversion coefficient +static const F32 onBoardThermistorRefTempInv = 1 / THERMISTOR_REFERENCE_TEMPERATURE; ///< On board thermistor reference inverse // ********** private function prototypes ********** @@ -77,7 +74,7 @@ static void monitorThermistors( void ); static void convertADCtoTemperature( void ); -static F32 calculateOnBoardThemristorTemperature( U32 adcValue ); +static F32 calculateTemperature( U32 adcValue, F32 betaValue ); static void publishThermistorsData( void ); static U32 getPublishThermistorsDataInterval( void ); @@ -221,12 +218,6 @@ // Get all the raw readings in ADC thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].rawADCRead = getIntADCReading( INT_ADC_BOARD_THERMISTOR ); - thermistorsStatus[ TEMPSENSOR_FPGA_SENSOR ].rawADCRead = getFPGABoardTemp(); - thermistorsStatus[ TEMPSENSOR_LOAD_CELL_A1_B1 ].rawADCRead = getFPGALoadCellsA1B1Temp(); - thermistorsStatus[ TEMPSENSOR_LOAD_CELL_A2_B2 ].rawADCRead = getFPGALoadCellsA2B2Temp(); - thermistorsStatus[ TEMPSENSOR_INTERNAL_THDO_RTD ].rawADCRead = getFPGATHDoInternalTemp(); - thermistorsStatus[ TEMPSENSOR_INTERNAL_TDI_RTD ].rawADCRead = getFPGATDiInternalTemp(); - thermistorsStatus[ TEMPSENSOR_INTERNAL_CONDUCTIVITY ].rawADCRead = getFPGAConductivitySnsrInternalTemp(); thermistorsStatus[ THERMISTOR_POWER_SUPPLY_1 ].rawADCRead = getIntADCReading( INT_ADC_POWER_SUPPLY_1_THERMISTOR ); thermistorsStatus[ THERMISTOR_POWER_SUPPLY_2 ].rawADCRead = getIntADCReading( INT_ADC_POWER_SUPPLY_2_THERMISTOR ); @@ -291,15 +282,9 @@ if ( ++adcReadCounter >= THERMISTORS_ADC_READ_INTERVAL ) { // Get all the raw readings in ADC - thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].rawADCRead = getIntADCReading( INT_ADC_BOARD_THERMISTOR ); - thermistorsStatus[ TEMPSENSOR_FPGA_SENSOR ].rawADCRead = getFPGABoardTemp(); - thermistorsStatus[ TEMPSENSOR_LOAD_CELL_A1_B1 ].rawADCRead = getFPGALoadCellsA1B1Temp(); - thermistorsStatus[ TEMPSENSOR_LOAD_CELL_A2_B2 ].rawADCRead = getFPGALoadCellsA2B2Temp(); - thermistorsStatus[ TEMPSENSOR_INTERNAL_THDO_RTD ].rawADCRead = getFPGATHDoInternalTemp(); - thermistorsStatus[ TEMPSENSOR_INTERNAL_TDI_RTD ].rawADCRead = getFPGATDiInternalTemp(); - thermistorsStatus[ TEMPSENSOR_INTERNAL_CONDUCTIVITY ].rawADCRead = getFPGAConductivitySnsrInternalTemp(); - thermistorsStatus[ THERMISTOR_POWER_SUPPLY_1 ].rawADCRead = getIntADCReading( INT_ADC_POWER_SUPPLY_1_THERMISTOR ); - thermistorsStatus[ THERMISTOR_POWER_SUPPLY_2 ].rawADCRead = getIntADCReading( INT_ADC_POWER_SUPPLY_2_THERMISTOR ); + thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].rawADCRead = getIntADCReading( INT_ADC_BOARD_THERMISTOR ); + thermistorsStatus[ THERMISTOR_POWER_SUPPLY_1 ].rawADCRead = getIntADCReading( INT_ADC_POWER_SUPPLY_1_THERMISTOR ); + thermistorsStatus[ THERMISTOR_POWER_SUPPLY_2 ].rawADCRead = getIntADCReading( INT_ADC_POWER_SUPPLY_2_THERMISTOR ); // Zero the counter for the next round of reading adcReadCounter = 0; @@ -374,26 +359,13 @@ switch ( thermistor ) { case THERMISTOR_ONBOARD_NTC: - temperature = calculateOnBoardThemristorTemperature( rawADC ); + temperature = calculateTemperature( rawADC, ONBOARD_THERMISTOR_BETA_VALUE ); thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].temperatureValue.data = temperature; break; - case TEMPSENSOR_FPGA_SENSOR: - // Temperature(C) = ((ADC x 503.975) / 4096) - 273.15 - // The value of 503.975/4096 was done in a const variable to prevent the division all the time - temperature = ( rawADC * fpgaBoardTempSensorConvCoeff ) - CELSIUS_TO_KELVIN_CONVERSION; - thermistorsStatus[ TEMPSENSOR_FPGA_SENSOR ].temperatureValue.data = temperature; - break; - - // All these sensors have the same conversion procedure - case TEMPSENSOR_LOAD_CELL_A1_B1: - case TEMPSENSOR_LOAD_CELL_A2_B2: - case TEMPSENSOR_INTERNAL_THDO_RTD: - case TEMPSENSOR_INTERNAL_TDI_RTD: - case TEMPSENSOR_INTERNAL_CONDUCTIVITY: - // Temperature(C) = ((ADC - 0x800000)/13584) - 272.5 - // The values for 1/0x800000 and 0x800000/13584 were done in a const variable to prevent the division all the time - temperature = ( ( rawADC * adcTempSensorsConversionCoeff1 ) - adcTempSensorsConversionCoeff2 ) - ADC_TEMP_SENSORS_CONVERSION_CONST; + case THERMISTOR_POWER_SUPPLY_1: + case THERMISTOR_POWER_SUPPLY_2: + temperature = calculateTemperature( rawADC, POWER_SUPPLY_THERMISTOR_BETA_VALUE ); thermistorsStatus[ thermistor ].temperatureValue.data = temperature; break; @@ -413,27 +385,28 @@ * onBoardThermistorBetaValueInv * @details Outputs: none * @param ADC value to be converted into temperature in C + * @param beta value which is used to calculate temperature from ADC * @return calculated temperature in C *************************************************************************/ -static F32 calculateOnBoardThemristorTemperature( U32 adcValue ) +static F32 calculateTemperature( U32 adcValue, F32 betaValue ) { /* * voltage = ADC x 3 / 2^12 * voltage = 3 x 10 / ( 10 + R(T) ) - * R(T) = 10000 x e^(3380 x (1/T - 1/298)) + * R(T) = 10000 x e^(beta x (1/T - 1/298)) * Solve for T which is temperature in Kelvin */ // Voltage = ADC x 3 / 2^12 for 12 bits resolution and a 3V ADC // The value of 3 / 2^12 has been calculated in a const to prevent the division again - F32 const thermistorVoltage = adcValue * onBoardThermistorVoltageConvCoeff; + F32 const thermistorVoltage = adcValue * thermistorVoltageConvCoeff; // Calculate the thermistor resistor by solving: thermistorVoltage = (3 x 10) / (10 + R(T)) - F32 const thermistorResistor = ( ( ONBOARD_THERMISTOR_REFERENCE_RESISTOR * ONBOARD_THERMISTOR_SOURCE_VOLTAGE ) - - ( ONBOARD_THERMISTOR_REFERENCE_RESISTOR * thermistorVoltage ) ) / thermistorVoltage; + F32 const thermistorResistor = ( ( THERMISTOR_REFERENCE_RESISTOR_AT_25 * THERMISTOR_REFERENCE_VOLTAGE ) - + ( THERMISTOR_REFERENCE_RESISTOR_AT_25 * thermistorVoltage ) ) / thermistorVoltage; // 1/T = Ln(thermistorResistor/10000)/3380 + 1/298 - F32 const invTemperature = ( logf( thermistorResistor / ONBOARD_THERMISTOR_REFERENCE_RESISTOR ) / ONBOARD_THERMISTOR_BETA_VALUE ) + + F32 const invTemperature = ( logf( thermistorResistor / THERMISTOR_REFERENCE_RESISTOR_AT_25 ) / betaValue ) + onBoardThermistorRefTempInv; // Inverse the value to get the temperature in Kelvin and then convert it to Celsius @@ -478,12 +451,6 @@ // Get all the sensors/thermistors temperature values for publication sensorsData.onboardThermistor = getThermistorTemperatureValue( THERMISTOR_ONBOARD_NTC ); - sensorsData.fpgaBoardTempSensor = getThermistorTemperatureValue( TEMPSENSOR_FPGA_SENSOR ); - sensorsData.loadCellA1TempSensor = getThermistorTemperatureValue( TEMPSENSOR_LOAD_CELL_A1_B1 ); - sensorsData.loadCellA2TempSensor = getThermistorTemperatureValue( TEMPSENSOR_LOAD_CELL_A2_B2 ); - sensorsData.rtdInternalTempSensor = getThermistorTemperatureValue( TEMPSENSOR_INTERNAL_THDO_RTD ); - sensorsData.rtdTDiInternalTempSensor = getThermistorTemperatureValue( TEMPSENSOR_INTERNAL_TDI_RTD ); - sensorsData.conductivityTempSensor = getThermistorTemperatureValue( TEMPSENSOR_INTERNAL_CONDUCTIVITY ); sensorsData.powerSupply1Thermistor = getThermistorTemperatureValue( THERMISTOR_POWER_SUPPLY_1 ); sensorsData.powerSupply2Thermistor = getThermistorTemperatureValue( THERMISTOR_POWER_SUPPLY_2 );