ADC in atmga8
Discussion in "AVR Discussion Forum" started by vijay Mar 14, 2013.
Thu Mar 14 2013, 06:44 pm
How to convert hexadecimal to decimal???
i m using this equation ((((ADCH*256)+ADCL)*5)/1024) to get decimal value...but not giving...Is there any other equation?
i m using this equation ((((ADCH*256)+ADCL)*5)/1024) to get decimal value...but not giving...Is there any other equation?
Sat Mar 16 2013, 01:43 am
How to convert hexadecimal to decimal???
i m using this equation ((((ADCH*256)+ADCL)*5)/1024) to get decimal value...but not giving...Is there any other equation?vijay.parmar1992
There may be some confusion here.
The value in ADCH and ADCL is a binary representation of a number.
(ADCH*256)+ADCL will give the right value , assuming the result has not been shifted
by the ADC.
Left or right shifting of results is an option on PICs, I don't know about AVR.
Sat Mar 16 2013, 05:26 pm
hex or decimal is just a representation. It doesnt make any sense to a variable. for example,
a = 0x10 is same as a = 16
for variable a it does not matter you are writing in hex/decimal. If you are displaying it on lcd/sending on uart etc, only then it becomes significant thing.
But if you are talking about BCD (binary coded decimal) that becomes different. for example
a = 0x10 becomes a = 0x16 in BCD
So these conversions depends on the use case of your program. Hope you get my idea now.
a = 0x10 is same as a = 16
for variable a it does not matter you are writing in hex/decimal. If you are displaying it on lcd/sending on uart etc, only then it becomes significant thing.
But if you are talking about BCD (binary coded decimal) that becomes different. for example
a = 0x10 becomes a = 0x16 in BCD
So these conversions depends on the use case of your program. Hope you get my idea now.
Powered by e107 Forum System