ADC Programming in ARM Microcontrollers


ADC holds an important significance in every Microcontroller since it allows user to measure the external analog parameters and gives the result in digital form. Almost every advanced Microcontroller is equipped with ADC and so does ARM series controllers. This tutorial is all about ADC programming in ARM microcontrollers and interfacing of temperature sensor LM35 with it.


ARM controllers consists of a 10 bit Successive approximation ADC with 4 to 8 pins based on the Controller. This ADC operates from 0 to 3V so the input voltage from the sensor should not exceed 3V.  




A/D control register which was used yo select the operating mode in which the ADC should operate. SEL bits in this register used to select the channels we are about to use. CLKDIV bits are used to  produce the clock for A/D converter which should be less than 4.5MHz.  PDN bit is to choose the operational mode while START bits are used to start the A/D conversion.


A/D Data register is a 32 bit register which consists of the result obtained from the A/D conversion along with the Flag bit which indicates that the conversion is complete. It do also consists of several other registers each of them serves a specific purpose. The 6-15 bits of this register holds the converted values which can be retrieved by shifting the values.

I have given a simple description of the registers we are about to use. However for deep understanding kindly refer to the Manual which provides a brief explanation of the bits in these registers. Download the manual from the below link


For the illustration of ADC working we are using a simple temperature sensor LM35 in which the output voltage changes by 10mV with rise or fall in each degree temperature. And it can sense temperature up to 150 degree Celsius. In ADC’s we always must perform calibration to obtain real value.  Since we are using a 10 bit ADC our resolution will be 2^ 10 =1024

Step Size = Reference voltage / Resolution = 3.3v / 1024 = 3.22 mV

So the value of the ADC changes with change in Ain voltage of about 3.22mV. The temperature sensor gives 10mV change in output with every change in temperature. For a degree change in temperature A/D value will undergo 3 increments 3.22mV * 3 = 9.7mV which is approximately equal to 10 mV. So we have to divide the A/D value by 3 to obtain the real time temperature.


This code was built using Keil uVision 4 IDE.

unsigned int temperature;
int i;
char conv_temp[8];
void adc(void);
void lcd(unsigned char data,int rs_status);  //lcd subroutine
void delay(void);

int main(void)
   PINSEL1=(1<<22);                  //Specifying A/D pin function
   lcd(0x38,0);                            //lcd intialization

void adc(void)
     ADCR|=(1<<0)|(1<<16)|(1<<8)|(1<<21)|(1<<24); //mode selection
       while(!(ADDR&(0x80000000)));         //Checking conversion status
       temperature=(ADDR>>6)&0x3ff;     //Reading A/D value
     temperature=temperature/3;          //Real temp conversion
       sprintf(conv_temp,"%lu",temperature);   //int to char conversion

void lcd(unsigned char data,int rs_status)

void delay(void)
     unsigned int j;
The following two tabs change content below.
Frank Donald

Frank Donald

Junior Network Engineer at Tata Communications
Frank Donald is an Electronics and Communication Engineer who loves building stuff in his free time. Video games, blogging and programming are the things he loves most

Ask your query

2 Comments on "ADC Programming in ARM Microcontrollers"

Notify of
Sort by:   newest | oldest | most voted

Dear,Frank Donald thank you for your post.
I worked in this program and i simulated it,i observed some error in calibration of ADC ,but it’s very useful and your explanation is very good , i suggest you to please keep the ADC registers snippets.I changed your code as **temperature/3 to **temperature/3.1 it works fine.