ADC10 Tutorial for MSP430 Launchpad

Pinterest icon

Tutorial on configuring and programming the 10 bit ADC of MSP430 Launchpad (MSP430G2553)

In this section we will learn how to configure and use the ADC10 of MSP430G2XX3 microcontroller that comes with the TI Launchpad development board. Later we will configure the internal temperature sensor of MSP430 and display the value on a 16X2 LCD module.

MSP430G2xxxx series (for eg MSP430G2553) comes with a 10 bit Successive Approximation ADC that can operate at 200Ksps. The ADC10 of MSP430G2xxx3 comes with 8 analog channels which can be used for interfacing external sensors and two internal one (one for Internal temperature sensor and the other for measuring Vcc-Vss/2 ).The ADC 10 also has a built in software selectable voltage reference source (1.5V or 2.5V) along with provision for providing external references.


link to xanthium enterprises repo on Github containing code for serial communication using CSharp and Dot net Framework 

All the C source files  used in this tutorial for configuring ADC10 can be downloaded from our GitHub Page.

If you are new to Github Check this article to download code .

Block Diagram of ADC10

ADC10 tutorial for MSP430 launchpad

Clock Sources

The SAR core of the MSP430G2xxx3 microcontroller can be clocked by either ACLK, SMCLK, MCLK or by the internal Oscillator ADC10OSC.The clock produced by the internal oscillator ADC10OSC is in the range of 5MHz and varies with changes in temperature and Voltage. The default clock for ADC10 is taken from ADC10OSC .

ADC10SSELx bits on ADC10CTL register is used to select the clock source. The selected clock can be divided by using ADC10DIVx bits (on ADC10CTL) before giving to the SAR core. The clock coming after the Divider is called ADC10CLK and is also used for setting Sample and Hold Timing.

selecting clocks to msp430 10 bit adc on launchpad development board  tutorial

In IAR embedded Workbench and Code Composer Studio the clock sources can be easily selected using the constants defined in the header file of the respective controller (here I am using MSP430G2553 so msp430g2553.h).Same option is available for the clock divider(ADC10DIVx).

finding clock divider  values on msp430 header file in  IAR embedded workbench

Modes of Operation

ADC10 of MSP430G2xxx can operate in 4 different modes ,they are 

1 Single Channel,Single Conversion A single channel is converted once 
 2 Sequence of Channels A Sequence of channels are converted once
 3 Repeat Single Channel A single channel is converted repeatedly
4 Repeat Sequence of Channels A Sequence of channels are converted repeatedly

Configuring the analog pins

The analog channels of ADC10 are selected by using INCHx bits on ADC10CTL1 register. In the case of MSP430G2xxx3 there are 8 analog channels + 2 internal channels. The internal channels are not available outside the chip and are used for connecting the internal temperature sensor and VCC/2.

Like any other microcontroller the ADC pins of MSP430 are shared with other peripherals like Digital IO, Comparator Inputs etc, So before reading analog values from outside we have to select the analog function of the port pins .This is done by setting the appropriate bits in the Analog Enable Control Register ADC10AE0.

Configuring the ADC core

Before configuring the ADC, the SAR core have to be switched on using ADC10ON bit and ENC bit should be cleared. After that you can configure the clock sources, interrupts, analog channels etc. After the configuration is over you can start the ADC conversion by setting ADC10SC bit and ENC.

The ADC conversion can be started by software or by hardware. In Software ,the conversion is started by setting the ADC10SC bit by the program. In Hardware, the conversion is started by an external peripheral like Timer A ,this method is recommended if there are time and power constraints.

ADC10 Interrupts

After the conversion is finished the ADC10 sets the ADC10IFG flag and an interrupt is generated. The converted value is available in the ADC10MEM register for further processing. The ADC10IFG flag is automatically reset after the interrupt is processed. Please note that for the interrupt to occur the ADC10IE flag and GIE bit should be set.

Writing the Code

Now let's write a small program to configure the ADC and convert analog values generated by a potentiometer. The program will use Single Channel, Single conversion and convert the voltage levels of a potentiometer attached to the analog channel A0 of MSP430G2553 chip (Pin number 2) on Launchpad board.

The circuit diagram for connecting the Launchpad is shown below along with the image. The central pin of the pot is connected to the A0 pin of MSP430G2553.

connecting a potentiometer (pot) to msp430 launchpad for adc interfacing

interfacing a potentiometer with msp430 launchpad

Now type the following code into IAR or CCS IDE and compile.

#include "msp430g2553.h"
#include "intrinsics.h"
void main(void)
   WDTCTL = WDTPW  + WDTHOLD;    // stop WDT

   // ADC configuration,V+ref=3V,V-ref=0V,Channel=A0
   ADC10CTL0  = ADC10ON + ADC10IE; // Vref Vr+=3v,Vr-=VSS,
                     // S&Htime = 4 X ADCCLK,ADC10 on,ADC interrupts enabled
   ADC10CTL1  = ADC10DIV_7; // INCH =0000->A0,ADCCLK src = ADC10CLK,
                            // ADCCLK/8,Single Channel Single Conversion

   ADC10AE0   = INCH_0;     // channel A0 
   ADC10CTL0 |= ENC + ADC10SC; // Start Conversion
   _BIS_SR(LPM0_bits +GIE);    // Go to LPM0,interrupts enabled

/*                 interrupt vectors for MSP430                            */

#pragma vector = ADC10_VECTOR
__interrupt void adc10_interrupt(void)
  ADC10CTL0 |= ENC + ADC10SC;  // Start Conversion again

Here ADC10 is clocked using ADC10OSC, interrupts are enabled and Voltage reference is selected as default (Vr+ =3V and Vr- =0V).The conversion is started by setting ADC10SC and ENC by Software. After the conversion is finished, ADC10 interrupt is generated.

To View the converted value put a break point inside the interrupt service routine and view the ADC10MEM register inside the Register Viewer.Adjust the shaft of the potentiometer to see the variation of ADC value from 0 to 3FF.When the wiper of the potentiometer is near the ground the adc value will be equal to zero and when it is near 3V the value will be around 3FF.

viewing the converted adc value inside the IAR embedded workbench for MSP430

LED Bar graph Display

msp430 launchpad driving a led bargraph display according to ADC values

Here we are going to implement a bar graph style display to show the ADC values using MSP430 Launchpad and a couple of LED’s. The bar graph display consists of 8 LED's arranged linearly and connected to Port 2 of the MSP430G2553 chip.

When the ADC value is Maximum ie 0xFE all the 8 LED's will light up and when ADC value is above 10, only one will glow. By varying the potentiometer connected to the A0 input of MSP430 you can vary the number of LED's lighting up.

One thing to note is that, P2.6 and P2.7 of MSP430G2553 will behave as Crystal input/output (XIN/XOUT) by default. In order to put the pins in digital IO mode their respective bits in P2SEL and P2SEL2 should be cleared.

The circuit diagram is shown below.

circuit diagram for implementing a bar graph type display for msp430 launchpad

The code converts the analog value available at A0 input into its equivalent digital value.After the conversion an "if " ladder in the Interrupt Service Routine decides which LED's to light up.


The Video below shows the LED's lighting up depending on the value on A0 input.The Voltage at A0 is varied by turning the potentiometer attached to it.


Please put your suggestions and opinions in the comment box below.




try displaying on lcd

nice article

Nice one