SLAA475A October 2010 – March 2019 MSP430L092
The A-Pool is not limited to providing only one of the available functions in an application. The user can decide when to provide a specific function for the application. For this, the timers or a software-based solution can be used. The following code shows a simple A/D conversion and SVM monitoring with software triggers. The observed VCC voltage is 1.25 V, and the measured channel is A0 with 500-mV range.
#include "msp430l092.h"
unsigned char result;
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P1DIR |= BIT0; // Indicates VCC crosses SVM level
APVDIV |= A0DIV+VCCDIVEN; // Enable VCC divider
// Set 500mV input range
_BIS_SR(GIE); // Switch on global interrupts
APCNF = CMPON+DBON+CONVON+APREFON; // Enable comparator on +
// Enable DAC buffer +
// Enable conversion +
// Enable reference
APOMR |= CTEN; // Enable CTEN mode
APIE |= EOCIE; // Enable end of conversion interrupt
while(1)
{
APINT = 156; // Set voltage level 1250mV / 8 = 156mV
APCTL = APPSEL2+APPSEL1+APNSEL2+APNSEL0+OSEL;
// Set voltage divider to PSEL +
// Set DAC output to NSEL +
// Select output buffer
SFRIFG1 &=~ SVMIFG; // Clear SVM flag
APCNF |= CMPON; // Start comparison
if (SFRIFG1 & SVMIFG) // Check if SVM flag is set
{
P1OUT ^= BIT0; // Indicates VCC crosses SVM level
SFRIFG1 &=~ SVMIFG; // Clear SVM flag
}
APINT = 0x00; // Clear ADC-DAC-REG
APCTL = CBSTP+SBSTP+APPSEL0+APPSEL2+OSEL;
// Set DAC buffer output to PSEL +
// Select output buffer +
// Enable Comparator based stop +
// Enable Saturation based stop +
APCTL |= RUNSTOP; // Start conversion
_BIS_SR(LPM0); // Go to LPM0
}
}
#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: result = APINT; // Save value in variable
__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
break;
case 4: break;
case 6: break;
case 8: break;
default: break;
}
}