PH415 Computer Interfacing
OSU logo
The content of this page is undergoing revision and will be moved to another site soon.
Analog Input

Table of Contents

Analog To Digital Conversion Specifications

  • The ADC10 features include:
    • Greater than 200-ksps maximum conversion rate
    • Monotonic 10-bit converter with no missing codes
    • Sample-and-hold with programmable sample periods
    • Conversion initiation by software or Timer_A
    • Input range of 0 to 3.3 V, with a maximum input tolerance of Vcc + 0.3 V
    • Software selectable on-chip reference voltage generation (1.5 V or 2.5 V)
    • Software selectable internal or external reference
    • Eight external input channels
    • Conversion channels for internal temperature sensor, VCC, and external references
    • Selectable conversion clock source
    • Single-channel, repeated single-channel, sequence, and repeated sequence conversion modes
    • ADC core and reference voltage can be powered down separately
    • Data transfer controller for automatic storage of conversion results

Configuring an Analog Input for the MSP430G2x3

  • Devices which don’t have all the ADC10 external inputs channels Ax or VeREF+/VREF+ and VeREF-/VREFavailable at device pins must not alter the default register bit configuration of the not available pins. See device specific datasheet. This is not the case for the MSPg2231.
  • To enable an ADC channel, set bits 7-0 to 1 in the one-byte register ADC10AE0 for each channel to be used. These bits enable the corresponding pin for analog input. BIT0 corresponds to A0, BIT1 corresponds to A1, etc. The analog enable bit of not implemented channels should not be programmed to 1.
  • Choose the A2 input on the P1.2 terminal, so add this line to the program:
    ADC10AE0 |= bit2;   // Enable analog input A2, preserving the status of other channels.
    Note that the values of P1DIR.2 and P1SEL.2 are irrelevant.
  • For two-byte registers, it is convenient to define the 1 condition for individual bits. Add these lines to the program:
    b0 = 0x0001; b1 = 0x0002; b2 = 0x0004; b3 = 0x0008; //1,2,4,8
    b4 = 0x0010; b5 = 0x0020; b6 = 0x0040; b7 = 0x0080; // 16,32,64 128
    b8 = 0x0100; b9 = 0x0200; b10 = 0x0400; b11 = 0x0800; // 256, 512, 1024, 2048
    b12 = 0x1000; b13= 0x2000; b14 = 0x4000; b7 = 0x8000; // 4096, 8192, 16384, 32768
  • The ADC10 peripheral is configured in part through ADC10CTL0, a 16-bit ADC10 control register. See section 22.3.1 of the family guide.
    • Bits 15-13 are defined by SREF, the select reference bits. Set this to 001 for VR+ = VREF+ and VR- = VSS. So, SREF = b0.
    • ADC10SHT, bits 12-11 of ADC10CTL0 specify the ADC10 sample-and-hold time. Choose ADC10SHT = 00 binary for 4 × ADC10CLKs. Thus, ADC10SHT = 0x0000.
  • The ADC10 peripheral also is configured through ADC10CTL1, a 16-bit ADC10 control register. See section 22.3.2 of the family guide.
    • Bits 4-3 are defined by ADC10SSEL, the ADC10 clock source select. Choose 10 binary for MCLK. So, ADC10SSEL = b4.
    • Bits 7-5 are defined by ADC10DIV, the clock divider. Choose 000 for divide by 1. So, ADC10DIV = 0x0000.

Analog to Digital Conversion

  • From the documentation, determine how to setup a single channel of analog input. Do not use P1.0 or P1.6. What is the input range and polarity of the analog input? Set MCLK to 1 MHz. Write a program to convert this single channel to a 16-bit integer at a low rate determined by a delay loop. For a sinewave input spanning the full dynamic range of the ADC, display the two most significant bits of the data (bits 8 and 9) on the green and red LEDs. You should be able to see a slowly varying 2-bit display of the data.