hi,
i would want that adc14 of msp432 start to sampling at time = 0 and finish to time 1000 microsecond. This is my part of code interested:
#define STEP 5
#define TIME_ON 50
#define TIME_ADC_START 0
#define TIME_OFF 250
#define TIME_ADC_END 1000
#define ADC_SPENTO 1010
#define TIME_SAVE 1200
#define TIME_RESET 10000
int microsecondi = 0;
int index_N = 0;
uint16_t values[16384];
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;}
void TA0_off() {TA0CCTL0 &= ~CCIE;}
P6SEL1 |= BIT1;
P6SEL0 |= BIT1; // Canale A14 (P6.1) configurato per ADC
//=============ADC14============
ADC14CTL0 &= ~ADC14ENC; //Turn off Enable. With few exceptions, the ADC14 control bits can only be modified when ADC14ENC = 0.
ADC14CTL0 = ADC14ON | ADC14SHP | ADC14CONSEQ_2; // Turn on ADC14, set sampling time, repeat single channel
ADC14CTL1 = ADC14RES__14BIT; // Use sampling timer, 14-bit conversion results
ADC14MCTL0 = ADC14VRSEL_0 | ADC14INCH_14; // A0 ADC input select; Vref=AVCC=3.3V
// ========== clock a 12 MHz==========
CSKEY = 0x695A; // Unlock CS module for register access
CSCTL0 = 0; // Reset tuning parameters
CSCTL0 = DCORSEL_3; // Set DCO to 12MHz (nominal, center of 8-16MHz range)
CSCTL1 = SELA_2 | SELS_3 | SELM_3; // Select ACLK = REFO, SMCLK = MCLK = DCO
CSKEY = 0; // Lock CS module from unintended accesses
// ==========Configurazione TimerA0==========
NVIC_ISER0 = 1 << ((INT_TA0_0 - 16) & 31); // Enable TA0_0 interrupt in NVIC module
TA0CCTL0 &= ~CCIFG; // Interrupt disable
TA0CCR0 = STEP; // Overflow (step dell'interrupt)
TA0CTL = TASSEL__SMCLK | MC__UP | ID_2; // SMCLK, UP mode, Divisione per 4 (12 MHz / 4 = 3 MHz)
TA0EX0 |= TAIDEX_2; // Divisione per 3 (3 MHz / 3 = 1 MHz)
// Timer A0 interrupt service routine
void TimerA0_0IsrHandler(void) {
TA0CCTL0 &= ~CCIFG;
/* STEP = 20 */
if(TIME_ADC_START < microsecondi <= TIME_ADC_END) {
ADC14CTL0 |= ADC14ENC | ADC14SC; // Start sampling/conversion; Enable and start conversion.
send(com_LOG, "...adc...\n");
while(!(ADC14IFGR0 & BIT0)); // Controlla che non abbia finito
values[index_N] = ADC14MEM0;
index_N++;
}
switch (microsecondi){
case TIME_ON:
IR_on();
send(com_LOG, "LED_ON\n");
break;
case TIME_OFF:
IR_off();
send(com_LOG, "LED_OFF\n");
break;
case ADC_SPENTO:
ADC14CTL0 &= ~ADC14CONSEQ_0;
ADC14CTL0 &= ~ADC14ENC;
break;
case TIME_SAVE:
send(com_LOG, "valori_inviati\n");
if (index_N >= N){
index_N = 0;
microsecondi = 0;
TA0_off();
led_off();
send_all_values();
}
default:
break;
}
microsecondi += STEP;
if (microsecondi >= TIME_RESET){
microsecondi = 0;
}
}
I don't know how stop conversion and sampling of adc14 because with this step it samples to 1200microsecond and doesn't stop at 1000