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.

MSP430F5325: I want to select 2 input channels by adc12, but one channel is not work.

Part Number: MSP430F5325

code:

void AdcInit(void)
{
    ADC12CTL0 = ADC12SHT02 + ADC12ON;         // Sampling time, ADC12 on
    ADC12CTL1 = ADC12SHP;                     // Use sampling timer
    ADC12MCTL0 = ADC12INCH_2;                  // select input channel 2
    ADC12MCTL1 = ADC12INCH_3 | ADC12EOS;      // select input channel 3
    ADC12IE = ADC12IE0;                       // Enable interrupt
    ADC12CTL0 |= ADC12ENC;
    P6SEL |= BIT2 | BIT3;                     // P6.0 ADC option select
}

#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
    uint16                      nTemp;

    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:                                  // Vector  6:  ADC12IFG0
        nTemp                   = ADC12MEM0;
        TraceLog("ADC12MEM0 = %d\n", nTemp);

        nTemp                   = ADC12MEM1;
        TraceLog("ADC12MEM1 = %d\n", nTemp);

        __bic_SR_register_on_exit(LPM0_bits);   // Exit active CPU
        break;
    case  8:                                  // Vector  8:  ADC12IFG1
        break;
    default: break;
    }
}

p6.2 is successed, but P6,3 is failed ADC12MEM1is zero. but P6.3 voltage is 3.3V

  • >   ADC12CTL0 = ADC12SHT02 + ADC12ON;         // Sampling time, ADC12 on

    >  ADC12CTL1 = ADC12SHP;                     // Use sampling timer

    This sets CONSEQ=0, which is single-conversion. For this case you need CONSEQ=1 (sequence) and MSC=1 (single trigger for sequence). Try:

    >   ADC12CTL0 = ADC12SHT02 +  ADC12MSC + ADC12ON;         // Sampling time, whole-sequence, ADC12 on.

    >  ADC12CTL1 = ADC12SHP + ADC12CONSEQ_1;                     // Use sampling timer, sequence-of-channels

    ------------------

    Unsolicited: You're indicating completion after the first channel is done, and so (potentially) before the second channel is done.  If TraceLog() takes a long time, this might work by accident, but it's likely to cause trouble later. I suggest:

    >    ADC12IE = ADC12IE1;                       // Enable interrupt after second channel is complete

    then in the ISR use:

    >     case  8:                                  // Vector  8:  ADC12IFG1
     

  • thank you very much.

**Attention** This is a public forum