lpc1769 ADC help

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

lpc1769 ADC help

1,751 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by qwerty on Wed Jun 12 10:55:18 MST 2013
Hi, I am using the code from an online source to get the ADC values from the lpc1769, but I want to use P0.25 (AD0.2), instead of P0.23 (AD0.0) which he used. However, I can't get it to work.

Here's the blog and original codes:
http://willhb.com/?p=114
https://github.com/willhb/lpc/blob/master/fft_adc.lpc17xx/main.c

Here's the code, with lines I changed noted:

LPC_SC->PCONP |= (1<<12);                 //Turn on ADC power and clock
LPC_SC->PCLKSEL0 |= (1<<24)|(1<<25);    //Scale the ADC clock by 8 (96/8 = 12MHz)

LPC_PINCON->PINSEL1 |= (1<<18);         //P0.25 is connected to AD0.2 (changed code)
LPC_PINCON->PINMODE1 |= (1<<19);         //No pullups/downs (changed code)
LPC_ADC->ADCR = (1<<21)|(0<<8);         //Turn on ADC

uint16_t valueFromPot;

LPC_ADC->ADCR |= (1<<24);                        //start a conversion
while((LPC_ADC->ADDR2 >> 31) && 1){}            //wait for conversion (changed code)
valueFromPot = (LPC_ADC->ADDR2>>4) & 0xFFF;        //real input is ADC conversion (changed code)
Thanks so much if anyone can offer help
0 Kudos
Reply
3 Replies

1,716 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed Jun 12 14:16:04 MST 2013

Quote: qwerty
But it is still not working.



What is not working? No conversion, no result, no risk, no fun?

while((LPC_ADC->ADDR2 >> 31) && 1){}            //wait for conversion (changed code)


That's a wait for no conversion loop. 8 lines of code and 2 errors :confused:

I don't know which drunken kid has been written this code, but it's a useful code to improve your troubleshooting skills.

I would prefer a working code like #2 of http://knowledgebase.nxp.com/showthread.php?p=28960
0 Kudos
Reply

1,716 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by qwerty on Wed Jun 12 14:00:00 MST 2013
thanks so much for pointing that out ..

I changed the code to set SEL bit
LPC_ADC->ADCR &= 0xFFFFFFFE;                // Clear bit 0
LPC_ADC->ADCR = (1<<21)|(0<<8)|(1<<2);         //Turn on ADC, set bit 2
But it is still not working. Previously I can get AD0.0 to give me values, but with my changes it just does not give me any output.

Thanks.
0 Kudos
Reply

1,716 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed Jun 12 11:50:56 MST 2013

Quote: qwerty
However, I can't get it to work.


:confused:

So what's not working? No conversion, no result, no risk, no fun?

Looks like a good idea to read UM10360 ADC chapter.

Especially:

Quote:

Table 531: A/D Control Register (AD0CR - address 0x4003 4000) bit description

7:0 SEL [COLOR=Red]Selects which of the AD0.7:0 pins is (are) to be sampled and converted.[/COLOR] For AD0, bit 0 selects Pin AD0.0, and bit 7 selects pin AD0.7. In software-controlled mode, only one of these bits should be 1. In hardware scan mode, any value containing 1 to 8 ones is allowed. All zeroes is equivalent to 0x01.

0 Kudos
Reply