Part Number: MSP430FR4133
Tool/software: Code Composer Studio
Hello,
This is one of the example code for analog to digital for msp430fr4133.
#include <msp430.h>
unsigned int adcResult; // Temporarily stores the ADC value
// that was read from ADCMEM0
int main(void)
{
volatile unsigned long dvccValue; // Calculated DVCC value
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
P1DIR |= BIT0; // Set P1.0 to output direction
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
// Configure ADC10
ADCCTL0 &= ~ADCENC; // Disable ADC
ADCCTL0 = ADCSHT_2 | ADCON; // ADCON, S&H=16 ADC clks
ADCCTL1 = ADCSHP; // ADCCLK = MODOSC; sampling timer
ADCCTL2 = ADCRES; // 10-bit conversion results
ADCIE = ADCIE0; // Enable ADC conv complete interrupt
ADCMCTL0 = ADCINCH_13 | ADCSREF_0; // A13 ADC input select = 1.5V Ref
// Vref = DVCC
// Configure reference module located in the PMM
PMMCTL0_H = PMMPW_H; // Unlock the PMM registers
PMMCTL2 |= INTREFEN; // Enable internal reference
while(!(PMMCTL2 & REFGENRDY)); // Poll till internal reference settles
while(1)
{
ADCCTL0 |= ADCENC | ADCSC; // Sampling and conversion start
__bis_SR_register(LPM0_bits | GIE); // Enter LPM0, ADC_ISR will force exit
__no_operation(); // For debug only
// To calculate DVCC, the following equation is used
// DVCC = (1023 * 1.5) / adcResult
// The following equation is modified to use only integers instead
// of using float. All results needs to be divided by 100 to obtain
// the final value.
// DVCC = (1023 * 150) / adcResult
dvccValue = ((unsigned long)1023 * (unsigned long)150) / (unsigned long) (adcResult);
if (dvccValue < 250) // DVCC > 2.50V?
P1OUT |= BIT0; // Set P1.0 LED on
else
P1OUT &= ~BIT0; // Clear P1.0 LED off
}
}
What I'm trying to understand is where do you equate the value of AnalogtoDigital conversion result to adcResult value which was first defined in the beginning of the code. Unsigned integer adcResult is only mentionend in the beginning of the code, and no where else.