MC9S12XDT512 A2D Converter

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MC9S12XDT512 A2D Converter

3,299 次查看
gmorton3
Contributor I
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!
标签 (1)
0 项奖励
回复
5 回复数

1,072 次查看
JimDon
Senior Contributor III
// 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;

}

Message Edited by JimDon on 2007-02-0206:03 PM

Message Edited by JimDon on 2007-02-0206:04 PM

0 项奖励
回复

1,072 次查看
JimDon
Senior Contributor III
Sorry -
SINGLE_MODE NO_SCAN_MODE are both 0
#define SCF 0x80 //Sequence Complete Flag in ATD0STAT0
0 项奖励
回复

1,072 次查看
gmorton3
Contributor I
Thanks, I cant try it till monday but i'll give it a go then and i'll let you know the result. 
0 项奖励
回复

1,072 次查看
gmorton3
Contributor I
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.
0 项奖励
回复

1,072 次查看
gmorton3
Contributor I
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. 
0 项奖励
回复