Forums

ADC HCS12 DP256

Started by hellfire1272000 September 10, 2002
I would like some help in putting together some C Code to set-up and
read one ADC Channel continuously and also set-up and Scan through
multiple ADC channels continuously. I have Codewarrior for HCS12.Some
help would be appreciated as I am a newcommer to embedded.



In a message dated 9/10/02 10:00:57 AM Eastern Daylight Time,
writes: > I would like some help in putting together some C Code to set-up and
> read one ADC Channel continuously and also set-up and Scan through
> multiple ADC channels continuously.

Example for icc12 and hc12a4.... hope its similar.......

somewhere in a setup subroutine:
ATDCTL2=0xc0; //atd enab
ATDCTL4=0x07; //sample rate
ATDCTL5=0x70; //continuous scan, multichannel, 8 ch

and later in the program:
//--------------------
void readads(void){
//read 8 ch of internal a/d into addat[]
unsigned char i;
unsigned int tmp;
unsigned char bh,bl;
volatile unsigned char *p;

ATDCTL5=0x70; //init multichannel conv
while((ATDSTAT & 0x80)==0){}; //wait for sequence finished
p=&ADR0H; //point to ch 0
for(i=0; i < 8; i++){
bl=*p++; //lo byte
bh=*p++; //hi byte
tmp=((unsigned int)bh << 8) | bl; //form word
addat[i]=tmp & 0x3ff; //save 10 bit value
}
}

//--------------------
void showads(void){
//show 8 ch of internal a/d
unsigned char i;

printf("\n");
for(i=0; i<8; i++){
printf("%3d ",i);
}
printf("\n");
while(!kbhit()){
readads();
for(i=0; i < 8; i++){
printf("%04x ",addat[i]);
}
printf("\r");
}
printf("\n");
}




Thanks for the help Bob, can you explain to me why line
(ATDCTL5=0x70; //continuous scan, multichannel, 8 ch) has to be put
in the setup section as well as the conversion section?

Please excuse me as I am a hardware engineer who is trying to get to
grips with this even though my "C" code ability is basic.
My company have just bought metrowerks for HCS12, it has been thrown
on my desk and I have been told to get to grips with it!!!! difficult
as the 2000 package only comes with a flashing LED program and a CD
Rom with 5000 pages of PDF files!, none of which actually contains
any useful "C" software routines ( accessing ADC, SPI, CAN,I/O
Frequency/Pulse counting)....help!!

I am trying to write a series of routines that tests the basic
functionality of a custom made Analogue board with ADC, programmable
gain amplifiers, programmable offset all accessed by SPI. --- In 68HC12@y..., BobGardner@a... wrote:
> In a message dated 9/10/02 10:00:57 AM Eastern Daylight Time,
> toby.merridan@s... writes: > > I would like some help in putting together some C Code to set-up
and
> > read one ADC Channel continuously and also set-up and Scan
through
> > multiple ADC channels continuously.
>
> Example for icc12 and hc12a4.... hope its similar.......
>
> somewhere in a setup subroutine:
> ATDCTL2=0xc0; //atd enab
> ATDCTL4=0x07; //sample rate
> ATDCTL5=0x70; //continuous scan, multichannel, 8 ch
>
> and later in the program:
> //--------------------
> void readads(void){
> //read 8 ch of internal a/d into addat[]
> unsigned char i;
> unsigned int tmp;
> unsigned char bh,bl;
> volatile unsigned char *p;
>
> ATDCTL5=0x70; //init multichannel conv
> while((ATDSTAT & 0x80)==0){}; //wait for sequence finished
> p=&ADR0H; //point to ch 0
> for(i=0; i < 8; i++){
> bl=*p++; //lo byte
> bh=*p++; //hi byte
> tmp=((unsigned int)bh << 8) | bl; //form word
> addat[i]=tmp & 0x3ff; //save 10 bit value
> }
> }
>
> //--------------------
> void showads(void){
> //show 8 ch of internal a/d
> unsigned char i;
>
> printf("\n");
> for(i=0; i<8; i++){
> printf("%3d ",i);
> }
> printf("\n");
> while(!kbhit()){
> readads();
> for(i=0; i < 8; i++){
> printf("%04x ",addat[i]);
> }
> printf("\r");
> }
> printf("\n");
> }





In a message dated 9/12/02 4:20:45 AM Eastern Daylight Time,
writes: > Bob, can you explain to me why line
> (ATDCTL5=0x70; //continuous scan, multichannel, 8 ch) has to be put
> in the setup section as well as the conversion section?
>

That's proabably redundant. Very observant. Original idea was to have all 8
channels continuously convert.... had some prob with that, so I fell back to
the version where I initiate conversion.... good luck with metroworks... this
list is full of guys looking for docs and tutorials on metroworks... a few of
them have conquereed it... I think they are renting themselves out as
consultants now... I like the imagecraft compiler... its inexpensive and the
guy that wrote it will actually answer your questions if you have any...


Have a look as well on
http://e-www.motorola.com/index.html

there are a lot of application notes with code around ADS/SPI/etc as well.

Erich

> -----Original Message-----
> From: hellfire1272000 [mailto:]
> Sent: Thursday, September 12, 2002 10:19 AM
> To:
> Subject: [68HC12] Re: ADC HCS12 DP256 > Thanks for the help Bob, can you explain to me why line
> (ATDCTL5=0x70; //continuous scan, multichannel, 8 ch) has to be put
> in the setup section as well as the conversion section?
>
> Please excuse me as I am a hardware engineer who is trying to get to
> grips with this even though my "C" code ability is basic.
> My company have just bought metrowerks for HCS12, it has been thrown
> on my desk and I have been told to get to grips with it!!!! difficult
> as the 2000 package only comes with a flashing LED program and a CD
> Rom with 5000 pages of PDF files!, none of which actually contains
> any useful "C" software routines ( accessing ADC, SPI, CAN,I/O
> Frequency/Pulse counting)....help!!
>
> I am trying to write a series of routines that tests the basic
> functionality of a custom made Analogue board with ADC, programmable
> gain amplifiers, programmable offset all accessed by SPI. > --- In 68HC12@y..., BobGardner@a... wrote:
> > In a message dated 9/10/02 10:00:57 AM Eastern Daylight Time,
> > toby.merridan@s... writes:
> >
> >
> > > I would like some help in putting together some C Code to set-up
> and
> > > read one ADC Channel continuously and also set-up and Scan
> through
> > > multiple ADC channels continuously.
> >
> > Example for icc12 and hc12a4.... hope its similar.......
> >
> > somewhere in a setup subroutine:
> > ATDCTL2=0xc0; //atd enab
> > ATDCTL4=0x07; //sample rate
> > ATDCTL5=0x70; //continuous scan, multichannel, 8 ch
> >
> > and later in the program:
> > //--------------------
> > void readads(void){
> > //read 8 ch of internal a/d into addat[]
> > unsigned char i;
> > unsigned int tmp;
> > unsigned char bh,bl;
> > volatile unsigned char *p;
> >
> > ATDCTL5=0x70; //init multichannel conv
> > while((ATDSTAT & 0x80)==0){}; //wait for sequence finished
> > p=&ADR0H; //point to ch 0
> > for(i=0; i < 8; i++){
> > bl=*p++; //lo byte
> > bh=*p++; //hi byte
> > tmp=((unsigned int)bh << 8) | bl; //form word
> > addat[i]=tmp & 0x3ff; //save 10 bit value
> > }
> > }
> >
> > //--------------------
> > void showads(void){
> > //show 8 ch of internal a/d
> > unsigned char i;
> >
> > printf("\n");
> > for(i=0; i<8; i++){
> > printf("%3d ",i);
> > }
> > printf("\n");
> > while(!kbhit()){
> > readads();
> > for(i=0; i < 8; i++){
> > printf("%04x ",addat[i]);
> > }
> > printf("\r");
> > }
> > printf("\n");
> > }
> >
> >
> >
> >
> >
> -------------------- >
> ">http://docs.yahoo.com/info/terms/