MC9S12XDT512 A2D Converter
‎01-31-2007
06:52 PM
3,370 Views

gmorton3
Contributor I
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi im using the following initiaization for a single channel conversion 8 bit conversion on AN0. I have a 0-5v reference voltage and an input that lies between this range.
im using:
void A2Dsetup (void){
ATD0CTL2_ADPU = 1;
ATD0CTL2_AFFC = 1;
ATD0CTL2_ASCIE = 1;
ATD0CTL3_FIFO = 0;
ATD0CTL4_SRES8 = 1;
ATD0CTL4_SMP1 = 1;
ATD0CTL4_SMP0 = 0;
ATD0CTL4_PRS4 = 0;
ATD0CTL4_PRS3 = 0;
ATD0CTL4_PRS2 = 0;
ATD0CTL4_PRS1 = 1;
ATD0CTL4_PRS0 = 1;
}
Im also using
int res;
int getTemperatures(void){
ATD0CTL5 = 0x00;
while (ATD0CTL2_ASCIF == 0);
res = (int) ATD0DR1H;
return res;
}
Using The debugger in CodeWarrior i have noticed that the program runs till the "while (ATD0CTL2_ASCIF == 0)" It never moves beyond this point.
Any ideas what im doing wrong or ideas for how i can get it to work?
Thanks to anyone who has any ideas!
im using:
void A2Dsetup (void){
ATD0CTL2_ADPU = 1;
ATD0CTL2_AFFC = 1;
ATD0CTL2_ASCIE = 1;
ATD0CTL3_FIFO = 0;
ATD0CTL4_SRES8 = 1;
ATD0CTL4_SMP1 = 1;
ATD0CTL4_SMP0 = 0;
ATD0CTL4_PRS4 = 0;
ATD0CTL4_PRS3 = 0;
ATD0CTL4_PRS2 = 0;
ATD0CTL4_PRS1 = 1;
ATD0CTL4_PRS0 = 1;
}
Im also using
int res;
int getTemperatures(void){
ATD0CTL5 = 0x00;
while (ATD0CTL2_ASCIF == 0);
res = (int) ATD0DR1H;
return res;
}
Using The debugger in CodeWarrior i have noticed that the program runs till the "while (ATD0CTL2_ASCIF == 0)" It never moves beyond this point.
Any ideas what im doing wrong or ideas for how i can get it to work?
Thanks to anyone who has any ideas!
5 Replies
‎02-03-2007
12:00 AM
1,143 Views

JimDon
Senior Contributor III
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
// ATD block set up.
ATD0CTL2 = 0x80; // Enable power up mode for ADC Block
ATD0CTL3 = 0x40; // Set 8 bit conversions.
//===============================================================================
// Trigger, wait, then read a channel and return 8-bit value..
//===============================================================================
byte ReadADC(byte channel)
{
byte status;
// This resets the conversion done flag and starts a new conversion.
ATD0CTL5 = SINGLE_MODE+NO_SCAN_MODE+channel;
for ( ; ; )
{
status = ATD0STAT0;
if( status & SCF )
break;
}
status = ATD0DR7H; // Just the hi byte. Ignore LSB's
ADTValue = status;
return status;
}
ATD0CTL2 = 0x80; // Enable power up mode for ADC Block
ATD0CTL3 = 0x40; // Set 8 bit conversions.
//===============================================================================
// Trigger, wait, then read a channel and return 8-bit value..
//===============================================================================
byte ReadADC(byte channel)
{
byte status;
// This resets the conversion done flag and starts a new conversion.
ATD0CTL5 = SINGLE_MODE+NO_SCAN_MODE+channel;
for ( ; ; )
{
status = ATD0STAT0;
if( status & SCF )
break;
}
status = ATD0DR7H; // Just the hi byte. Ignore LSB's
ADTValue = status;
return status;
}
Message Edited by JimDon on 2007-02-0206:03 PM
Message Edited by JimDon on 2007-02-0206:04 PM
‎02-03-2007
12:52 AM
1,143 Views

JimDon
Senior Contributor III
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry -
SINGLE_MODE NO_SCAN_MODE are both 0
#define SCF 0x80 //Sequence Complete Flag in ATD0STAT0
SINGLE_MODE NO_SCAN_MODE are both 0
#define SCF 0x80 //Sequence Complete Flag in ATD0STAT0
‎02-03-2007
04:18 AM
1,143 Views

gmorton3
Contributor I
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, I cant try it till monday but i'll give it a go then and i'll let you know the result.
‎02-05-2007
03:17 PM
1,143 Views

gmorton3
Contributor I
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok a quick update. Got the A2D working and converting as expected. Didnt really make too many changes to the set-up already being used but changed the while loop to look at ATD0STAT0_SCF and that seems to be more successfull. Thanks for the suggestions JimDon.
‎02-01-2007
11:34 AM
1,143 Views

gmorton3
Contributor I
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry i should have made this clearer. I only used the debugger to see where the program trips up. It doesnt work when run in hardware. I used an LED switching both sides of the while loop to try and highlight where the code fails and sure enough the led is on before the while loop and never turns off after it. This indicates that the while loop is where im getting tripped up.
