12 years, 8 months ago.

Problem with Input multiplexing in LPC2124

Hello: I have a problem with my lpc2124. I did make test with the channel 0 (AIN0) pin 11, its ok. But with the others 3 inputs... I am not sure

int config_ADC(void)

{

unsigned int configura;

unsigned char canal;

canal = 11; AIN0 and AIN1 pin 11 y pin 13 configura = (16 << 8); /* CLKDIV = 16 */

configura |= (1 << 21); /* PDN = 1 ADC operational*/

configura |= canal;

configura |= (1 << 16); BURST = 1 , hardware scan mode, 2 ch

configura |= (101 << 17); CLKS = 101 6 clocks / 5 bits

AD_ADCR = configura;

return 0; }

int Impr_Corriente(unsigned int); int LEER_Ain0(void)

{

unsigned int salida, corriente; int i;

AD_ADCR |= (0 << 24); /* START = 000 becouse BURST = 1 */ for (i = 0; i <0X60000; i++)

AD_ADCR |= (0 << 16); BURST clearing , for conversions can be terminated do {

salida = AD_ADDR; Escribir_1('e');

} while((salida & (1 << 31)) & (salida |= (1 << 24)) == 0); CHN = 0 chl from which the last convertion corriente = (salida >> 6) & 0x3FF; /* RESULT bit 6 a 15*/ Impr_Corriente(corriente);

return 0;

}

The convert is not good, always read from AIN 0 Please Help me

1 Answer

12 years, 8 months ago.

I did it!! just had to call the function again (with the configuration included) and change the SEL bit (first 1 and second with 10)

int Impr_Corriente(unsigned int); int LEER_Ain0(void)

{

unsigned int configura,corriente;

unsigned char canal;

canal = 1;ENTRADA ANALOGICA AIN0

configura = (16 << 8); /* CLKDIV = 16 configuro divisor externo */

configura |= (1 << 21); /* PDN = 1 ADC en modo operacional*/

configura |= canal;

AD_ADCR = configura;

AD_ADCR |= (1 << 24); /* START = 001 porque BURST = 1 */ do { corriente = AD_ADDR; } while (( corriente & (1<<31) ) == 0);

corriente = (corriente >> 6) & 0x3FF; /* tomar el resultado del bit 6 a 15*/ Impr_Corriente(corriente); return 0;

} int Impr_Tension(unsigned int );

int LEER_Ain1(void)

{

unsigned int configura,tension; unsigned char canal; canal = 10;ENTRADA ANALOGICA AIN1

configura = (16 << 8); /* CLKDIV = 16 configuro divisor externo */

configura |= (1 << 21); /* PDN = 1 ADC en modo operacional*/

configura |= canal;

AD_ADCR = configura; AD_ADCR |= (1 << 24); do { tension = AD_ADDR; } while (( tension & (1<<31) ) == 0); tension = (tension >> 6) & 0x3FF; /* tomar el resultado del bit 6 a 15*/ Impr_Tension(tension);

return 0;

}