Monday , June 18 2018

# ADC in LPC2148 ARM7 Microcontroller Analog to Digital Converter

Let’s learn about ADC in LPC2148 ARM7 Microcontroller. Microcontrollers are very useful especially when it comes to communicate with other devices, such as sensors, motors, switches, memory and even other microcontroller. As we all know many interface methods have been developed over years to solve complex problem of balancing need of features, cost, size, power consumption, reliability etc. but ADC Analog-to-Digital converter remains famous among all. Interfacing analog sensors using ADC is simple and efficient technique to read data from sensor. Let’s have a look at basics and then we will look at real world example project.

#### What is ADC & its Resolution?

Analog to Digital Converter (ADC) is used to convert analog signal/voltage into its equivalent digital number so that microcontroller can process that numbers and make it human readable. The ADC characterized by resolution. The resolution of ADC indicates the number of digital values. Let’s take example: In LPC2148 microcontroller we have in-built 10-bit ADC. So for 10-bit ADC resolution is 10-bit and maximum value will be 210=1024. This means our digital value or discrete level lies between 0 to 1023. There is one more term important to understand while dealing with ADC and it is step size. Step size is the minimum change in input voltage which can be resolved by ADC. The concept of step size is closely associated with the resolution of ADC.

So in this case we can measure minimum 2.23 mV (Approx.) with our microcontroller. This is how step size defines an accuracy of ADC circuit.

#### Introduction: ADC in LPC2148 ARM7 Microcontroller

The ADC in LPC2148 ARM7 Microcontroller is 10-bit successive approximation analog to digital converter. The features are listed as:

• ADC operating frequency is 4.5 MHz (max.), operating frequency decides the conversion time.
• Supports power down mode.
• Burst conversion mode for single or multiple inputs.

There are several registers associated with ADC feature but we will mainly discussing about ADC Control Register (ADCR) & ADC Global Data Register (ADGDR). For more details on register description keep datasheet in hand UM10130, Chapter: 19.

Let’s have a look at table which illustrate ADC related channels and pins:

#### Registers of ADC in LPC2148 Microcontroller

There are several registers which will be used to setup and configure ADC feature in LPC2148. The two registers we will be concerning about: ADCR (A/D Control Register) and ADGDR (A/D Global Data register).

#### Programming Steps: ADC in LPC2148 ARM7 Microcontroller

• Select channel we wish to use in our conversion
• Select clock for conversion & start conversion
• Wait for conversion to complete
• Convert this result i.e. ADC output into decimal number
• Display reading on serial emulator or display device

Example Project: In this example project we will be using 10K POT to provide analog input at ADC Channel 0 i.e. Pin P0.28 of LPC2148 Microcontroller. To read ADC count from POT we will configure UART0 of LPC2148 and read data on terminal emulator (PuTTY). When we vary resistance of POT the change in ADC count will reflect on PuTTY terminal in real time. The circuit connection shown as:

#### Source Code: ADC in LPC2148 ARM7 Microcontroller

The project is fully tested and functioning. We only have to compile and download .hex file onto LPC2148 Microcontroller. To see output on computer we will have to configure PuTTY to establish serial communication to read ADC results on PuTTY.

IMPORTANT: After loading .hex file, Make sure that you’re not into ISP Mode. We will be using same UART0 for programming as well as for receiving ADC result. In case if you’re using STK2148-UltraLite Board then turned off SW7 switches to read ADC Data on PuTTY.

Once we have done with all settings, just open console. And we will start receiving ADC results on PuTTY, sent by LPC2148 Microcontroller. Here is an output from our project:

Umesh Lokhande holds a Master degree in Scientific Instrumentation from University of Applied Sciences Jena, Germany. and has previously worked at Orbotech, Alere Technologies etc. Umesh is also a founder and first author of BINARYUPDATES.COM

1. splendid……….

• could you please explain the C language code

• write about DAC too with full explanation

• I am working on it, soon will be posted. I hope you understand that it takes lots of time to document explanation of every line of code

2. hey currently i am need of various other interfacing with LPC2148 as my semester exam is approaching so can you please share with me the real platform where i can find stuffs like interfacing of RFID,Biometric,GSM,ZIGBEE,SD-MMC card,sensors,memory etc with LPC2148

consider this as urgent

3. (adcdata >> 6) & 0x3ff

Kindly anyone explain the above command in detail…

• making to 16bits output what we get from ADC is 10 bit so shifting by right 6 times provides 16 bit

4. Dear sir,
Can u pls gelp me with sorting out my difficulty for understanding
Initclock();And inituart(); Functions in this code..
And pls help to understand How to claculate clock frequency and the value to load to register for a temperature sensor project.. etc..

5. Thanks for such elaborative and wonderful explanation….!!!!

6. why u used return((adcdata >> 6) & 0x3ff) ;????
that means return((adcdata /2^6 & 1023=???

7. what if we want to connect external ADC?

8. What is the identity to measure voltage using advice values

9. We have use adc of the 10 bit then which 10 bits can we consider in adc control register
What actually it means by 10 bit

• I too didn’t understand.
Can you explain if you got the answer ?