Analog IO Functions

Analog voltages are continuously variable voltages,  where as Digital voltages are either high or low. On the MSP430 microcontroller a digital signal low is 0v and a high is 3.3v (the supply voltage).

ADC is short for Analog to Digital Converter.  Some of the MSP430 microcontrollers contain an ADC which is used to convert an analog voltage on an input pin into a 10 bit integer number. This means the value will be a number between 0 and 1023 depending on the input voltage.  0 for 0v, to 1023 for a voltage of 3.3v (or  the supply voltage to the microcontroller).

Compare this to a regular input using the inp( ) which can only give a 0 or 1 digital value.

Not all MSP430 chips have an ADC. See here to see which chips have an ADC.

To use the ADC (if the chip has an ADC) you must first enable the ADC  using the adc_enable( ) command.

Then to read the voltage at an input pin use the  adc( pinname ) command.

Only one pin can be read at a time, but the pin can be any pin P1_0 through to P1_7. (This makes the ADC an 8 channel ADC as the input can come from one of 8 different input channels)

Example:

adc_enable()                           # Enable the ADC block
while 1:
   val = adc( P1_4 )                   # Use the ADC to convert voltage at pin P1_4 into a 10 bit number
   print( 'ADC P1_4 is:', val )
   wait( 1000 )

The ADC is also able to measure the chip temperature, and the chip supply voltage.