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.

MSP430G2553: ADC change INCH_x in ISR of ADC

Part Number: MSP430G2553


I write a program, which is supposed to digitize a signal coming from A6 (Pin 1.6). After 90 samples I want to check the battery status. To do so I change the INCH_x to A7 (Pin 1.7).

My problem: after the the ADC was stopped (reset ENC and ADC10SC), INCH_x changed to A7 and restart (setting ENC and ADC10SC), the ADC is not triggered anymore. I debugged the programme and the first conversion of the pin 1.7 works just fine. But after that the ISR is never entered again.

Here is my code:

#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void){
    counterISR++;
    //standard conversion
    if(counterISR < 90){
        tempRaw = ADC10MEM;
        serial_write_int(tempRaw);
    }
    //send data and change input channel of ADC
    else if(counterISR == 90){
        tempRaw = ADC10MEM;
        serial_write_int(tempRaw);
        stoppADC();
        ADC10CTL1 = INCH_7;
        startADC();
    }
    //no data sent, just add up values
    else if(90 < counterISR && counterISR < 100){
        tempRaw = ADC10MEM;
        batteryLevel += tempRaw;
    }
    else if(counterISR == 100){
        tempRaw = ADC10MEM;
        batteryLevel += tempRaw;
        int batAverage = batteryLevel / 10;
        serialWrite('!');
        serialWrite('!');
        serial_write_int(batAverage);
        stoppADC();
        ADC10CTL1 = INCH_6;
        startADC();
        counterISR = 0;
    }
}

void startADC(void){
    ADC10CTL0 |= ENC + ADC10SC;
}

void stoppADC(void){
    ADC10CTL0 &= ~ENC;
    ADC10CTL0 &= ~ADC10SC;
}

void configADC(void){
    P1SEL = BIT6 + BIT7;
    ADC10CTL0 = 0;
    ADC10CTL0 = ADC10SHT_3 + SREF_1 + REFON + ADC10ON + ADC10IE;
    ADC10CTL1 = INCH_6 + SHS1 + CONSEQ1;
    ADC10AE0 = BIT6 + BIT7;
}
  • Hi Markus,

    if you stop the ADC and change the Channel, you also have to set the sequence like in your configADC.

    ADC10CTL1 = INCH_6 + SHS1 + CONSEQ1;

    ADC10CTL1 = INCH_7 + SHS1 + CONSEQ1;

    Please try to change your ISR accordingly.

  • I just found a different solution to my problem:

    When I assigned the new channel my code was overriding the whole register:

    ADC10CTL1 = INCH_7;

    Instead I have to reset the channel and set only the bits storing the Channel:

    ADC10CTL1 &= ~INCH_15;

    ADC10CTL1 |= INCH_7;

    I tried your suggestion as well, but still get the same error.

**Attention** This is a public forum