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.

MSP430FR6989: ADC 12bit - Multichannel sampling periodically

Part Number: MSP430FR6989


Hello

I am trying to read from 4 ADC channels every 10 secs to gas sensors, temperature etc. The following is the code I am using.

void Init_ADC (void)
{
    REFCTL0 &= 0x00;
    ADC12CTL0 = ADC12ON | ADC12MSC | ADC12SHT0_8;
    ADC12CTL1 |= ADC12SHP + ADC12CONSEQ_1;
    ADC12CTL2 |= ADC12RES_2 + ADC12PWRMD;
    ADC12MCTL0 = ADC12VRSEL_4 + ADC12INCH_1; // A1 VeRef
    ADC12MCTL1 = ADC12VRSEL_4 + ADC12INCH_7; // A7 ADC
    ADC12MCTL2 = ADC12VRSEL_4 + ADC12INCH_6; // A6 ADC
    ADC12MCTL3 = ADC12VRSEL_4 + ADC12INCH_5; // A5 ADC
    ADC12MCTL4 = ADC12VRSEL_4 + ADC12INCH_4 + ADC12EOS; // A4 ADC
    ADC12CTL0 &= ~ADC12ENC;
    _delay_cycles(1000);
}

void Enable_ADC (void)
{
    while(ADC12CTL1 & ADC12BUSY);
    ADC12IER0 |= ADC12IE4;
    ADC12CTL0 |= ADC12ENC | ADC12SC;
}

void Disable_ADC (void)
{
    ADC12IER0 &= ~ADC12IE4;
    ADC12CTL0 &= ~(ADC12ENC | ADC12SC);
}

Should I disable the ADC and enable them every 10 seconds using a Timer or should just let the ADC run forever? I want to know which is a better approach.

1. ADC runs continuously and sends results like below in the ISR and then read in the timer every 10 seconds.

#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
    result1 = +=ADC12MEM1;
    result2 = +=ADC12MEM2;
    result3 = +=ADC12MEM3;
    result4 = +=ADC12MEM4;

    ADC_Flag = TRUE;
}

__interrupt void Timer0_A0_ISR (void)
{
    TA0CCR0 += 40960;                         // Add 10 Second Offset to TA0CCR0
    if(ADC_Flag == TRUE)
        myprintf("ADC1: %d, ADC2: %d, ADC3: %d, ADC3: %d\n", result1, result2, result3, result4); // print to uart
}

2. The ADC is enabled every 10 secs through Timer and disabled after reading.

#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
    result1 = +=ADC12MEM0;
    result2 = +=ADC12MEM0;
    result3 = +=ADC12MEM0;
    result4 = +=ADC12MEM0;

    Disable_ADC();
    ADC_Flag == TRUE
    __bic_SR_register_on_exit(LPM0_bits | GIE);
}

__interrupt void Timer0_A0_ISR (void)
{
    TA0CCR0 += 40960;                         // Add 10 Second Offset to TA0CCR0
    Enable_ADC();
}

int main (void)
{
    __bis_SR_register(LPM0_bits | GIE);
    if(ADC_Flag == TRUE)
        myprintf("ADC1: %d, ADC2: %d, ADC3: %d, ADC3: %d\n", result1, result2, result3, result4); // print to uart

}

I am not an engineer or an experienced programmer. So please try to explain in detail. Also please let me know if the ADC configuration is correct.

**Attention** This is a public forum