This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
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
Hi Josue!
Josue Pareja said: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.
As you can see from the Technical Reference Manual, the setting ADC14SHT1_2 means a sample and hold time of 16 ADC14CLK cycles:
As you can see you have to look at this individual bit field. 0000 binary is 0 decimal which is _0. 0011 binary is 3 decimal is _3. And those settings cause a sample and hold time starting at a minimum of 4 and double with each step.
Josue Pareja said:What ADC14SHP is for, what is S&H and why is it equal to 16.
The required sample and hold time depends on your source impedance. 16 is just an example in this case. If you have no idea about S&H, you can read about it here:
Josue Pareja said:Whit ADC14INCH I can enable more ADC channels at the same time?
INCH selects the input channel you want to sample. There is a multiplexer inside the MSP432 which routes the input signal (A1, A2, A3, ...) to the ADC module. This multiplexer is controlled by the INCH setting:
Josue Pareja said:The example use P5.4, but it but should not be P4.5?
You could also use 4.5 - look at the pinout of the MSP432P401R:
Pin 5.4 is analog channel A1, pin 4.5 is analog channel A8. In this example A1 was chosen.
Josue Pareja said:because P4.5 is for ADC and P5.4 is reserved?
I don't know what you mean here.
Josue Pareja said:Why the exaple use an interruption to detect de analog variation? Could it be done in the default void?
Yes, you could also work without interrupts and poll for the ADC result, but using interrupts is always the way you should prefer, at least when the processor gets more to do than this single task of measuring one input. Using interrupts is simply the smartest way. But for a beginner, polling for the ADC result might be the easier way to start.
Dennis
Hi Dennis, thank you very much for your answer.
I would like to know if I can have 8 ADC o more working at the same time in this chip, Its for an acoustic aplication whit 8 or more microphones. It requires a minimun sample frecuency of 48000 Hz. Also I would like to use this kind of proyect to create a Data Adquisicion System for myself.
Thank you very much.
**Attention** This is a public forum