Tuesday , December 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.

Analog To Digital Conversion

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.

Calculate: ADC Resolution in LPC2148 ARM7

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:

  • LPC2148 has two inbuilt ADC Modules, named as ADC0 & ADC1.
  • ADC0 has 6-Channels (AD0.1-AD0.6).
  • ADC1 has 8-Channels (AD1.0-AD1.7).
  • 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:

ADC Related Pins in LPC2148

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).

Register Name Function
ADCR A/D Control Register: The ADCR register must be written to select the operating mode before A/D conversion can occurs.
ADGDR A/D Global Data Register: This register contains ADC’s DONE bit and the result of the most recent A/D conversion.
ADSTAT A/D Status Register: This register contains DONE and OVERRUN flag for all the A/D Channels, as well as the A/D interrupt flag.
ADGSR A/D Global Start Register: This address can be written (in the AD0 address range) to start conversions in both A/D converters simultaneously.
ADINTEN A/D Interrupt Enable Register: This register contains enable bits that allow the DONE flag of each A/D channel to be included or excluded from contributing to the generation of an A/D interrupt.
ADDRx A/D Channel x Data: ‘x’ varies from 0 to 7

Programming Steps: ADC in LPC2148 ARM7 Microcontroller

  • Configure input pin as analog input pin for ADC block
  • Select channel we wish to use in our conversion
  • Select clock for conversion & start conversion
  • Wait for conversion to complete
  • Read 10-bit conversion result
  • 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:

CIRCUIT DIAGRAM: ADC in LPC2148 ARM7 Microcontroller

ADC in LPC2148 ARM7 Microcontroller
Circuit: ADC in LPC2148 ARM7 Microcontroller

Source Code: ADC in LPC2148 ARM7 Microcontroller

Download Project: Click Here

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:

Output of ADC in LPC2148 ARM7

This is how we can program internal ADC in LPC2148 ARM7 Microcontroller to read analog input from any device. In future post we will explore topics such as multiple ADCs and External ADC interfacing etc. We hope this post will help you to get your ADC up-running. If you have any question then please feel free to drop comment. Thanks…!!!!

About Umesh Lokhande

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……….

    please upload the same for DAC as soon as possible….

    waiting for your post………….

  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

    waiting for your reply……

  3. could you please explain the C language code

  4. write about DAC too with full explanation
    please do this fast

  5. 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

  6. (adcdata >> 6) & 0x3ff

    Kindly anyone explain the above command in detail…

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

  8. 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..
    Your details are much helpful indeed..

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

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

  11. Thanks sir..Doing Best Job

  12. what if we want to connect external ADC?

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

  14. 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

  15. still waiting for your new post of 2148..hope u will post something for us..

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


Register | Lost your password?