I'm new to the MSP430 and relatively new to C. I'm building a proejct which seems to be working fine except I can't change channels on the ADC. I know I'm doing somethign stupid but I can't see it. If I configure it for channel 4 and never try to change to 3, I get the result I expect from 4. If I configure it for 3, it never switches to 4.
In the following code, I always get the same answer for V_Bat and IGN. It appears the highlighted code doesn't change the channel.
Ideas???
while(1)
{
v_bat=v_bat_in();
ign=ign_in();
}
void ConfigADC10(void)
{
ADC10CTL0 &= ~ENC;
ADC10CTL0 = ADC10ON + REFON + REF2_5V + ADC10SHT_2 + SREF_1;
ADC10CTL1 = CONSEQ_0 + ADC10SSEL_0 + ADC10DIV_0 + SHS_0 + INCH_4;
ADC10AE0 = 0x6;
__delay_cycles(30000);
ADC10CTL0 |= ENC+ ADC10SC;
}
int ign_in(void) // read in and average ign
{
ign_total=0;
P1OUT |= green_led;
i=0;
ADC10CTL0 &= ~ENC; // disable adc during channel switch
ADC10CTL1 &= ~INCH_3; // Deselect channel 3
ADC10CTL1 |= INCH_4; // select channel 4
__delay_cycles(thirtyms);
while (i < loop_avg)
{
ADC10CTL0 |= ENC + ADC10SC; //start conversion
_delay_cycles(100); //wait for conversion to finish and delay
ADC10CTL0 &= ~ENC; //have to turn of enc before reading
ADC10CTL0 &= ~(REFON + ADC10ON);
tempRaw = ADC10MEM;
ign_total = ign_total+tempRaw;
i++;
}
ign=ign_total/(loop_avg*4);
P1OUT &= ~green_led;
return ign;
}
int v_bat_in(void) // read in and average vbat
{
v_bat_total=0;
P1OUT |= red_led;
i=0;
ADC10CTL0 &= ~ENC; // disable adc during channel switch
ADC10CTL1 &= ~INCH_4; // Deselect channel 4
ADC10CTL1 |= INCH_3; // select channel 3
__delay_cycles(thirtyms);
while (i < loop_avg)
{
ADC10CTL0 |= ENC + ADC10SC; //start conversion
_delay_cycles(100); //wait for conversion to finish and delay
ADC10CTL0 &= ~ENC; //have to turn of enc before reading
ADC10CTL0 &= ~(REFON + ADC10ON);
tempRaw = ADC10MEM;
v_bat_total = v_bat_total+tempRaw;
i++;
}
v_bat=v_bat_total/(loop_avg*4);
P1OUT &= ~red_led;
return v_bat;
}