EmbeddedRelated.com
Forums

Reading ADR register in Motorola HC08 processor

Started by Aria August 10, 2005
Hi,

I am new to programming MCUs and am trying to program my MC68HC098QY4
using CodeWarrior.

In my program I am incorporating the analog-digital convertor and I
have a question regarding the nature of its output in the ADR register.

Currently what I am doing is assigning the value of the ADR to an
integer as such:

int adrval;
adrval = ADR;

from the datasheets, I see that if the input to the ADC (analog digital
convertor) is equal to Vss of the MCU, then the output is $00 and if
it's equal to Vdd then the output is $FF so using my integer approach,
does that mean that the output will be a linear distribution between 0
and 255 (decimal equivalent of hex FF) with no offsets?


I was browsing through the Freescale documentations and found one for
program the ADC at
(http://www.freescale.com/files/microcontrollers/doc/app_note/AN2984.pdf).
Now in this document, on page 5, it puts the result of the ADR into a
char variable as such:

unsigned char result;
result = ADR;

so is the result now put into a character array with 8 elements (0 to
7)? If so, do I now have to manually convert the 8 elements (each being
either 0 or 1) to an integer?


I am a little confused between which approach to take. Can you please
clarify my questions.

Thanks in advance,
Aria Kashefi

Aria wrote:
> Hi, > > I am new to programming MCUs and am trying to program my MC68HC098QY4 > using CodeWarrior. > > In my program I am incorporating the analog-digital convertor and I > have a question regarding the nature of its output in the ADR register. > > Currently what I am doing is assigning the value of the ADR to an > integer as such: > > int adrval; > adrval = ADR; > > from the datasheets, I see that if the input to the ADC (analog digital > convertor) is equal to Vss of the MCU, then the output is $00 and if > it's equal to Vdd then the output is $FF so using my integer approach, > does that mean that the output will be a linear distribution between 0 > and 255 (decimal equivalent of hex FF) with no offsets? > > > I was browsing through the Freescale documentations and found one for > program the ADC at > (http://www.freescale.com/files/microcontrollers/doc/app_note/AN2984.pdf). > Now in this document, on page 5, it puts the result of the ADR into a > char variable as such: > > unsigned char result; > result = ADR; > > so is the result now put into a character array with 8 elements (0 to > 7)? If so, do I now have to manually convert the 8 elements (each being > either 0 or 1) to an integer? > > > I am a little confused between which approach to take. Can you please > clarify my questions.
A char is nothing more than an *integer* expressed on 8 bits so the range is 0 .. 255 or 0 .. FF in hexadecimal. Since the output of the ADC is 0 .. FF it can fit in a char. You can do arithmetic with a char in the same way as with an integer. It is unsigned since the value is always positive.
Lanarcam wrote:
> Aria wrote: >> >> I am new to programming MCUs and am trying to program my >> MC68HC098QY4 using CodeWarrior. >> >> In my program I am incorporating the analog-digital convertor and >> I have a question regarding the nature of its output in the ADR >> register. >>
... snip ...
>> >> so is the result now put into a character array with 8 elements >> (0 to 7)? If so, do I now have to manually convert the 8 elements >> (each being either 0 or 1) to an integer? >> >> I am a little confused between which approach to take. Can you >> please clarify my questions. > > A char is nothing more than an *integer* expressed on 8 bits > so the range is 0 .. 255 or 0 .. FF in hexadecimal. > > Since the output of the ADC is 0 .. FF it can fit in a char. You > can do arithmetic with a char in the same way as with an integer. > It is unsigned since the value is always positive.
Whether a char is signed or unsigned depends on the implementation. Since it can be either, you must specifically cast (or define) the incoming data as being unsigned char if that is what you want. -- Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net) Available for consulting/temporary embedded and systems. <http://cbfalconer.home.att.net> USE worldnet address!