Hi,
I'm having some troubles with ATD module of the MC9S12E128. I'm using the high chanel and the CH7 as digital IOs and the other pins as analogic inputs. I don't know why, the AN4, AN5 and AN6 operation, doesn't sets the ATDSTAT1 with their corresponding CCFx Flags.
I'm sending a piece of code to show the ATD initialization and using..
----------------------------------------------------------------------
void AdcConfig(void){
ATDDIEN0 = 0xFF; // Enable digital ports to PTADHi.
ATDDIEN1 = 0x80; // Enable digital ports to PTADLo bit7 and analog to others.
ATDCTL2 = 0xC0; // Normal ATD functionality and enable Fast Clear Flag
ATDCTL4 = 0x21; // ATD Clock prescaler = Divide by 4 due the max/min clock freq
ATDTEST1 = 0x00; // No Special conversion chanel
}
int Adc6(void){
ATDCTL5 = 0x86; // Right justified data in the result registers - turn on ch6
while (!(ATDSTAT1 & CCF6)); //Wait
return ATDDR6;
}
int Adc5(void){
ATDCTL5 = 0x85; // Right justified data in the result registers - turn on ch5
while (!(ATDSTAT1 & CCF5)); //Wait
return ATDDR5;
}
int Adc4(void){
ATDCTL5 = 0x84; // Right justified data in the result registers - turn on ch4
while (!(ATDSTAT1 & CCF4));
return ATDDR4;
}
int Adc3(void){
ATDCTL5 = 0x83; // Right justified data in the result registers - turn on ch3
while (!(ATDSTAT1 & CCF3)); //Wait
return ATDDR3;
}
..... until CH0
The chanels below CH4, works fine and the digital pins too. I don't know what's happening,
Please, If you could help me..
Thank you.