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.

4 pin ADC read issues

Other Parts Discussed in Thread: MSP430G2553

I am trying to take an ADC reading on 4 of the analog pins on an MSP430G2553.  I want to take a single reading using Vcc as my reference voltage.  I am trying to take these readings on P1.0, P1.3, P1.4, and P1.5.  The issue I am having is that the readings on P1.3, P1.4, and P1.5 seem to be reading in correctly while the reading from P1.0 never moves.  It doesn't matter how much I change the voltage on the pin it just never changes.  I think this is an issue in my setup but this is my first adc project and I am unsure.  I have included my code.  Any help would be greatly appreciated.  

#include <msp430.h>

volatile unsigned int adc_read[10];

void main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

    BCSCTL1 = CALBC1_12MHZ;
    DCOCTL = CALDCO_12MHZ;
    BCSCTL2 |= DIVS_0;							// SMCLK = MCLK = 12Mhz
    BCSCTL3 |= LFXT1S_2;						// LFXT1 = VLO
	
	ConfigureADC();
	
	while(1){
    	ADC_Read();

    	volatile unsigned int pin_one_zero = adc_read[3];
    	volatile unsigned int pin_one_three = adc_read[2];
    	volatile unsigned int pin_one_four = adc_read[1];
    	volatile unsigned int pin_one_five = adc_read[0];

    	_nop();
    }	//while(1)
	
}	//main()


// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
   __bic_SR_register_on_exit(CPUOFF); // Return to active mode
}

void ConfigureADC(void) {
	/* Configure ADC Channel */
	P1SEL |= BIT0 + BIT3 + BIT4 + BIT5;
	ADC10CTL1 = INCH_5 + ADC10DIV_3 + CONSEQ_1 + SHS_0; // Channel 5, ADC10CLK/4
	ADC10CTL0 = SREF_0 + ADC10SHT_3 + MSC + ADC10ON + ADC10IE; //Vcc & Vss as reference
	ADC10DTC1 = 4;
	ADC10AE0 = BIT0 + BIT3 + BIT4 + BIT5; //P1.5 ADC option

}	//void ConfigureADC(void)

void ADC_Read(void) {
	delay_ms(20);	// Wait for ADC Ref to settle
	ADC10CTL0 &= ~ENC;
	while (ADC10CTL1 & BUSY);
	ADC10SA = (unsigned int)adc_read;
	ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
	__bis_SR_register(CPUOFF + GIE); // LPM0 with interrupts enabled
	_nop();
}	//void ADC_Read(void)

  • Hi Ryan,

    I think I see a possible problem.

    I see that you set the ADC10DTC1 = 4. This means that the DTC will transfer 4 times. You have CONSEQ_1 for sequence-of-channels mode, and you set INCH_5 as the highest channel in the conversion.

    With this setup, the ADC will first sample A5, then A4, A3, A2, A1, and finally A0 (P1.0). However you have the DTC set to do only 4 transfers - so the data you'll see in your adc_read array will really contain A5, A4, A3, A2. And that's it - it won't have A1 or A0. So if you are simply looking at the last/4th data transferred you are looking at A2 instead (not A0/P1.0), and you don't have A2/P1.2 set for ADC function.. 

    I would recommend trying to change your ADC10DTC1 register to be 6 instead so that you will transfer all data for A5 - A0. You'll need to increase the size of your adc_read array to make sure there's enough room for all of these. Your other code when you process the data output will then just need to know to ignore/throw away the A2 and A1 values because you are not using these channels/pins for ADC function. 

    Hope this helps,

    -Katie

  • Thanks for the response.  Making the change of ADC10DTC = 6 made it so that I get all the values I am looking for.  One other question, so in my case I plan to use P1.1 and P1.2 for the UART port.  Will taking this analog value across those pins cause any funky issues or will it be ok?  That is also the reason I don't have P1.2 set as an analog pin.  

  • Hi Ryan,

    Looking at the pin-muxing port schematic on p. 42 of www.ti.com/lit/gpn/msp430g2553 for Port P1.0-2, it looks like as long as you have kept ADC10AE0.y = 0 for these bits (which your code appears to do), then these external pins won't really be connected to the ADC. So I don't think you'll have any problem using these as UART pins as long as they're configured correctly.

    Regards,

    Katie

  • Excellent, thank you very much for the help.  

  • Unfortunately, you are wrong, Katie.

    On G2 devices, the moment the ADC samples an analog input channel, it deactivates the output driver on this channel. Independent of PxSEL or ADC10AEx. (those only permanently disable the digital output). IMHO a bad design decision. (else you could measure the output current of a digital pin by sampling the output voltage, in addition to the non-disturbance of the ‘skipped’ inputs in a sequence)

    In case of TxD (P1.2), this may cause a glitch in the transmitted signal. A possible solution would be a small capacitor (10 or 22nF) on this line, so the signal will be kept stable for the short time the output driver is off and the ADC input charges its sampling capacitor. THis will, however, perhaps limit the maximum baudrate or at least negatively affect the signal edges.

**Attention** This is a public forum