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.

msp432 adc14 clock divider

Hello, i have a question about adc14div_x of msp432. If we set DCO = 24Mhz and SMCLK = 12Mhz and this clock (smclk) is the source clock of adc14, then if i want to sample every 10 microsecond (it means that every 10us i want the value converted and in memory from adc14mem), so have i set the adc14 clock or set adc14div_x to give him the correct frequency??

an example of code could be:

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, select DCO as source then divide by 2
CSKEY = 0;                         // Lock CS module from unintended accesses

P6SEL1 |= BIT1;
P6SEL0 |= BIT1;    // adc pin

ADC14CTL0 &= ~ADC14ENC;	//Turn off Enable. With few exceptions, the ADC14 control bits can only be modified when ADC14ENC = 0.
ADC14CTL0 = ADC14ON | ADC14SHT0_5 | ADC14CONSEQ_2 | ADC14SSEL_4 | ADC14SHP | ADC14SHS_0;   // Turn on ADC14, set sampling time, repeat single channel (ssel = smclk)
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;
ADC14CTL0 |= ADC14ENC;   // ADC enable

In this case i have 96S&H cycles + 16Conversion(14 bit) --> 96+16/12Mhz = 9.3 us (<10us). Is it correct this?

I add that the start conversion is in Timer_A of msp432. In particulart the code is set as:

void TimerA0_0IsrHandler(void) {
TA0CCTL0 &= ~CCIFG;
if(microseconds > 0 && microseconds <= 1000) {
	ADC14CTL0 |= ADC14SC; // Start sampling/conversion; Enable and start conversion.
	values[index_N] = ADC14MEM0;	
	index_N++;	
}
[......]

Where microsecond is a variable that increments with timer_A (set to 1Mhz -> 1us)

Thanks

  • Hi Luca!

    Your approach looks more like you want to ensure that the conversion takes about 10µs with the side effect that there is a conversion each 10µs when having repeated sampling.

    A timer could trigger a new conversion every 10µs.

    Dennis
  • Using my example how can i make this? I'm not expert :( In my code I need to start conversion and finish on schedule. And I thought this was the most effective system so that I can be sure that ADC conversion is only between 50 and 1000 (or more times)
  • Hi Luca!

    Maybe you want to explain the desired functionality a little bit more in detail. What exactly shall happen? Do you need the long S&H time or was it just to extend the time to ~10µs?

    Dennis

  • I have a sensor that turn on and off a IR_led. In this period i want sampling with adc. So for example i start sampling from 0 to 1000 (while the led turn on at time 50 and turn off at time 450). All time are expressed in microsecond. My problem is sampling rate: i'm trying to find the right frequency of adc that determines the number of samples. For this i use a timer that counts. Every step (that i decide in variable STEP) i have a sample of adc.

    The comunication from msp and me is with a software written in python that send parameters and other commands.

    i hope this help you. Sorry if my english is not perfect. If you want i post my code here.

    3666.luca_code_01.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    #include "msp.h"
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    // ==========Definizione costanti==========
    typedef enum {false=0, true=1} bool; // definizione tipo bool
    // costanti dei tempi di acquisizione
    #define STEP 10 // 10 us tempo dell'interrupt
    #define TIME_ON 50 // 50 us led IR on, signal = 0 V
    #define TIME_ADC_START 0 // 0 us inizio istante di acquisizione
    #define TIME_OFF 450 // 450 us led IR off, signal = 3,3 V
    #define TIME_ADC_END 1000 // 1000 us fine istante di acquisizione
    #define TIME_SAVE 1200 // 1200 us controllo fine ciclo
    #define TIME_RESET 10000 // 10.000 us periodo del segnale generato
    // costanti comandi protocollo trasmissione seriale
    #define com_PING 'P' // ping
    #define com_T 'T' // parametro T (periodo in minuti)
    #define com_N 'N' // parametro N (numero campioni per periodo)
    #define com_UTC 'U' // sincronizzazione data/ora
    #define com_MODE 'A' // 0 (off) - 1 (auto) - 2 (manual)
    #define com_START 'S' // inizio acquisizione degli N valori
    #define com_RESET 'R' // provoca reset
    #define com_VALUE 'D' // invio di N valori
    #define com_END 'E' // fine invio valori
    #define com_LOG 'L' // stringa di log
    // ==========Dichiarazione variabili globali==========
    // parametri modificabili via seriale a run-time
    int T = 5; // min // Periodo globale di acquisizione [N/100/60 < T < 32767]
    int N = 100; // Numero di campioni memorizzati per periodo [ 1 < N < 16384]
    // variabili tempi
    int microsecondi = 0; // contatore di microsecondi del timer A0 [0 - 10.000]
    int minuti = 0; // contatore di minuti del Real Time Clock [0 - T]
    int secondi = 0; // contatore di secondi del Real Time Clock
    // indici contatori array
    int index_N = 0; // contatore campioni [0 - N]
    // variabili acquisizione
    uint16_t values[200]; // array che contiene tutti gli N valori di un periodo
    char micro[8];
    // variabili ricezione seriale
    char RXData[32]; // buffer che contiene la stringa ricevuta
    char RXByte; // ultimo byte ricevuto
    int index_RX; // indice del ciclo che riempie il buffer RXData
    // ==========Funzioni in/out==========
    void IR_off() {P4OUT |= BIT2;}
    void IR_on() {P4OUT &= ~BIT2;}
    void led_on() {P1OUT |= BIT0;}
    void led_off() {P1OUT &= ~BIT0;}
    void TA0_on() {TA0CCTL0 |= CCIE;}
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Scheme:

    | 0 adc start -- | 50 turn On led -- | 450 tunr Off led -- | 1000 adc end -- | send values -- | end cycle -- | ......... repeat cycle every 2 seconds (parameter)

**Attention** This is a public forum