Electronic – Get temperature via ADC of microcontroller

adcmicrocontroller

I want to manipulate the physical value of temperature. Here is the characteristic of this µC:

Resolution: 12 bits
Supply: 5 V
Min Mesure: -45
Max Mesure: 75
Min ADC IN: 0.4
Max ADC IN: 4.8

Here is the formula which i used:

 Value = (Digital value * Max ADC IN) / 4095.0;

I used the rule of three.

Max ADC IN (4.8) ===> 4095 (depends on the resolution (12 bits)) 
Value            ===> Digital value from ADC

If I use this formula, it is sufficient to read the physical value?

I don't have the datasheet of the sensor, the microcontroller is 68HCs12.

Best Answer

I think your formula is ok. As mentioned by Sanjeev, do not forget to get the approximate number of samples you need to get the accuracy you need.

Here is an example of an ADC_get_value routine that I used time ago. It uses a similar formula:

/* Function name    :   unsigned char ConvertAdcvalueToFuelLevel( unsigned int x )
* Crated by     :   
* Description   :   This function converts from ADC values to its equivalent voltage and then returns a number
*                   between 0 - 255 representing voltages between 0 - 5000mV.
*                   The receiver must multiply the returned value by 19.6078 in order to get the equivalent
*                   voltage.
*                   The transfer function for the hardware used on the ADC input is:
*                   f(x)= 0.999*x       x:volts
******************************************************************************************************************/
unsigned char ConvertAdcvalueToFuelLevel( unsigned int x )
{
    unsigned int Voltage;
    unsigned int Offset = 5;        //15mV

    //Converts from ADC bits to voltage
    Voltage = ((unsigned long int)((unsigned long int)x * 4990))/4095;  //(x*Vref)/4095 (Millivolts)

    //The hardware used on the analog input is almost lineal between 0V and 4.2V.
    Voltage = (unsigned int)(0.999*Voltage) + Offset;
    return (unsigned char)(Voltage / 19.6078);
}