NPEDUCATIONS, Electronic circuits development, electronics tutorials, microcontroller tutorials and projects, advanced microcontroller (ARM) based tutorials and projects, Embedded c development, Embedded c for ARM cortex M, Intel IoT based projects, IoT projects, CC3200 launch pad projects, MSP430 Launchpad tutorials and projects, Tiva C launch pad tutorials and projects, 8051 tutorials and projects, sensor interfacing with microcontroller tutorials, data communications and networking tutorials, peripheral interfacing with microcontroller, led message scrolling display, arduino based tutorials and projects, intel galileo based tutorials and project, ADC interfacing tutorials, LED Blinking, LCD interfacing, Embedded System tutorials and projects, B.tech projects, M.tech projects, online Embedded C training

TI MSP430 ADC10 Tutorial - Part1

TI MSP430G2553 ADC10 tutorial


MSP430 ADC10 Tutorial - Part1 - using Internal Temperature sensor and polling method. 
In this tutorial, we are trying to make the MSP430 ADC10 easier to understand, so that you can easily build your experiment on ADC10.

 In this tutorial, we are going to discuss about the ADC 10 operation and trying to write a simple program to work with ADC10 in MSP430 launch pad.
Basically, the MSP430 itself designed with two types of ADC’s core, off course not all versions.
1. ADC10 core
2. ADC12 core
 The last digit in ADC (10 or 12) indicates the resolution of the ADC.
Here, I am fully concentrating on ADC10 operation of MSP430G2553.

 The ADC10 in MSP430 is a multi-channel ADC which means it capable to convert more than one input channel (Maximum 8 external - input channels (A0-A7)). It’s also contains four internal channels including the in-built TEMPERATURE SENSOR. Maximum sampling rate of ADC10 is more 200-ksps.
The MSP430G2553 itself contains internally a 10-bit ADC core. It converts the analog input value to 10-bit binary representation as output and then stores the value into a special register called “ADC10MEM”. The conversion formula for the ADC10 is given by
                                                                        Nadc = 2^10 *((Vin-VR-)/(VR+ - VR-))
Where,
 VR+ and VR- are used to define upper and lower limits of the conversion which can be programmable.
One of main difficultly to work with advanced processors is its special registers. Day by day a more number of digital and analog IC’s has been integrated into processor like our MSP430 16-bit processor, so the designer providing many special registers to the control the operation of the digital and analog IC’s integrated in the processor. At the user end due to presence of more special registers  it is more difficult to work with or to remember, but these registers will bring more flexibility to the user so that one can change/program a lot of options and operations available in that integrated chip.

 Therefore it is necessary for the user to look at what are special registers available to operate with internal integrated IC’s! That’s why I listed the following registers set and its short form used to operate the ADC10.
Ok! Come back to actual track!. There are 8-special registers are available to make ADC10 operation as programmable. The Texas Instruments has included these many registers to make the ADC10 core more powerful and flexible to program its operation.

List of ADC10 special registers:
1. ADC10 input enable register 0                   ADC10AE0.
2. ADC10 input enable register 1                   ADC10AE1.
3. ADC10 control register 0                            -- ADC10CTL0.
4. ADC10 control register 1                           -- ADC10CTL1.
5. ADC10 memory                                         -- ADC10MEM.
6. ADC10 data transfer control register 0       ADC10DTC0.
7. ADC10 data transfer control register 1      ADC10DTC1.
8. ADC10 data transfer start address              ADC10SA.

 Here my intension is to make the basic ADC10 operation simple, so that who are new to the MSP430 ADC can easily understand and start work with it. Therefore I am not going to discuss all ADC10 core registers. I am going to explain Three ADC10 special registers in MSP430, by using these three we control the basic operation of ADC10 in MSP430 and also write our simple ADC program.

There are two special control registers are used to configure ADC10 core
1. ADC10CTL0.
2. ADC10CTL1.
3. ADDC10MEM.

These are more useful registers to configure the basic operations of the ADC10 core. All the above three registers are 16-bit registers.

Fig 1. ADC10 Control Register 0 and Control Register 1


1. Generally ADC10CTL0 is used mainly to configure different reference voltages for ADC10 core, output data format (binary or two’s complement), sampling timings. Some bit are used to configure the clock source and ADC interrupts.
2. Generally ADC10CTL1 is used mainly to configure ADC clock, sampling source selection and some bits are used to select input channels and its conversion sequence.
Now we have understand that ADC10CTL0 register deals with ADC reference voltage, clock and ADC interrupts, where as ADC10CTL1 is used to selected input channels and its conversion sequence. Now we will look into the block diagram of MSP430 ADC10.
3. ADC10MEM is a 16-bit register used to store the binary result produce by the ADC10 device.

To make the ADC10 in MSP430 simpler to understand, the ADC10 Block diagram is divided into five blocks as dotted lines
1. Sample and conversion module.
2. Channel Selection module.
3. Sample and Hold configuration module.
4. ADC clock source selection module.
5. Reference Voltage Selection module.
Note 1: I don’t want to scare the beginners of MSP430, so that some of the special bits and modules are not drawn in the block diagram. Don’t worry I will explain those in next series of tutorials. First of all understand the basic modules and special registers available in the ADC10 of MSP430, so that you can able to write your own programs.

Fig 2. ADC10 Block diagram

1. Sampling and conversion module:

i. The sampling and conversion module itself consists of 10-bit SAR (Successive Approximation Register technique) for conversion and Sample and Hold circuit to generate and hold the sample of input signal
ii. ADC10ON: This bit is used to switch ON or OFF the ADC device. This bit should be enabled otherwise ADC10 won’t start.
iii. The SAMPCON signal controls the sample period and start of conversion. When SAMPCON is high, sampling is active.
iv. ADC10MEM: This register is used to store the binary result produced by the ADC10 device. It is 16-bit register.

2. ADC10 Input channel selection:

i. INCHx:          Actually MSP430G2553 provided 8 external and 4 internal channels are provided. These channel selection can be done by using INCHx bits.
                        0000 - INCH0 – External Channel 1 – P1.0
                        0001 - INCH1 – External Channel 2 – P1.1
- -
- -
- -
1000 - INCH8 – Internal channel 8 – External Voltage reference VeREF+.
1001 - INCH9 – Internal channel 9 –VREF/VeREF-.
1010- INCH10 – Internal Temperature sensor.
- -
- -
- -

These input channel selection bits available on ADC10CTL1 register as INCHx.

ii. CONSEQx: Conversion Modes
ADC10 has four conversion modes of operations which can be selected by the CONSEQx bits.
1. Single channel single conversion mode: In this mode a single channel is converted once (CONSEQx = 00).
2. Sequence of channels conversion mode: In this mode a sequence of channels is converted once (CONSEQx = 01).
3. Repeat single channel conversion mode: In this mode a single channel is converted repeatedly (CONSEQx = 10).
4. Repeat sequence of channels conversion mode: In this mode a sequence of channels is converted repeatedly (CONSEQx = 11).
Note 2:            Where do we use these modes?
Generally if we require more than one sample I go for repeat conversion modes. For example if you want to sampling the voice (f=4000kHz) we need to generate 8000 samples per second (Nyquist rate). Then I configure the conversion mode in either two or three modes (CONSEQx = 10 and CONSEQx = 11) and with the help of PWM generation using Timers A and B (SHSx bits selection) in MSP430 I can generate 8000 samples per second.  Any way doesn’t worry about these conversion modes, these thing will clearly explained in the next coming tutorials.

3. Sample and hold configuration module:

ENC: This bit is used to enable/disable the conversion.
            0 – ADC10 disabled.
            1 – ADC10 enabled.
MSC: Multiple Sample and Conversion. When MSC = 1 and CONSEQx > 0, Successive conversions are started automatically one by one. So this bit is used when we go multi-channel conversion application. For example, if you trying to prepare a weather forecasting application, you have to interface many sensors like Temperature, barometer, humidity, light sensor, etc.,, in such cases you go for multi- channel ADC conversion. In such application you have to enable the MSC = 1.
ADC10SHTx: Sample and Hold time selection
                        00 – 4 X ADC10CLKs
                        01 – 8 X ADC10CLKs
                        10 – 16 X ADC10CLKs
                        11 – 64 X ADC10CLKs

                                                            Fig 3. Sampling and conversion timings
           

From the above diagram tsample can be selected using ADC10SHTx bits. The Total sampling and hold time is given by
            t(sample & Hold)  = tsync + tsample.
The tsample can be configured by using ADC10SHTx bits – 4,8,16 or 64 ADC10CLK cycles.
Always the conversion time is fixed, which 13 ADC10CLK cycles is.
            tconvert = 13x ADC10CLKs.
The raising sample input signal (SHI) initiates the analog to digital conversion. The SHI source can be selected by using SHSx bits in ADC10CTL1.
                 SHI source selected by using SHSx bits –      00 -- The ADC10SC bit.
                                                                                       01 -- The Timer_A Output Unit 1.
                                                                                       10 --  The Timer_B Output unit 0.
                                                                                       11 -- The Timer_B Output unit 1.
These SHI sources are used to define the rate of sampling, check out note 2 in this tutorial.
The ISSH bit is used to invert SHI signal source.
ADC10SC: Start of Conversion bit. This bit automatically cleared after the conversion is completed.
                        0 – No sample and conversion start.
                        1 – Start sample and conversion.
The SAMPCON signal controls the sample period and start of conversion. When SAMPCON is high, sampling is active.

4. ADC Clock Source Selection Modules:

ADC10 can be sourced from three basic clock signals (ACLK, MCLK, SMCLK) of MSP430 or ADC10 internal oscillator (ADC10OSC) especially design for ADC10 core up to 5MHz depend up the MSP430 device variant.                                                                                                                                                                                                                                                                                                                        
ADC10SSELx: ADC10 clock divider bits, by using these bit we can choose different frequencies of the clock source which is selected by using ADC10SSELx bits. ADC10SSELx bits available in ADC10CTL1
                        01 – ACLK
                        10 – MCLK
                        11 –SMCLK
ADC10DIVx: ADC10 clock divider bits, by using these bit we can choose different frequencies of the clock source which selected ADC10SSELx bits. ADC10SSELx bits available in ADC10CTL1
                       000 – Clock source divided by 1.
                        001 – Clock source divided by 2.
                        010 – Clock source divided by 3.
                        011 – Clock source divided by 4.
                        100 – Clock source divided by 5.
                        101 – Clock source divided by 6.
                        110 – Clock source divided by 7.
                        111 – Clock source divided by 8.

5. MSP430 ADC10 Reference Voltage:

 MSP430 provides the flexibility that ADC10 core reference voltage can be sourced from external voltage or internal in-built voltage. In this tutorial, I am only concentrating on internal reference voltage which is far enough for our example program.
The Reference Generator can be enabled using REFON bit.
SREFx : SREF0 and SREF1 bits are used to buffer an external positive reference VeREF.
000 VR+ = VCC and VR- = VSS
001 VR+ = VREF+ and VR- = VSS
010 VR+ = VeREF+ and VR- = VSS.
011 VR+ = Buffered VeREF+ and VR- = VSS.
100 VR+ = VCC and VR- = VREF-/ VeREF-.
101 VR+ = VREF+ and VR- = VREF-/ VeREF-.
110 VR+ = VeREF+ and VR- = VREF-/ VeREF-.
111 VR+ = Buffered VeREF+ and VR- = VREF-/ VeREF-.
The ADC10 module contains a built – in voltage reference with two selectable voltages levels.
            REF2_5V = 1 à internal reference is 2.5V.
                            = 0 à internal reference is 1.5V, default.
If the Reference Voltage is to be Internal, then REFOUT = 0, default.
If the Reference Voltage is to be External, then REFOUT = 1.
Ok! We have seen some of ADC configuration bits. By using these, we can develop the basic ADC program using MSP430G2553.

 In this tutorial, The MSP430 internal temperature sensor output A10 is sampled once and the result is placed in ADC10MEM register. Again the output of the ADC is converted into DEGREES centi-grades. Finally, if the temperature value is greater than 25 degrees then a LED will ON otherwise it is in OFF stage. Up on reset, the MCLK and SMCLK are sourced by DCO clock with 1.2MHz frequency. Here ACLK is not applicable; because we haven't initialized the clock settings of MSP430 using Basic clock control registers (BCSCTLx). The ADC10OSC is chosen as default ADC10 clock source. The MSP430 internal temperature sensor output A10 is sampled once and the result is placed in ADC10MEM register. And a reference voltage (Vref) is set to 1.5V which is enough for Temperature sensor why because the voltage of temperature sensor is not exceeding 1.4V for commercial range of temperature. A 30usec of time is required for reference to settle. Therefore by using a software delay function _delay_cycles(30), offcourse this will produce not exact delay. One more important thing is that sampling and hold time which is 64 ADC10CLKs. I will explain regarding sample and hold timings in the next tutorial, because the tutorial became lengthy.

The program is divided into two sections
1.     ADC10 initialization.
// ADC initialization, for this we need initialize two ADC10 control register

/**i. ADC10CTL0 INITIALIZATION
   ADC10ON -- ADC is getting enabled when we set this bit
   REFON -- REFERENCE GENERATOR IS ON
  SREF_1 -- CONTECT THE ADC REFERENCE TO VREF+(INTERNAL VOLTAGE- VR+ = VREF+ AND VR- = Vss)
  REF2_5v -- REFERENCE GENERATOR VOLTAGE, REF2_5v = 0 --- 1.5V and REF2_5v = 1 -- 2.5V
   The default clock source for ADC10 is ADC10CLK--00 -- ADC10OSC
  The sampling and hold time is 64xADC10CLKs. Don't worry about this value i will clear this in next series of tutorial.
   ***********************************************************/

                ADC10CTL0 = ADC10SHT_3 + SREF_1 + REFON + ADC10ON;

 /** ii. ADC10CTL1 INITIALIZATION
   * INCH_10 -- CHANNEL10 IS SELECTED -- INTERNAL TEMPERATURE SENSOR
   * ADC10DIV_3 -- ADC10 clock divider bits -Clock source divided by 4      ******/

  ADC10CTL1 = INCH_10 + ADC10DIV_3;

2. Generating a delay of 30 microseconds for reference voltage to be settled before ADC10 conversion.

/* Wait for 30 microseconds delay to settle down the reference. Here the reference voltage is getting ON when we enable in REFON bit, after that we have added ADC10CTL1 instruction and _delay_cycles(30) is used to generate the delay for reference to settle down
***********************************************************/

/* The _delay_cycles(no.of cycles) takes the argument on number of cycles.For example, if the operating clock frequency is 1MHz then _delay_cycles(1) produce 1 microsecond delay. The Master clock (MCLK) is sourced by DCO of 1.2MHz ~ 1MHz. Therefore delay_cycles(30) may produce a delay approximate to 30 microsecnds.
 **********************************************/

                          _delay_cycles(30);

3. INFINITE LOOP CONTINUOUSLY REPEATS THE ADC CONVERSION MECHANISM.
THIS PROGRAM USES SOFTWARE POLLING METHOD TO CHECK WEATHER ADC CONVERSION IS COMPLETED.

while(1)
{
/********************************************************************
Enable the conversion by using ENC bit and start Conversion by using ADC10SC bit in ADC10CTL0.
Note: Use compound OR (|=) operator for the bits assignment of ADC10CTL0. Because this is second time you are using ADC10CTL0 for bit assignment, therefore it may overwrite the old settings.
***********************************************************8*****/

ADC10CTL0 |= ENC + ADC10SC;//Enable and start ADC sampling and conversion
while (!(ADC10IFG & ADC10CTL0)); // check for ADC conversion is completed
ADCDATA = ADC10MEM; // Read ADC value
/******************************************************************
Temperature in degrees conversion by using formula ADCDATA = (1024*(Vin/Vref)); here Vin = Vtemp
Vtemp is given in the data sheet of MSP430G2553 Vtemp  = TCtsensor(273+T(0C)) – page no: 40.
**********************************************************************/
   TEMP_in_Deg = ((ADCDATA * 1500)/1024 - 986)/3.55;
   if (TEMP_in_Deg > 25)
   P1OUT |= 0x01;                          // LED on
   else
   P1OUT &= ~0x01;                         // LED off
 }


 OUTPUT:
output showing the raw data of ADC temperature and its converted value in degrees.

Program Code:
/**************************************************************************************
 ****************************WELCOME TO NPEDUCATIONS **********************************
                   Up on reset the DCO clock source with 1.2MHz frequency
 acts as default source for MCLK and SMCLK signals. Here ACLK is not applicable because we
 haven't initialized the clock settings of MSP430 using Basic control control registers(BCSCTLx).
 The ADC10OSC is chosen as default ADC10 clock source. The MSP430 internal temperature sensor
 output A10 is sampled once and the result is placed in ADC10MEM register. And a reference
 voltage (Vref) is set to 1.5V which is enough for Temperature sensor why because
 the voltage of temperature sensor is not exceed 1.4V for commercial range of temperature.
 A 30usec of time is required for reference to settle. Therefore by using a software delay
 function _delay_cycles(30), offcourse this will produce not exact delay. One more important
 thing is that sampling and hold time which is 64 ADC10CLKs. I will explain regarding
 sample and hold timings in the next tutorial, because the tutorial became lengthy.
**************************************************************************************/
#include

//Declare ADCDATA variable to store ADC data
long ADCDATA;
long tempInDeg;

//MAIN PROGRAM
void main(void)
{
  // Stop Watch Dog Timer
    WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  // set the P1.0 as output
    P1DIR |= 0x01;

 // ADC initialization

   /* ADC10CTL0 INITIALIZATION
   ADC10ON -- ADC is getting enabled when we set this bit
   REFON -- REFERENCE GENERATOR IS ON
   SREF_1 -- CONTECT THE ADC REFERENCE TO VREF+(INTERNAL VOLTAGE- VR+ = VREF+ AND VR- = Vss)
   REF2_5v -- REFERENCE GENERATOR VOLTAGE, REF2_5v = 0 --- 1.5V and REF2_5v = 1 -- 2.5V
   The default clock source for ADC10 is ADC10CLK--00 -- ADC10OSC
   The sampling and hold time is 64xADC10CLKs. Don't worry about this value i will clear this
   in next series of tutorial.
   */

    ADC10CTL0 = ADC10SHT_3 + SREF_1  + REFON + ADC10ON;

   /* ADC10CTL1 INITIALIZATION
    * INCH_10 -- CHANNEL10 IS SELECTED -- INTERNAL TEMPERATURE SENSOR
    * ADC10DIV_3 -- ADC10 clock divider bits -Clock source divided by 4
    ******/

    ADC10CTL1 = INCH_10 + ADC10DIV_3;

   /* Wait for 30 microseconds delay to settle down the reference. Here the reference voltage is
    * getting ON when we enable in REFON bit, after that we have added ADC10CTL1 instruction and
    * _delay_cycles(30) is used to generate the delay for reference to settle down
    * */

      /* The _delay_cycles(no.of cycles) takes the argument on number of cycles.
       * For example, if the operating clock frequency is 1MHz then _delay_cycles(1) produce
       * 1microsecond delay. The Master clock (MCLK) is sourced by DCO of 1.2MHz ~ 1MHz. Therefore
       * _delay_cycles(30) may produce a delay approximate to 30 microsecnds.
       */

    _delay_cycles(30);

   // INFINITE LOOP CONTINUOUSLY REPEAT THE ADC CONVERSION MECHANISM.
   // THIS PROGRAM USES SOFTWARE POLLING METHOD TO CHECK WEATHER ADC CONVERSION IS COMPLETED.

    while(1)
    {
       ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
       while (ADC10CTL1 & ADC10BUSY);          // check for ADC conversion is completed

       ADCDATA = ADC10MEM;                 // Read ADC value

       // Temperature in degrees conversion by using formula ADCDATA = (1024*(Vtemp/Vref))
       tempInDeg = ((ADCDATA - 673) * 423) / 1024;
       //tempInDeg = ((ADCDATA * 1500)/1024 - 986.6)/3.55;

       if (tempInDeg > 39)
         P1OUT |= 0x01;                          // LED on
       else
         P1OUT &= ~0x01;                         // LED off

    }

}





2 comments :

  1. Nice One Where z the 2nd part of this tutorial

    ReplyDelete
  2. This is good, I have learnt a lot, thankyou

    ReplyDelete

Thanks for visiting NPEDUCATIONS. We will contact you soon

2 comments :

Aman Ankit said...

Nice One Where z the 2nd part of this tutorial

Viraj N H said...

This is good, I have learnt a lot, thankyou

Post a Comment

Thanks for visiting NPEDUCATIONS. We will contact you soon

If you really like this tutorial, Don't forget to give the comment or please subscribe to the RSS feed by submitting your E-mail or like our Facebook page.
Related Posts Plugin for WordPress, Blogger...

 
Powered by Blogger