Hello, I have a lot of Doubts whit the next ADC example code
//******************************************************************************
// MSP432P401 Demo - ADC14, Sample A1, AVcc Ref, Set P1.0 if A1 > 0.5*AVcc
//
// Description: A single sample is made on A1 with reference to AVcc.
// Software sets ADC14SC to start sample and conversion - ADC14SC
// automatically cleared at EOC. ADC14 internal oscillator times sample (16x)
// and conversion. In Mainloop MSP432 waits in LPM0 to save power until ADC14
// conversion complete, ADC14_ISR will force exit from LPM0 in Mainloop on
// reti. If A0 > 0.5*AVcc, P1.0 set, else reset. The full, correct handling of
// and ADC14 interrupt is shown as well.
//
//
// MSP432p401rpz
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// >---|P5.4/A1 P1.0|-->LED
//
// Dung Dang
// Texas Instruments Inc.
// November 2013
// Built with Code Composer Studio V6.0
//******************************************************************************
#include "msp.h"
#include "stdint.h"
int main(void) {
volatile unsigned int i;
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
// GPIO Setup
P1OUT &= ~BIT0; // Clear LED to start
P1DIR |= BIT0; // Set P1.0/LED to output
P5SEL1 |= BIT4; // Configure P5.4 for ADC
P5SEL0 |= BIT4;
__enable_interrupt();
NVIC_ISER0 = 1 << ((INT_ADC14 - 16) & 31); // Enable ADC interrupt in NVIC module
// Configure ADC14
ADC14CTL0 = ADC14SHT0_2 | ADC14SHP | ADC14ON; // Sampling time, S&H=16, ADC14 on
ADC14CTL1 = ADC14RES_2; // Use sampling timer, 12-bit conversion results
ADC14MCTL0 |= ADC14INCH_1; // A1 ADC input select; Vref=AVCC
ADC14IER0 |= ADC14IE0; // Enable ADC conv complete interrupt
SCB_SCR &= ~SCB_SCR_SLEEPONEXIT; // Wake up on exit from ISR
while (1)
{
for (i = 20000; i > 0; i--); // Delay
ADC14CTL0 |= ADC14ENC | ADC14SC; // Start sampling/conversion
__sleep();
// __bis_SR_register(LPM0_bits | GIE); // LPM0, ADC14_ISR will force exit
__no_operation(); // For debugger
}
}
// ADC14 interrupt service routine
void ADC14IsrHandler(void) {
// ADC14CLRIFGR0 |= CLRADC14IFG0; //Attempt at clearing flag
if (ADC14MEM0 >= 0x7FF) // ADC12MEM0 = A1 > 0.5AVcc?
P1OUT |= BIT0; // P1.0 = 1
else
P1OUT &= ~BIT0; // P1.0 = 0
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1. At first in "ADC14CTL0 = ADC14SHT0_2 | ADC14SHP | ADC14ON; " I dont understand why ADC14SHT0 have a "_2", reading the Technical Reference Manual i have found that the values of this ADC14CTL0 register part should be at least 4 and maximum 192.
2. What ADC14SHP is for, what is S&H and why is it equal to 16.
3. Whit ADC14INCH I can enable more ADC channels at the same time???
4. The example use P5.4, but it but should not be P4.5???, because P4.5 is for ADC and P5.4 is reserved??
5. Why the exaple use an interruption to detect de analog variation? Could it be done in the default void???
Thanks
