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;
}