EmbDev.net

Forum: ARM programming with GCC/GNU tools LPC2138 ADC example


Author: Thomas Fernando (thomas_f)
Posted on:

Rate this post
0 useful
not useful
Hello ,

Just a quick clarification needed :
I was checking the ADC example for LPC2148 in the examples. However it
says that the example was checked with LPC2138 Keil board.
Are both LPC2148 and LPC2138 ADC modules the same ?

Thomas

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 useful
not useful
Thomas Fernando wrote:
> Hello ,
>
> Just a quick clarification needed :
> I was checking the ADC example for LPC2148 in the examples. However it
> says that the example was checked with LPC2138 Keil board.
> Are both LPC2148 and LPC2138 ADC modules the same ?
>
> Thomas

Compare the ADCs in the respective user manuals:

http://www.nxp.com/#/pip/pip=[pip=LPC2131_32_34_36...]
http://www.nxp.com/#/pip/pip=[pip=LPC2141_42_44_46...]

They are different. The 48 is far more capable than the 38, having a
data register for each channel, however a cursory look suggests that the
design of the 48 is compatible with the 38 and so 38 ADC code would work
with the 48 (but not necessarily the other way around). But do read the
manual to determine that that is correct, I have not looked in detail.

The ADC is not that complicated, and I would always advocate building
your own drivers from the user manual information rather than relying on
someone else's code. That would limit your choice of microcontroller to
only those that you could find code existing for.

Note also that the "all documentation" downloads include application
notes which may provide useful code examples.


Clifford

Author: Thomas Fernando (thomas_f)
Posted on:

Rate this post
0 useful
not useful
Well I have tried some stuff and got a bit stuck.

I am trying this :
       uint32_t Init_Read_ADC(void)
       {
    uint32_t ADC_Val;

      //  Set up (PIN0.28) as AD1
    PINSEL1 = 0x01000000;
    AD0CR   &= 0x00200602;   // see comment plate
    AD0GDR;                  // dummy read to clear DONE bit
          AD0CR |= (1<<24);        // start conversion

  do
  {
    ADC_Val = AD0GDR;  //Read A/D data register0
  }
  while ((ADC_Val & 0x80000000) == 0); //Wait for end of A/D

  AD0CR &= ~0x01000000;   //Stop A/D conversion
  ADC_Val = ((ADC_Val >>6) & 0x000003FF); // extract result
  return(ADC_Val);

}
The problem I face is that the ADC gets stuck infinitely in the
do-while,loop. Just to check , I printed the value of AD0GDR , which
gives me a value :0x01000000,indicating that the right channel is being
read.

PCLK = 27.6475MHz (config.h)
Hence ADCLK = (27.6475 / 7 ) = 3.95 MHz

Any ideas on what I could try out ?

Thomas

Author: Thomas Fernando (thomas_f)
Posted on:

Rate this post
0 useful
not useful
Just to check , I printed the value of AD0GDR , which
 gives me a value :0x01000000,indicating that the right channel is being
 read.
> Thomas

Ooops !!! It gives the same value , irrespective of channel selected.

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 useful
not useful
>     AD0CR   &= 0x00200602;   // see comment plate
Did you intend to use &= here? The reset value for AD0CR is 0x00000001,
so you may have simply set AD0CR to zero and disabled the ADC.

I suggest:

AD0CR = 0x00200602;



>     AD0GDR;                  // dummy read to clear DONE bit

I would not trust that to work. It depends how the macro is defined I
suppose, but it relies on assumptions about its definition. I would
assign it to a value thus:

ADC_Val = AD0GDR;                  // dummy read to clear DONE bit


Clifford

Author: Thomas Fernando (thomas_f)
Posted on:

Rate this post
0 useful
not useful
Thanks for looking it over ,Clifford.

Clifford Slocombe wrote:
>
>> AD0CR   &= 0x00200602;   // see comment plate
>  Did you intend to use &= here?

That was a mistake,corrected.But it still does not work.

ADC_Val = AD0GDR;                  // dummy read to clear DONE bit
Also tried this. No effect.

Hopefully the morning would give some fresh ideas :).

Author: Thomas Fernando (thomas_f)
Posted on:

Rate this post
0 useful
not useful
Thomas Fernando wrote:

> Hopefully the morning would give some fresh ideas :).
Actually it was the evening.
I had messed up my LPC21xx.h file while trying some random shots.It
works just fine now.

Author: Thomas Fernando (thomas_f)
Posted on:

Rate this post
0 useful
not useful
And of course this was there too.
Thanks Clifford !!

Clifford Slocombe wrote:
>
>>     AD0CR   &= 0x00200602;   // see comment plate
> Did you intend to use &= here? The reset value for AD0CR is 0x00000001,
> so you may have simply set AD0CR to zero and disabled the ADC.
>
> I suggest:
>
> AD0CR = 0x00200602;

Author: (unknown) (Guest)
Posted on:
Attached files:

Rate this post
0 useful
not useful
This is source code for ADC using LPC2148.

Author: Akash Phalak (asphalak)
Posted on:

Rate this post
0 useful
not useful
I was make a program of adc conversion using interrupt. i was connected 
a pot to AD0.1 to lpc2148 and send the converted data to the lcd. i was 
getting a output, but every time i have  to reset the controller for new 
value, means when the pot is in the middle then it will show the 
respective value but when i vary the pot it will not get the change 
value on lcd, it remains same.
I was post a program below. please give me the solution
#include <Philips\LPC2148.h>


//#define Addr1    (*((volatile unsigned long *) 0xFFFFF104))

void ISR_ADC (void);
void lcd_initialize(void);
void delay(unsigned int);
void lcd_cmd(unsigned char);
void lcd_data(unsigned char);
void lcd_display(void);
void strng(char *);
void hex_bcd(unsigned int);


char msg[20] = "ADC data:";   //msg
char msg1[20] = " Embedded";   //msg
char cmd[4] = {0x38,0x0c,0x06,0x01};

void lcd_initialize(void)

{
  int i;
  for(i=0;i<4;i++)
  {
    lcd_cmd(cmd[i]);  
    delay(15);
  }
}


void lcd_cmd(unsigned char data)

{
  IO0PIN   = data << 8;  
  IO0CLR   |= 0x00060000;     //RS = 0, RW = 0
  IO0SET   |= 0x00010000;     //EN = 1
  delay(15);
  IO0CLR   |= 0x00010000;     //EN =0
}


void lcd_data(unsigned char data)

{
  IO0PIN   = data << 8;  
  IO0SET   |= 0x00050000;     //RS = 1,EN = 1  
  IO0CLR   |= 0x00020000;     //RW = 0  
  delay(15);  
  IO0CLR   |= 0x00010000;     //EN = 0
}


void strng(char *str)
{
  while(*str)
  {
    lcd_data(*str++);
  }
}


void delay(unsigned int n)
{
  int i,j;
  for(i=0;i<n;i++)
  {
    for(j=0;j<0x270;j++);  
  }
}


void hex_bcd(unsigned int var)
{
  unsigned char i,d[4];
  lcd_cmd(0xC0);
  for(i=0;i<4;i++)
  {
    d[i] = var % 10;
    var = var / 10;
  }
  for(i=0;i<4;i++)
  {
    lcd_data(d[3-i] + 0x30);
  }
}


void ISR_ADC (void) 
{
  unsigned int val;
  AD0CR &= 0xFEFFFF00;
  //VICIntEnClr |= (1<<18);
  val = (AD0DR1 & 0x0000FFC0) >> 6;
  hex_bcd(val);
  //AD0INTEN |= (1<<1);
  //VICIntEnable |= (1<<18);
  AD0CR &= 0xFFFFFF02;  //Setup A/D:10-bit AIN1 @ 4.28MHz
  AD0CR |= 0x01000000; //Restart A/D Converter
  //return;
  //strng(msg1);
  VICVectAddr = 0; // The ISR has finished!
}


int main (void)
{

  PINSEL1 = 0x01000000; // P0.28 set to input AD0.1
  IO0DIR = 0X0007FF00; // PORT [P0.8--p0.18] as output
  delay(10);
  
  lcd_initialize();   // Initialize LCD
  delay(10);  
  strng(msg);

  VICIntEnable |= (1<<18);
  VICVectCntl0 = (1<<5) | 18;
  VICVectAddr0 = (unsigned) ISR_ADC;
  
  AD0CR = 0x00200602;  //Setup A/D:10-bit AIN1 @ 4.28MHz
  AD0INTEN |= (1<<1);
  AD0CR |= 0x01000000; // Start A/D Conversion
  while(1);
  return(0);
}

Author: Umesh Lokhande (Guest)
Posted on:

Rate this post
0 useful
not useful
Hello Akash

Working on your code and pointing error is whole lot of work. I have 
written a post with all explanation about how to configure ADC and 
step-by-step instruction guide to program ADC in LPC2148 
Microcontroller.

Here is 
link:http://www.binaryupdates.com/adc-in-lpc2148-arm7-m...

I am pretty sure you'll find all your answer after reading this post 
also in the end there is FREE TO DOWNLOAD PROJECT FILES SUPPLIED. I 
recommend you to download and try your hands with ADC of LPC2148 
Microcontroller

Good Luck !

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 useful
not useful
Umesh Lokhande wrote:
> Hello Akash
>
> ...

It has been three years since Ackash posted the message you have 
respondes to, and that was itself a hijack of a message posted 8 years 
ago.  One would hope that the question is answered now.  Apart from then 
the ARM7 based LPC2148 is almost obsolete for new designs.

Author: Thomas Fernando (thomas_f)
Posted on:

Rate this post
0 useful
not useful
Most amusing to get these notifications :-)

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.