SLAA475A October 2010 – March 2019 MSP430L092
The A-Pool can sample up to four external analog voltages with individual voltage dividers for each input channel. The conversions are done sequentially, and the user applications must select the sample channel. The APINTB register can be used to save the last sampled value during the conversion of the next channel.
The following code shows the sample of three channels (A0 to A2) with different input dividers.
#include "msp430l092.h"
unsigned char result[3]; // result array
unsigned char i = 0; // counting variable
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
APCNF = CMPON+DBON+CONVON+APREFON+EOCBU;
// Enable comparator on +
// Enable DAC buffer +
// Enable conversion +
// Enable reference +
// Enable EOC buffer
APVDIV = A0DIV+A1DIV+A2DIV0; // Set A0 to 500mV input range
// Set A1 to 500mV input range
// Set A2 to 1V input range
APINT = 0x00; // Clear ADC-DAC-REG
APIE |= EOCIE; // Enable end of conversion interrupt
_BIS_SR(GIE); // Switch on global interrupts
APCTL = APPSEL0+APPSEL2+OSEL+CBSTP+SBSTP;
// Set DAC buffer output to PSEL +
// Set A0 to NSEL +
// Select output buffer +
// Enable Comparator based stop +
// Enable Saturation based stop +
APCTL |= RUNSTOP; // Start conversion
_BIS_SR(LPM0); // Go to LPM0
APINT = 0x00; // clear ADC-DAC-REG
APCTL = APPSEL0+APPSEL2+APNSEL0+OSEL+CBSTP+SBSTP;
// Set DAC buffer output to PSEL +
// Set A1 to NSEL +
// Select output buffer +
// Enable Comparator based stop +
// Enable Saturation based stop +
// Inverted comparator output is used +
result[0] = APINTB; // Save first value
APCTL |= RUNSTOP; // Start conversion
_BIS_SR(LPM0); // Go to LPM0
APINT = 0x00; // clear ADC-DAC-REG
APCTL = APPSEL0+APPSEL2+APNSEL1+OSEL+CBSTP+SBSTP;
// Set DAC buffer output to PSEL +
// Set A1 to NSEL +
// Select output buffer +
// Enable Comparator based stop +
// Enable Saturation based stop +
// Inverted comparator output is used +
result[1] = APINTB; // Save second value
APCTL |= RUNSTOP; // Start conversion
_BIS_SR(LPM0); // Go to LPM0
result[2] = APINTB; // Save third value
APCTL |= RUNSTOP; // Start conversion
_BIS_SR(LPM0); // Go to LPM0
asm("nop");
while(1);
}
#pragma vector=APOOL_VECTOR // A-Pool interrupt service routine
__interrupt void APOOL_ISR(void)
{
switch(__even_in_range(APIV,8)) // Add offset to PC and delete flag
{
case 0: break;
case 2: __bic_SR_register_on_exit(CPUOFF); // Exit LPM0
break;
case 4: break;
case 6: break;
case 8: break;
default: break;
}
}