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.

ADC10 Always Busy?

Other Parts Discussed in Thread: MSP430F6733

Hello everybody,

I'm trying to implement the ADC10 on an MSP430F6733 and have run into a problem in my preliminary messing-around code:

P1SEL |= 0x01; // Enable analog input A2 pin for alternate use
ADC10MCTL0 = ADC10INCH_2; // Use analog input A2
ADC10CTL0 = ADC10SHT_2 | ADC10ON; // 16 s&h cycles, ADC on
ADC10CTL1 = ADC10SSEL_2; // Use MCLK
ADC10CTL2 = 0;

while (1) {
   ADC10CTL0 |= ADC10ENC | ADC10SC;
   lcd_disp_int(&myLcd, 9999, off);

   while (ADC10CTL1 & ADC10BUSY) ;

   int16_t result = ADC10MEM0;
   lcd_disp_int(&myLcd, result, off);
   while (1) ;
}

The code seems to get stuck at the while(ADC10CTL1 & ADC10BUSY) statement, as though the ADC were always busy. Removing the statement which starts the conversion (ADC10CTL0 |= ADC10ENC | ADC10SC) "fixes" the problem in the sense that the code doesn't get stuck, but of course this defeats the purpose of having ADC code.

Any thoughts on what might be wrong here? I've gone over the initializations a couple of times and they seem right to me, but I must have missed something.

Thanks!

  • Jacob Dickinson said:

    Hello everybody,

    I'm trying to implement the ADC10 on an MSP430F6733 and have run into a problem in my preliminary messing-around code:

    P1SEL |= 0x01; // Enable analog input A2 pin for alternate use
    ADC10MCTL0 = ADC10INCH_2; // Use analog input A2
    ADC10CTL0 = ADC10SHT_2 | ADC10ON; // 16 s&h cycles, ADC on
    ADC10CTL1 = ADC10SSEL_2; // Use MCLK
    ADC10CTL2 = 0;

    while (1) {
       ADC10CTL0 |= ADC10ENC | ADC10SC;
       lcd_disp_int(&myLcd, 9999, off);

       while (ADC10CTL1 & ADC10BUSY) ;

       int16_t result = ADC10MEM0;
       lcd_disp_int(&myLcd, result, off);
       while (1) ;
    }

    The code seems to get stuck at the while(ADC10CTL1 & ADC10BUSY) statement, as though the ADC were always busy. Removing the statement which starts the conversion (ADC10CTL0 |= ADC10ENC | ADC10SC) "fixes" the problem in the sense that the code doesn't get stuck, but of course this defeats the purpose of having ADC code.

    Any thoughts on what might be wrong here? I've gone over the initializations a couple of times and they seem right to me, but I must have missed something.

    Thanks!

    ADC10CTL0 |= ADC10ENC+ ADC10SC?

    maybe

  • xiaochun lu said:

    ADC10CTL0 |= ADC10ENC+ ADC10SC?

    maybe

    Definitely not. Because result will be identical to:

    xiaochun lu said:
       ADC10CTL0 |= ADC10ENC | ADC10SC;

  • Jacob Dickinson said:
    emoving the statement which starts the conversion

    Obviously, the ADC can't be busy if you didn't start a conversion :)

    The problem is simple but not obvious: YOu do not set the SHP bit. With this bit set, you trigger a conversion and the timing for sampling is internally done by using the SHTx controls. If you don't set this bit, the sampling time is controlled by the trigger. That means wehn you set ADC10SC, you open the sampling gate for charging the sampling capacitor, and when you manually clear this bit, the sampling gate closes and the conversion begins. This is mostly for timer-controlled timing, but may also be of use for manual control. However, in your case it's not what you expect and handle.

  • Jens-Michael Gross said:

    The problem is simple but not obvious: YOu do not set the SHP bit. With this bit set, you trigger a conversion and the timing for sampling is internally done by using the SHTx controls. If you don't set this bit, the sampling time is controlled by the trigger. That means wehn you set ADC10SC, you open the sampling gate for charging the sampling capacitor, and when you manually clear this bit, the sampling gate closes and the conversion begins. This is mostly for timer-controlled timing, but may also be of use for manual control. However, in your case it's not what you expect and handle.

    Thanks! That solved it -  I clearly did not read the datasheet carefully enough.

**Attention** This is a public forum