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.

CCS/MSP430FR2311: ADC Interrupt Service Routine

Part Number: MSP430FR2311

 
void initADC(void){
    // Configure ADC10
       ADCCTL0 |= ADCSHT_7 | ADCON;               // ADC Sample and Hold Time = 192 cycles, ADC on bit set
       ADCCTL1 |= ADCSHP  | ADCCONSEQ_1;             //Sample and Hold pulse mode select,  Clk = ACLK
       ADCCTL2 |= ADCRES;                          //10 - bit Resolution
       ADCIE   |= ADCIE0;                          //Interrupt Enable
       ADCMCTL0|= ADCINCH_0 + ADCINCH_1 + ADCINCH_3| ADCSREF_1;      

       PMMCTL0_H = PMMPW_H;                        // Unlock the PMM registers
       PMMCTL2 |= INTREFEN_0;                      // disable internal reference
       __delay_cycles(10);                        // Delay for reference settling
}






// ADC interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC_VECTOR
__interrupt void ADC_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC_VECTOR))) ADC_ISR (void)
#else
#error Compiler not supported!
#endif
{
    switch(__even_in_range(ADCIV,ADCIV_ADCIFG))
    {
        case ADCIV_NONE:
            break;
        case ADCIV_ADCOVIFG:
            break;
        case ADCIV_ADCTOVIFG:
            break;
        case ADCIV_ADCHIIFG:
            break;
        case ADCIV_ADCLOIFG:
            break;
        case ADCIV_ADCINIFG:
            break;
        case ADCIV_ADCIFG: // ch 5
            ADC_SM[Index] = ADCMEM0;
            done =0;
            Index++;
            loop = 1;
             if(Index >= 50)
              {
                Index = 0;
                loop = 0;
                done = 1;
            //   __bic_SR_register_on_exit(LPM0_bits);             // Exit LPM0
               __no_operation();
                        }
            break;
        default:
            break;
    }
}

I'm trying to get ADC readings from A0, A1, and A3 and I can't figure out which channels this corresponds to in the ADC service routine. Here is my interrupt routine, and my ADC set up to read from either different channels or the same channel. I just need to be able to differentiate which pin I am getting it from.Thanks.


Tool/software: Code Composer Studio

  • > ADCMCTL0|= ADCINCH_0 + ADCINCH_1 + ADCINCH_3| ADCSREF_1;
    ADCINCH isn't a bit vector, it's an integer. It indicates the (starting) channel number to count down from. If (with CONSEQ=1) you set ADCINCH_4, it will sample 4,3,2,1,0 in that order (see also SLAU445G Fig 20-11).

    If you read the ADCINCH field, it indicates the "current" channel number, but that really means (with CONSEQ=1) the channel it will do next (the "x" value in Fig 20-11). You can add 1 to this (modulo (4+1) for ADCINCH_4) to get the channel corresponding to the sample in ADCMEM0. (It's also possible to count modulo (4+1) in a separate index variable, but if you ever miss one you'll be off-by-1 forever.)
  • Small mistake above: I was thinking of CONSEQ=3; for CONSEQ=1 if ADCINCH reads as 0 that's ambiguous.

    I suggest you use CONSEQ=3 (SLAU445G Fig 20-15). With MSC=0 (which I recommend anyway for the FR2x ADC) it will act pretty much like CONSEQ=1, without the ADCINCH ambiguity.

**Attention** This is a public forum