Forums

msp432 adc sampling rate

Started by luca89 3 years ago2 replieslatest reply 3 years ago948 views

Hi all, i have some problems with my msp432 (#MSP430) and adc14. 

I want to have a sample every 5 microseconds. So i have set smclk = 1Mhz (dco = 24Mhz and then divided) and ta0ccr0 = 5 so that every interrupt i should have a sample. Furthermore i have set adc14 clock = smclk (ADC14SSEL_4) and clock cycles (32 cycles sh + 16 cycles conversion --> 32+16 / 12 = 4 < 5us).

Is correct this reasoning? I post a part of my code:

Thanks for help.

Luca

// ==========Configuration clock 24Mhz - Smclk 12Mhz==========
CSKEY = 0x695A;                    // Unlock CS module for register access
CSCTL0 = 0;                        // Reset tuning parameters
CSCTL0 = DCORSEL_4;                // Set DCO to 24MHz
CSCTL1 = CSCTL1 & ~(SELS_M | DIVS_M); // Clear existing registers
CSCTL1 = CSCTL1 | (SELS_3 | DIVS_1); // For SMCLK = 12Mhz, select DCO as source then divide by 2
CSKEY = 0;                         // Lock CS module from unintended accesses

// ==========Configurazione ADC 14 bit (24Mhz)==========
P6SEL1 |= BIT1
P6SEL0 |= BIT1;    // p1.6 ad
<span></span>ADC14CTL0 &= ~ADC14ENC;  //Turn off Enable. With few exceptions, the ADC14 control bits can only be modified when ADC14ENC = 0
<span></span>ADC14CTL0 = ADC14ON | ADC14SHT0_3 | ADC14CONSEQ_2 | ADC14SSEL_4 | ADC14SHP | ADC14SHS_0;   // Turn on ADC14, set sampling time (SH = 32), repeat single channel (ssel = smclk), adc14sc start
<span></span>ADC14CTL1 = ADC14RES__14BIT;                      // Use sampling timer, 14-bit conversion results (16 clock cycles)
ADC14MCTL0 = ADC14VRSEL_0 | ADC14INCH_14;         // A0 ADC input select; Vref=AVCC=3.3V
ADC14IER0 |= ADC14IE0;
<span></span>ADC14CTL0 |= ADC14ENC;                          // ADC enable

// ==========Configurazione TimerA0==========
NVIC_ISER0 = 1 << ((INT_TA0_0 - 16) & 31);  // Enable TA0_0 interrupt in NVIC module
TA0CCTL0 &= ~CCIFG;                         // Interrupt disable
TA0CCR0 = 5;                                // Overflow (step dell'interrupt)
TA0CTL = TASSEL__SMCLK | MC__UP | ID_2;     // SMCLK, UP mode, division 4 (12 MHz / 4 = 3 MHz)
TA0EX0 |= TAIDEX_2;                         // division 3 (3 MHz / 3 = 1 MHz)

// ==========Timer A0 interrupt service routin==========
void TimerA0_0IsrHandler(void) {
TA0CCTL0 &= ~CCIFG;
// I want adc sampling only in this period (0-1000). Every 5us i have time to have sample
if(microsecondi > 0 && microsecondi <= 1000) {
    ADC14CTL0 |= ADC14SC; // Start conversion;
    values[index_N] = ADC14MEM0;
    index_N++;
}
microsecondi += STEP;
// There is a rtc that repeat this cycle (this works)
if (microsecondi >= 10000){
    microsecondi = 0;
}

        
[ - ]
Reply by stephanebSeptember 6, 2016

Hey Luca, if you tell a little more about what you mean by 'some problems', you stand more chances to receive help from other members.

[ - ]
Reply by luca89September 7, 2016

ok :) 

1)i would like to know if this method to have a sample every ~5us is correct because having adc14clock = 12Mhz, Cycles&h= 32 and Cycleconversion = 16 the total time to have adc sample is 4us. But if i use Cycles&h = 64 i have time > 5us. (interrupt routine). 

2)i would like to know if start conversion with timerA, memorize the values of adc and assure that conversion is only from 0 to 1000 (values of microseconds in TimerA) is correct.

Thanks