LPC2136 ADC Problems

Started by Mauro Luiz December 10, 2013
Hi guys,
I'm trying to use a AD converter input on LPC2136 and I'm having
some problems.
I revised the ADC registers configuration many times and can't find
the problem. The AD conversion just start on the right channel, with
the righ frequency but ever returns zero.
I'm using the folow code on IAR Embedded Workbench 6.5

//init AD1.6 (PIN 1, P0.21)
void initAd_16(void)
{
AD1CR = (0<<21); //put ADC off
PCONP |= (1<<20); //power up AD1
PINSEL1 |= 0x800; //select the P0.21 as ADC input
AD1CR = (1<<21); //put ADC on
}

//read AD1.6 and return the AD value
unsigned int leAD_16(void)
{
unsigned int k;

AD1CR = 0x200940; //sets channel 6 on AD1 @2MHz (PCLK MHz)
AD1CR |= (1<<24); //start AD conversion
do {
k = AD1GDR;
} while (!(k & 0x80000000)); //wait until AD conversion is finished
k = k >> 6; //shift the AD result 6 right
k = (k & 0x3FF); //10bits mask
return(k); //retunr AD value
}

Has anyone had a similar problem and can help me?
--
Atenciosamente, Mauro L. Lenz "Ajude a combater o Spam. Ao encaminhar uma mensagem, apague o e-mail do remetente e utilize o campo CCo quando enviar para mais de um destinatio."

An Engineer's Guide to the LPC2100 Series

> PINSEL1 |= 0x800; //select the P0.21 as ADC input

Looking at LPC2k documentation and assuming reset values, this selects
P0[21] as RD3 (CAN).

Also, it looks like P0[21] does not support analog input to the ADC.

So, you have multiple problems here, I think.

--

Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk


SolderCore Development Platform http://www.soldercore.com

From: l... [mailto:l...] On Behalf Of
Mauro Luiz
Sent: 11 December 2013 01:57
To: l...
Subject: [lpc2000] LPC2136 ADC Problems

Hi guys,
I'm trying to use a AD converter input on LPC2136 and I'm having some
problems.
I revised the ADC registers configuration many times and can't find the
problem. The AD conversion just start on the right channel, with the righ
frequency but ever returns zero.
I'm using the folow code on IAR Embedded Workbench 6.5

//init AD1.6 (PIN 1, P0.21)
void initAd_16(void)
{
AD1CR = (0<<21); //put ADC off
PCONP |= (1<<20); //power up AD1
PINSEL1 |= 0x800; //select the P0.21 as ADC input
AD1CR = (1<<21); //put ADC on
}

//read AD1.6 and return the AD value
unsigned int leAD_16(void)
{
unsigned int k;

AD1CR = 0x200940; //sets channel 6 on AD1 @2MHz
(PCLK MHz)
AD1CR |= (1<<24); //start AD conversion
do {
k = AD1GDR;
} while (!(k & 0x80000000)); //wait until AD conversion is
finished
k = k >> 6; //shift the AD result
6 right
k = (k & 0x3FF); //10bits mask
return(k); //retunr AD value
}

Has anyone had a similar problem and can help me?

--
Atenciosamente,

Mauro L. Lenz

"Ajude a combater o Spam. Ao encaminhar uma mensagem, apague o e-mail do
remetente e utilize o campo CCo quando enviar para mais de um destinatio."
(0<<21) means "shift '0' 21 times to the left" and the result is 0.

If you want to clear just the bit 21 use ad1cr use ad1cr &= ~(1<<21).

-- Paulo Ricardo Pabst
E-mail enviado do Android.
E-mail sent from Android.
Mauro Luiz escreveu:
>��Hi guys,
>I'm trying to use a AD converter input on LPC2136 and I'm having
> some problems.
>I revised the ADC registers configuration many times and can't find
> the problem. The AD conversion just start on the right channel, with
> the righ frequency but ever returns zero.
>I'm using the folow code on IAR Embedded Workbench 6.5
>
>//init AD1.6 (PIN 1, P0.21)
>void initAd_16(void)
>{
>�� AD1CR = (0<<21);������������������������������ //put ADC off
>�� PCONP |= (1<<20);���������������������������� //power up AD1
>�� PINSEL1 |= 0x800;���������������������������� //select the P0.21 as ADC input
>�� AD1CR = (1<<21);������ ������ ������ ������ //put ADC on
>}
>
>//read AD1.6 and return the AD value
>unsigned int leAD_16(void)
>{
>�� unsigned int k;
>��
>�� AD1CR = 0x200940;���������������������������������������� ������ //sets channel 6 on AD1
>@2MHz (PCLK MHz)
>�� AD1CR |= (1<<24);�������������������������������������� �� ������ //start AD conversion
>�� do {
>������ k = AD1GDR;
>�� } while (!(k & 0x80000000));������������������ //wait until AD conversion is
>finished
>�� k = k >> 6;������ ������ ������ ������ ������ ������ ������ ������ ������ ������ �� //shift the AD
>result 6 right
>�� k = (k & 0x3FF);������������������������������������������ ������ �������� //10bits mask
>�� return(k);������ ������ ������ ������ ������ ������ ������ ������ ������ ���������� //retunr AD value
>}
>
>Has anyone had a similar problem and can help me?
>--
>Atenciosamente, Mauro L. Lenz "Ajude a combater o Spam. Ao encaminhar
>uma mensagem, apague o e-mail do remetente e utilize o campo CCo quando
>enviar para mais de um destinat��rio."
Hi all,

Paul, I didn't think so. Take a look at the LPC2131/2/4/6/8 User manual
( http://www.nxp.com/documents/user_manual/UM10120.pdf ). On chapter 6
(pin connector block) you can see that P0.21 support ADC chanel AD1.6 on
LPC2136 devices.

Paulo Ricardo, thanks for the advice. I alredy fix it but it still not
working correctly.

Atenciosamente,

Mauro L. Lenz
Fone: (55) 8115-6944
Skype: mauro_eafs

"Ajude a combater o Spam. Ao encaminhar uma mensagem, apague o e-mail do remetente e utilize o campo CCo quando enviar para mais de um destinatio."

Em 11/12/2013 07:02, Paul Curtis escreveu:
>
> >PINSEL1 |= 0x800; //select the P0.21 as ADC input
>
> Looking at LPC2k documentation and assuming reset values, this selects
> P0[21] as RD3 (CAN).
>
> Also, it looks like P0[21] does not support analog input to the ADC.
>
> So, you have multiple problems here, I think.
>
> --
>
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> SolderCore Development Platform http://www.soldercore.com
>
> *From:*l... [mailto:l...] *On
> Behalf Of *Mauro Luiz
> *Sent:* 11 December 2013 01:57
> *To:* l...
> *Subject:* [lpc2000] LPC2136 ADC Problems
> Hi guys,
> I'm trying to use a AD converter input on LPC2136 and I'm having some
> problems.
> I revised the ADC registers configuration many times and can't find
> the problem. The AD conversion just start on the right channel, with
> the righ frequency but ever returns zero.
> I'm using the folow code on IAR Embedded Workbench 6.5
>
> //init AD1.6 (PIN 1, P0.21)
> /void initAd_16(void)
> {
> AD1CR = (0<<21); //put ADC off
> PCONP |= (1<<20); //power up AD1
> PINSEL1 |= 0x800; //select the P0.21 as ADC input
> AD1CR = (1<<21); //put ADC on
> }/
> /
> //read AD1.6 and return the AD value/
> /unsigned int leAD_16(void)
> {
> unsigned int k;
>
> AD1CR = 0x200940; //sets channel 6 on AD1 @2MHz (PCLK MHz)
> AD1CR |= (1<<24); //start AD conversion
> do {
> k = AD1GDR;
> } while (!(k & 0x80000000)); //wait until AD conversion is
> finished
> k = k >> 6; //shift the AD result 6 right
> k = (k & 0x3FF); //10bits mask
> return(k); //retunr AD value
> }/
>
> Has anyone had a similar problem and can help me?
> --
> Atenciosamente,
>
> Mauro L. Lenz
>
> "Ajude a combater o Spam. Ao encaminhar uma mensagem, apague o e-mail do remetente e utilize o campo CCo quando enviar para mais de um destinatio."
>