Quantcast
Channel: MSP 低功耗微控制器论坛 - 最近的话题
Viewing all articles
Browse latest Browse all 3634

MSP430FR5739的ADC多通道单次采样问题

$
0
0

程序是在官方的MSP430FR57xx_adc10_10.c  ----ADC10, DMA Sample A2-0, 8-bit Res, Single Sequence, DCO上做了一点点的修改的。原官方的程序能正常运行,我想使用中断的方式读取ADC转换的数据,发现不能正常运行。

程序在仿真的时候只触发了一次中断,不会自动切换到下一通道。看寄存器的值,符合切换 ADC10MSC=1 、 ADC10SHP=1 、x!=0 的条件,但是程序就是不会再触发ADC的中断。

程序:

#include <msp430.h>

unsigned int ADC_Result[3];                                    //  ADC conversion result array
unsigned char i;


int main(void)
{

  WDTCTL = WDTPW+WDTHOLD;                   // Stop WDT


  P3DIR |= BIT5 +BIT6 + BIT7;                            // Set LEDs to output
  P3OUT |= BIT5 +BIT6 + BIT7;

  // Configure ADC pins
  P1SEL0 |= BIT0 + BIT1 + BIT2;
  P1SEL1 |= BIT0 + BIT1 + BIT2;
  // Configure ADC10
  ADC10CTL0 = ADC10SHT_2 + ADC10MSC + ADC10ON;// 16ADCclks, MSC, ADC ON
  ADC10CTL1 = ADC10SHP + ADC10CONSEQ_1;     // sampling timer, s/w trig.,single sequence
  ADC10MCTL0 =ADC10INCH_2;                 // A0,A1,A2(EoS), AVCC reference
  ADC10IE |= ADC10IE0;                     // Enable ADC conv complete interrupt


  for (;;)
  {
    i = 2;

    while (ADC10CTL1 & BUSY);               // Wait if ADC10 core is active
    ADC10CTL0 |= ADC10ENC + ADC10SC;        // Sampling and conversion start

    __bis_SR_register(CPUOFF + GIE);        // LPM0, ADC10_ISR will force exit

    if (ADC_Result[0] < 0x1FF)
      P3OUT &= ~BIT5;                       // Clear  LED off
    else
      P3OUT |= BIT5;                        // Set  LED on

    if (ADC_Result[1] < 0x1FF)
      P3OUT &= ~BIT6;                       // Clear  LED off
    else
      P3OUT |= BIT6;                        // Set  LED on

    if (ADC_Result[2] < 0x1FF)
      P3OUT &= ~BIT7;                       // Clear  LED off
    else
      P3OUT |= BIT7;                        // Set LED on
  }
}

// ADC10 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC10_VECTOR))) ADC10_ISR (void)
#else
#error Compiler not supported!
#endif
{
  switch(__even_in_range(ADC10IV,12))
  {
    case  0: break;                          // No interrupt
    case  2: break;                          // conversion result overflow
    case  4: break;                          // conversion time overflow
    case  6: break;                          // ADC10HI
    case  8: break;                          // ADC10LO
    case 10: break;                          // ADC10IN
    case 12:

        ADC_Result[i] = ADC10MEM0;
        if(i == 0)
        {
            __bic_SR_register_on_exit(CPUOFF);
        }
        else
        {
            i--;
        }

             break;

    default: break;
  }
}


Viewing all articles
Browse latest Browse all 3634

Trending Articles