ADC MC9S08QG8, 10bit or 12bit ??

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ADC MC9S08QG8, 10bit or 12bit ??

965 Views
Brasil
Contributor I
I'm using MC9S08QG8 ADC module with the code:

SOPT1 = 0b01010010; //Pino Reset como I/O. COP desativado, DEBUG habiliado.
SOPT2 = 0b00000000; //I2C nos pinos PTA2 e PTA3.
ICSC2 = 0b00101111;
ICSC1 = 0b00111000;

//Configuração do Conversor AD:
ADCSC2 = 0;
ADCCFG = 0b01010100; //Clock ADC, Modo de consumo.
APCTL1 = 0b00000010; //Pinos usados pelo ADC.

//Função que faz a leitura do canal AD.
//Recebe: Canal do AD para efetuar a leitura.
//Retorna: Valor lido (10bit).
unsigned int ler_ad(unsigned char canal)
{
unsigned char conta = 8;
unsigned int temp =0;

while(conta)
{
ADCSC1 = (0b00000000 | canal); //Pega o canal (5 LSBs).

while(!ADCSC1_COCO); //Aguarda conversão...
temp += ADCR;
conta--;
delay_ms(2);
}


ADCSC1 = 0b00011111; //Desliga o ADC.

return temp >>3 ; //Divide por 8 (que foi o número de conversões).

}

The function 'int ler_ad(unsigned char canal)' it is returning a 12bit value, varying of 0 to the 4095 (varying the tension of pin PTA1 from 0V to VDD).
what it is happening ??! Datasheet says that the AD converter is of 10 bit but it seems that in the practical it works as if was an 12bit ADC!!

I'm using an 4MHz external crystal whith a 8MHz BUSCLK.
Labels (1)
0 Kudos
1 Reply

245 Views
peg
Senior Contributor IV
Hi Brasil,
 
Ths analogue converter is only 10-bit, 0 to 1023.
 
You have set the conversion mode incorrectly, you have selected a reserved setting in MODE in ADCCFG. This could be causing strange behaviour.
 
0 Kudos