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/MSP430FR6989: Multi-channel ADC with repeated sequence

Part Number: MSP430FR6989

Tool/software: Code Composer Studio

Hi

I am trying to read from 12bit ADC A4, A5, A6, A7 using the the TI example MSP430F55xx_adc_06.c making few changes but the program seems to get stuck at __bis_SR_register(GIE). Below is the code.


#include <msp430fr6989.h>
#define   Num_of_Results   8

volatile unsigned int A0results[Num_of_Results];
volatile unsigned int A1results[Num_of_Results];
volatile unsigned int A2results[Num_of_Results];
volatile unsigned int A3results[Num_of_Results];

void main(void)
{
  WDTCTL = WDTPW+WDTHOLD;                   // Stop watchdog timer
  P8SEL0 = 0x0F;
  P8SEL1 = 0x0F;                            // Enable A/D channel inputs
  ADC12CTL0 = ADC12ON+ADC12MSC+ADC12SHT0_8; // Turn on ADC12, extend sampling time
                                            // to avoid overflow of results
  ADC12CTL1 = ADC12SHP+ADC12CONSEQ_3;       // Use sampling timer, repeated sequence
  ADC12MCTL0 = ADC12INCH_4;                 // ref+=AVcc, channel = A0
  ADC12MCTL1 = ADC12INCH_5;                 // ref+=AVcc, channel = A1
  ADC12MCTL2 = ADC12INCH_6;                 // ref+=AVcc, channel = A2
  ADC12MCTL3 = ADC12INCH_7+ADC12EOS;        // ref+=AVcc, channel = A3, end seq.
  ADC12IFGR0 = 0x08;                           // Enable ADC12IFG.3
  ADC12CTL0 |= ADC12ENC;                    // Enable conversions
  ADC12CTL0 |= ADC12SC;                     // Start convn - software trigger

  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, Enable interrupts
  __no_operation();                         // For debugger

}

#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
  static unsigned int index = 0;

  switch(__even_in_range(ADC12IV,34))
  {
  case  0: break;                           // Vector  0:  No interrupt
  case  2: break;                           // Vector  2:  ADC overflow
  case  4: break;                           // Vector  4:  ADC timing overflow
  case  6: break;                           // Vector  6:  ADC12IFG0
  case  8: break;                           // Vector  8:  ADC12IFG1
  case 10: break;                           // Vector 10:  ADC12IFG2
  case 12:                                  // Vector 12:  ADC12IFG3
    A0results[index] = ADC12MEM0;           // Move A0 results, IFG is cleared
    A1results[index] = ADC12MEM1;           // Move A1 results, IFG is cleared
    A2results[index] = ADC12MEM2;           // Move A2 results, IFG is cleared
    A3results[index] = ADC12MEM3;           // Move A3 results, IFG is cleared
    index++;                                // Increment results index, modulo; Set Breakpoint1 here

    if (index == 8)
    {
      (index = 0);
    }
  case 14: break;                           // Vector 14:  ADC12IFG4
  case 16: break;                           // Vector 16:  ADC12IFG5
  case 18: break;                           // Vector 18:  ADC12IFG6
  case 20: break;                           // Vector 20:  ADC12IFG7
  case 22: break;                           // Vector 22:  ADC12IFG8
  case 24: break;                           // Vector 24:  ADC12IFG9
  case 26: break;                           // Vector 26:  ADC12IFG10
  case 28: break;                           // Vector 28:  ADC12IFG11
  case 30: break;                           // Vector 30:  ADC12IFG12
  case 32: break;                           // Vector 32:  ADC12IFG13
  case 34: break;                           // Vector 34:  ADC12IFG14
  default: break;
  }
}

  • Hi

    I made the following changes and got it to work with external Vref of 2.048V. But now the readings from the adc pins are varying greatly.

    #include <msp430fr6989.h>
    
    volatile int A4results;
    volatile int A5results;
    volatile int A6results;
    volatile int A7results;
    
    void main(void)
    {
      WDTCTL = WDTPW+WDTHOLD;                   // Stop watchdog timer
      P8SEL0 = 0x0F;
      P8SEL1 = 0x0F;                            // Enable A/D channel inputs
      ADC12CTL0 = ADC12ON+ADC12MSC+ADC12SHT0_8; // Turn on ADC12, extend sampling time
                                                // to avoid overflow of results
      ADC12CTL1 = ADC12SHP+ADC12CONSEQ_3;       // Use sampling timer, repeated sequence
      ADC12MCTL0 = ADC12VRSEL_4 + ADC12INCH_4;                 // ref+=AVcc, channel = A0
      ADC12MCTL1 = ADC12VRSEL_4 + ADC12INCH_5;                 // ref+=AVcc, channel = A1
      ADC12MCTL2 = ADC12VRSEL_4 + ADC12INCH_6;                 // ref+=AVcc, channel = A2
      ADC12MCTL3 = ADC12VRSEL_4 + ADC12INCH_7 + ADC12EOS;        // ref+=AVcc, channel = A3, end seq.
      ADC12IFGR0 = 0x08;                           // Enable ADC12IFG.3
      ADC12CTL0 |= ADC12ENC;                    // Enable conversions
      ADC12CTL0 |= ADC12SC;                     // Start convn - software trigger
    
      while(1)
      {
          while (!(ADC12IFGR0 & ADC12IFG3));
          A4results = ADC12MEM0;
          A5results = ADC12MEM1;
          A6results = ADC12MEM2;
          A7results = ADC12MEM3;
    }

    }

    OUTPUT

    A4: 109
    A5: 63
    A6: 74
    A7: 55
    A4: 0
    A5: 0
    A6: 0
    A7: 0
    A4: 20
    A5: 24
    A6: 20
    A7: 22
    A4: 0
    A5: 22
    A6: 2
    A7: 21
    A4: 103
    A5: 67
    A6: 66
    A7: 57
    A4: 45
    A5: 30
    A6: 27
    A7: 25
    A4: 0
    A5: 0
    A6: 0
    A7: 0
    A4: 0
    A5: 0
    A6: 0
    A7: 6
    A4: 114
    A5: 63
    A6: 55
    A7: 53
    A4: 118
    A5: 67
    A6: 71
    A7: 53
    A4: 0
    A5: 0
    A6: 0
    A7: 0
    A4: 0
    A5: 0
    A6: 0
    A7: 9
    A4: 75
    A5: 43
    A6: 39
    A7: 40

  • Hi Vijay,
    This topic is best discussed with the experts in the MSP forums. I will move it there.

    Thanks
    ki
  • A7 through A4 are on pins 8.4 through 8.7, respectively, therefore P8SEL[0&1] should be 0xF0. Then you might at least be sampling from the correct channels. The first code example does not work since you should not be setting ADC12IFG0 as these are the flag bits, ADC12IER0 should be set for ADC12IE3.

    Regards,
    Ryan

**Attention** This is a public forum