SLAA475A October 2010 – March 2019 MSP430L092
If the voltage range of the input voltage is known, the ADC can also be used in a windowed mode. The counting of the ADC starts at a specific value and decreases the runtime of the ADC. For a comparison of the conversion methods, see Section 2.6.4. For an input voltage in a range of 250 mV to 500 mV, the following code can be used.
#include "msp430l092.h"
unsigned char result;
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
APCNF = CMPON+DBON+CONVON+APREFON; // Enable comparator on +
// Enable DAC buffer +
// Enable conversion +
// Enable reverence
APVDIV = A0DIV; // Set 500mV input range
APINT = 0x80; // Start measurement at 250mV
APIE |= EOCIE; // Enable end of conversion interrupt
_BIS_SR(GIE); // Switch on global interrupts
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
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: 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;
}
}