adc problem in LPC2148

cancel
Showing results for 
Search instead for 
Did you mean: 

adc problem in LPC2148

Jump to solution
269 Views
Contributor I

Hi,

we are using ADC0 to measure voltage of a sensor which gives output 4 to 40mamp.

But sometimes the ADC conversion is not wokring.it is wiaitng at conversion only.

The code what we are using is 

PINSEL1 |= 0x01000000; // channel 0 in adc0
AD0CR &= 0xffffff00;
AD0CR |= 0x00000002; // Select ADC = AD0.1
// START = 001 = Start Conversion Now
AD0CR |= 0x01000000;

while((AD0DR1 & 0x80000000) == 0); // Wait ADC Conversion to Complete and Read A/D Data Register

val = (unsigned int)(AD0DR1 >> 6) & 0x000003FF;
AD0CR &= 0xF8FFFFFF;
return (val);

Please help us in this issue.

thank you in advance 

Tags (2)
0 Kudos
1 Solution
9 Views
NXP Employee
NXP Employee

Hi,

According with your code, most of the initialization seems to be good. However, it doesn’t show the clock reference, as the ADC clock divisor is set to divide by 1, and, by spec, the ADC clock must be lees or equal to 4.5 MHz; besides, the PDN bit is not set on the code, which means that the ADC will not be operational, so, you should verify that.

Additionally, are you running the code on an infinite loop? Because the general recommendation is setting pins/clocks first and then, just launching the conversion and waiting for the competition on the infinite loop.

As complementary info, you could take a look at the following page:

http://www.ocfreaks.com/lpc2148-adc-programming-tutorial/

Hope this will be useful for you.
Best regards!
/Carlos
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
2 Replies
9 Views
Contributor I

Thank you sir,

We have used fallowing code for intilaising 

AD0CR &= 0x00000000; // Clear All Bit Control
AD0CR |= 0x00000400; // ADC Clock = VPB(PCLK) / 8
AD0CR &= 0xFFFEFFFF; // Busrt = 0 - Conversions are software controlled and reguire 11 clocks
AD0CR &= 0xFFF1FFFF; // CLKS = 000 - 10Bit : 11 Cycle Clock Conversion
AD0CR |= 0x00200000;

We are using 12Mhz Crystal for controller

0 Kudos
10 Views
NXP Employee
NXP Employee

Hi,

According with your code, most of the initialization seems to be good. However, it doesn’t show the clock reference, as the ADC clock divisor is set to divide by 1, and, by spec, the ADC clock must be lees or equal to 4.5 MHz; besides, the PDN bit is not set on the code, which means that the ADC will not be operational, so, you should verify that.

Additionally, are you running the code on an infinite loop? Because the general recommendation is setting pins/clocks first and then, just launching the conversion and waiting for the competition on the infinite loop.

As complementary info, you could take a look at the following page:

http://www.ocfreaks.com/lpc2148-adc-programming-tutorial/

Hope this will be useful for you.
Best regards!
/Carlos
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos