This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Decimal Conversion

Hi, I have just managed to successfully read ADC values and send as a service but they are in uint8 format. Is there an easy way to convert this to decimal within my adc handler? Thank you for any response.

Parents
  • There is no way to know what the ADC measurement really means, so there is no way to convert it into "decimal".

    All the ADC measurement is telling you is the voltage as measured at the pin, according to the control parameters.

    So for example if you are using a 1200 mV reference, and a 2/3 prescaler then the pin voltage is

    pin voltage = (1200 * 3/2 * ADC_VAL/256)

    The pin itself might the be fed through a voltage divider or there might be other losses (eg diode drop) that must be compensated for.

    Be careful if you do this in an interrupt service routine because doing division can be slow (if you are not careful).

Reply
  • There is no way to know what the ADC measurement really means, so there is no way to convert it into "decimal".

    All the ADC measurement is telling you is the voltage as measured at the pin, according to the control parameters.

    So for example if you are using a 1200 mV reference, and a 2/3 prescaler then the pin voltage is

    pin voltage = (1200 * 3/2 * ADC_VAL/256)

    The pin itself might the be fed through a voltage divider or there might be other losses (eg diode drop) that must be compensated for.

    Be careful if you do this in an interrupt service routine because doing division can be slow (if you are not careful).

Children
No Data
Related