EmbDev.net

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


von Thomas F. (thomas_f)


Rate this post
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

von Clifford S. (clifford)


Rate this post
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_38_4]|pp=[t=pip,i=LPC2131_32_34_36_38_4]
http://www.nxp.com/#/pip/pip=[pip=LPC2141_42_44_46_48_3]|pp=[t=pip,i=LPC2141_42_44_46_48_3]

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

von Thomas F. (thomas_f)


Rate this post
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

von Thomas F. (thomas_f)


Rate this post
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.

von Clifford S. (clifford)


Rate this post
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

von Thomas F. (thomas_f)


Rate this post
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 :).

von Thomas F. (thomas_f)


Rate this post
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.

von Thomas F. (thomas_f)


Rate this post
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;

von (unknown) (Guest)


Attached files:

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

von Akash P. (asphalak)


Rate this post
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
1
#include <Philips\LPC2148.h>
2
3
4
//#define Addr1    (*((volatile unsigned long *) 0xFFFFF104))
5
6
void ISR_ADC (void);
7
void lcd_initialize(void);
8
void delay(unsigned int);
9
void lcd_cmd(unsigned char);
10
void lcd_data(unsigned char);
11
void lcd_display(void);
12
void strng(char *);
13
void hex_bcd(unsigned int);
14
15
16
char msg[20] = "ADC data:";   //msg
17
char msg1[20] = " Embedded";   //msg
18
char cmd[4] = {0x38,0x0c,0x06,0x01};
19
20
void lcd_initialize(void)
21
22
{
23
  int i;
24
  for(i=0;i<4;i++)
25
  {
26
    lcd_cmd(cmd[i]);  
27
    delay(15);
28
  }
29
}
30
31
32
void lcd_cmd(unsigned char data)
33
34
{
35
  IO0PIN   = data << 8;  
36
  IO0CLR   |= 0x00060000;     //RS = 0, RW = 0
37
  IO0SET   |= 0x00010000;     //EN = 1
38
  delay(15);
39
  IO0CLR   |= 0x00010000;     //EN =0
40
}
41
42
43
void lcd_data(unsigned char data)
44
45
{
46
  IO0PIN   = data << 8;  
47
  IO0SET   |= 0x00050000;     //RS = 1,EN = 1  
48
  IO0CLR   |= 0x00020000;     //RW = 0  
49
  delay(15);  
50
  IO0CLR   |= 0x00010000;     //EN = 0
51
}
52
53
54
void strng(char *str)
55
{
56
  while(*str)
57
  {
58
    lcd_data(*str++);
59
  }
60
}
61
62
63
void delay(unsigned int n)
64
{
65
  int i,j;
66
  for(i=0;i<n;i++)
67
  {
68
    for(j=0;j<0x270;j++);  
69
  }
70
}
71
72
73
void hex_bcd(unsigned int var)
74
{
75
  unsigned char i,d[4];
76
  lcd_cmd(0xC0);
77
  for(i=0;i<4;i++)
78
  {
79
    d[i] = var % 10;
80
    var = var / 10;
81
  }
82
  for(i=0;i<4;i++)
83
  {
84
    lcd_data(d[3-i] + 0x30);
85
  }
86
}
87
88
89
void ISR_ADC (void) 
90
{
91
  unsigned int val;
92
  AD0CR &= 0xFEFFFF00;
93
  //VICIntEnClr |= (1<<18);
94
  val = (AD0DR1 & 0x0000FFC0) >> 6;
95
  hex_bcd(val);
96
  //AD0INTEN |= (1<<1);
97
  //VICIntEnable |= (1<<18);
98
  AD0CR &= 0xFFFFFF02;  //Setup A/D:10-bit AIN1 @ 4.28MHz
99
  AD0CR |= 0x01000000; //Restart A/D Converter
100
  //return;
101
  //strng(msg1);
102
  VICVectAddr = 0; // The ISR has finished!
103
}
104
105
106
int main (void)
107
{
108
109
  PINSEL1 = 0x01000000; // P0.28 set to input AD0.1
110
  IO0DIR = 0X0007FF00; // PORT [P0.8--p0.18] as output
111
  delay(10);
112
  
113
  lcd_initialize();   // Initialize LCD
114
  delay(10);  
115
  strng(msg);
116
117
  VICIntEnable |= (1<<18);
118
  VICVectCntl0 = (1<<5) | 18;
119
  VICVectAddr0 = (unsigned) ISR_ADC;
120
  
121
  AD0CR = 0x00200602;  //Setup A/D:10-bit AIN1 @ 4.28MHz
122
  AD0INTEN |= (1<<1);
123
  AD0CR |= 0x01000000; // Start A/D Conversion
124
  while(1);
125
  return(0);
126
}

von Umesh Lokhande (Guest)


Rate this post
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-microcontroller/

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 !

von Clifford S. (clifford)


Rate this post
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.

von Thomas F. (thomas_f)


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

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.