The ADC10 has two main control registers ADC10CTL0 and ADC10CTL1, and two analog input enable registers ADC10AE0 and ADC10AE1 (10bit ADC Analog Enable 0/1). These registers control all the timing and conversion aspects of the ADC.
In the first control register (ADC10CTL0), we only need to change two parameters,
-
ADC10SHTx--10bit ADC Sample Hold Time-- a higher value means each sample will be held for a longer period of time. We want to set this at the max value of
ADC10SHT_3 .
-
ADC10ON--10bit ADC ON/OFF--setting this bit to "1" (denoted by the label
ADC10ON) turns on the ADC, a vital step to performing any conversion!
To actually do this in C, just use addition and an equals sign:
ADC10CTL0 = ADC10SHT_3 + ADC10ON ;
In the second control register (ADC10CTL1), we want to again set two parameters, but we will need to use 4 alias labels instead of just two.
- ADC10DIVx--10bit ADC clock Divider bit x-- for "more flexibility", you set each bit individually in the three bit ADC10DIVx section of the register. Since we want the maximum divider, we will set all the bits.
Since some of the bit labeling is inconsistent (ADC10DIV is bit-wise while ADC10SHT is not), it is always good to examine the header file for a controller to see how its aliases are defined before using them in your code.
- INCHx--Input Channel #-- this 4 bit section determines which of the possible input channels the ADC will actually convert in single convert mode. In series mode, this determines the highest channel to be converted in the series (all channels below this number will also be converted).
ADC10CTL1 = ADC10DIV0 + ADC10DIV1 + ADC10DIV2 + INCH_X;
Lastly, the ADC10 has the ADC10AE0/1 registers that enable analog input on the different pins. These act as gates to prevent leakage current from flowing from a pin set as an output through the ADC to ground-- a substantial waste of power. To enable the ADC for your desired GPIO pin, just set the corresponding bit in ADC10AE0 to "1".
For more info about the ADC10's configuration options, see the MSP430 manual starting on page 609.