SLAA475A October 2010 – March 2019 MSP430L092
In addition to the ramp method, a SAR conversion is also implemented. Within 8 clock cycles, the SAR implementation reaches the measured value with an accuracy of 1 bit. The SAR logic does not compensate for any internal offsets of the A-Pool module. The following code shows the settings to use the SAR logic.
#include "msp430l092.h"
unsigned char result; // Result variable
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 reference
APVDIV = A0DIV; // Set 500mV input range
APIE |= EOCIE; // Enable end of conversion interrupt
APOMR |= SAREN; // Enable SAR logic
_BIS_SR(GIE); // Switch on global interrupts
APCTL = APPSEL0+APPSEL2+OSEL+RUNSTOP;
// Set DAC buffer output to PSEL +
// Select output buffer +
// 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
break;
case 4: break;
case 6: break;
case 8: break;
default: break;
}
}