Index: firmware/App/Controllers/Thermistors.c =================================================================== diff -u -rc0ef736096da93e4d094f2408146f0238fd2328a -r87e007b4910c7369d71e769a35f82837b64eecf4 --- firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision c0ef736096da93e4d094f2408146f0238fd2328a) +++ firmware/App/Controllers/Thermistors.c (.../Thermistors.c) (revision 87e007b4910c7369d71e769a35f82837b64eecf4) @@ -37,7 +37,9 @@ #define THERMISTORS_ADC_READ_INTERVAL ( MS_PER_SECOND / ( 2 * TASK_GENERAL_INTERVAL ) ) ///< Thermistors ADC read time interval. #define ADC_FPGA_READ_DELAY_COUNT 1.0F ///< FGPA read delay upon startup. #define TWELVE_BIT_RESOLUTION 4096U ///< 12 bit resolution conversion. +#define TEN_BIT_RESOLUTION 1024U ///< 10 bit resolution conversion. #define THERMISTOR_REFERENCE_VOLTAGE 3.0F ///< Thermistors source voltage. +#define THERMISTOR_FPGA_REF_VOLTAGE 5.0F ///< Onboard NTC, PS2 source voltage (read by FPGA). #define THERMISTOR_REFERENCE_RESISTOR_AT_25 10000.0F ///< Thermistors reference resistor in ohms. #define THERMISTOR_REFERENCE_TEMPERATURE 298.0F ///< Thermistors reference temperature in kelvin. #define THERMISTOR_BETA_VALUE 3380.0F ///< Thermistors beta value. @@ -60,6 +62,8 @@ { S32 rawADCRead; ///< Thermistor raw ADC read. OVERRIDE_F32_T temperatureValue; ///< Thermistor temperature value. + F32 voltageReference; ///< Thermistor voltage reference. + F32 adcBitResolution; ///< Thermistor ADC Bit resolution } THERMISTOR_T; static THERMISTORS_EXEC_STATES_T thermistorsExecState; ///< Thermistors exec state. @@ -80,7 +84,7 @@ static void monitorThermistors( void ); static void convertADC2Temperature( void ); -static F32 calculateThemristorTemperature( U32 adcValue ); +static F32 calculateThermistorTemperature( THERMISTORS_TEMP_SENSORS_T thermistor, U32 adcValue ); static void publishThermistorsData( void ); /*********************************************************************//** @@ -92,12 +96,21 @@ *************************************************************************/ void initThermistors( void ) { - // Reset the thermistors values for a run - thermistorsExecState = THERMISTORS_EXEC_STATE_START_STATE; - dataPublishCounter = DATA_PUBLISH_COUNTER_START_COUNT; - // Initialize a persistent alarm for thermistors temeprature out of range - initPersistentAlarm( ALARM_ID_DG_THERMISTORS_TEMPERATURE_OUT_OF_RANGE, MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD, MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD ); + // Set voltage reference and ADC bit resolution for each thermistor + thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].voltageReference = THERMISTOR_FPGA_REF_VOLTAGE; + thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].adcBitResolution = TEN_BIT_RESOLUTION; + thermistorsStatus[ THERMISTOR_POWER_SUPPLY_1 ].voltageReference = THERMISTOR_REFERENCE_VOLTAGE; + thermistorsStatus[ THERMISTOR_POWER_SUPPLY_1 ].adcBitResolution = TWELVE_BIT_RESOLUTION; + thermistorsStatus[ THERMISTOR_POWER_SUPPLY_2 ].voltageReference = THERMISTOR_FPGA_REF_VOLTAGE; + thermistorsStatus[ THERMISTOR_POWER_SUPPLY_2 ].adcBitResolution = TEN_BIT_RESOLUTION; + + // Reset the thermistors values for a run + thermistorsExecState = THERMISTORS_EXEC_STATE_START_STATE; + dataPublishCounter = DATA_PUBLISH_COUNTER_START_COUNT; + + // Initialize a persistent alarm for thermistors temeprature out of range + initPersistentAlarm( ALARM_ID_DG_THERMISTORS_TEMPERATURE_OUT_OF_RANGE, MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD, MAX_ALLOWED_TEMP_OUT_OF_RANGE_PERIOD ); } /*********************************************************************//** @@ -229,13 +242,19 @@ #ifndef _RELEASE_ if ( HW_CONFIG_BETA == getHardwareConfigStatus() ) { - thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].rawADCRead = getIntADCReading( INT_ADC_BOARD_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 ); } + else + { + thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].rawADCRead = getFPGAOnBoardThermistorCount(); + thermistorsStatus[ THERMISTOR_POWER_SUPPLY_1 ].rawADCRead = getIntADCReading( INT_ADC_POWER_SUPPLY_1_THERMISTOR ); + thermistorsStatus[ THERMISTOR_POWER_SUPPLY_2 ].rawADCRead = getFPGAPowerSupply2ThermistorCount(); + + } #endif // Get all the raw readings in ADC - thermistorsStatus[ THERMISTOR_ONBOARD_NTC ].rawADCRead = getFPGAOnBoardThermistorCount(); - 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; @@ -296,14 +315,14 @@ { rawADC = (S32)thermistorsStatus[ thermistor ].rawADCRead; - temperature = calculateThemristorTemperature( rawADC ); + temperature = calculateThermistorTemperature( thermistor, rawADC ); thermistorsStatus[ thermistor ].temperatureValue.data = temperature; } } /*********************************************************************//** * @brief - * The calculateThemristorTemperature function converts the ADC value + * The calculateThermistorTemperature function converts the ADC value * of thermistors into temperature in C. Below are the calculation * steps: * voltage = ADC x 3 / 2^12 @@ -315,14 +334,15 @@ * @param ADC value to be converted into temperature in C * @return calculated temperature in C *************************************************************************/ -static F32 calculateThemristorTemperature( U32 adcValue ) +static F32 calculateThermistorTemperature( THERMISTORS_TEMP_SENSORS_T thermistor, U32 adcValue ) { // 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 thermistorVoltage = adcValue * THERMISTOR_VOLTAGE_CONV_COEFF; + thermistorVoltage = adcValue * ( thermistorsStatus[ thermistor ].voltageReference / thermistorsStatus[ thermistor ].adcBitResolution ); // Calculate the thermistor resistor by solving: thermistorVoltage = (3 x 10) / (10 + R(T)) - F32 thermistorResistor = ( ( THERMISTOR_REFERENCE_RESISTOR_AT_25 * THERMISTOR_REFERENCE_VOLTAGE ) - + F32 thermistorResistor = ( ( THERMISTOR_REFERENCE_RESISTOR_AT_25 * thermistorsStatus[ thermistor ].voltageReference ) - ( THERMISTOR_REFERENCE_RESISTOR_AT_25 * thermistorVoltage ) ) / thermistorVoltage; // 1/T = Ln(thermistorResistor/10000)/3380 + 1/298