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.

  • Resolved

MSP-EXP430G2: When changing the ADC channel, the input cannot be read correctly

Expert 2950 points

Replies: 3

Views: 208

Part Number: MSP-EXP430G2

Hello, I was trying to modify the ADC - ACLK source example from TI (msp430g2x33_adc10_11).

I have soldered the 32kHz crystal on my MSP-EXP430G2 launchpad.

#include <msp430.h>

void init(){
    ADC10CTL1 = SHS_1 + CONSEQ_2 + INCH_3; // TA1 trigger sample start
    ADC10CTL0 = SREF_0 + ADC10SHT_2 + ADC10ON + ADC10IE +MSC;
    __enable_interrupt(); // Enable interrupts.
    TACCR0 = 30; // Delay to allow Ref to settle
    TACCTL0 |= CCIE; // Compare-mode interrupt.
    TACTL = TASSEL_2 + MC_1; // TACLK = SMCLK, Up mode.
    LPM0; // Wait for delay.
    TACCTL0 &= ~CCIE; // Disable timer Interrupt
    __disable_interrupt();
    ADC10CTL0 |= ENC + ADC10SC; // ADC10 Enable
    ADC10AE0 |= BIT3; // P1.3 ADC10 option select

    P1DIR |= 0x01; // Set P1.0 output

    TACCR0 = 5-1; // Sampling Period 6553.6 Hz
    TACCTL1 = OUTMOD_3; // TACCR1 set/reset
    TACCR1 = 4; // TACCR1 PWM Duty Cycle
    TACTL = TASSEL_1 + MC_1; // ACLK, up mode
}

int main(void)
{
    WDTCTL = WDTPW + WDTHOLD; //Stop WDT
    if(CALBC1_1MHZ==0xFF) {
        while(1);
    }
    DCOCTL = 0;
    BCSCTL1 = CALBC1_1MHZ; // Set DCO
    DCOCTL = CALDCO_1MHZ;
    init();
    __bis_SR_register(LPM3_bits + GIE); // Enter LPM0, interrupts enabled
}

// ADC10 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(ADC10_VECTOR))) ADC10_ISR (void)
#else
#error Compiler not supported!
#endif
{
  if (ADC10MEM < 0x155)                     // ADC10MEM = A1 > 0.5V?
    P1OUT &= ~0x01;                         // Clear P1.0 LED off
  else
    P1OUT |= 0x01;                          // Set P1.0 LED on
}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_A0_VECTOR
__interrupt void ta0_isr(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) ta0_isr (void)
#else
#error Compiler not supported!
#endif
{
  TACTL = 0;
  LPM0_EXIT;                                // Exit LPM0 on return
}

I hope I'm on the correct track;

I wanted to set the sampling frequency approximately 6553 Hz so I can send some data via UART which will use a 115200 baud rate.

Because I will be using UART which occupies P1.1, I wanted to use P1.3 (A3, INCH3) as my ADC input.

When trying the original example (using P1.1), it read the input signal correctly.

However, the P1.3 couldn't read the ADC input (a function generator's 2Hz min=0V, max=1.5V sine wave) and it shows a saturated (a digital value close to the reference voltage) value.

This happens whether P1.3 is connected or not connected to an input.

- Is my sampling frequency configured as 6553 Hz correctly?

- In this case, what seems to be a problem for P1.3? Is this related to ADC10CLK?

-Best Regards, David

  • P1.3 is connected to a pushbutton. I vaguely recall a generation of the G2 Launchpad which had an external (physical) pullup resistor installed there. Do you get the same effect on A4?

    Unsolicited: With CONSEQ=2 and MSC=1 you won't get a timer trigger, rather it will sample as fast as it can. I think you can get the effect you want by just setting MSC=0.
  • In reply to Bruce McKenney47378:

    Hi, Bruce.

    Bruce McKenney47378
    P1.3 is connected to a pushbutton.

    Thank goodness. You were right. I didn't notice that! I will try with another GPIO pin right away.

    Bruce McKenney47378
    Unsolicited: With CONSEQ=2 and MSC=1 you won't get a timer trigger, rather it will sample as fast as it can.

    I always appreciate this type of comments. However, it is strange that the TI example said this;

    ADC10CTL1 = SHS_1 + CONSEQ_2 + INCH_1;    // TA1 trigger sample start

    Although this doesn't trigger a Timer ISR, the ADC ISR is triggered.

    Can you explain the meaning of "you won't get a timer trigger"?

    -Best Regards, David

  • In reply to David__:

    With your settings, you'll get conversions, but they'll come one right after another since with MSC=1 the ADC won't wait for the timer trigger. You can see this in the User Guide (SLAU144J) Figure 22-7.

    My copy of adc10_11.c (from SLAC485J) sets ADC10CTL0:MSC=0:

    > ADC10CTL1 = SHS_1 + CONSEQ_2 + INCH_1; // TA1 trigger sample start
    > ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE;

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.