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 BUSY bit issue

Other Parts Discussed in Thread: MSP430F5310

Hi,

 

I am using ADC10 of MSP430F5310. I am having problem that ADC10BUSY bit is not getting reset. Below is my code.

int main(void)
{
int adc_val;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer to prevent time out reset


// ACLK = REFO = 32.768kHz, MCLK = SMCLK = (Default DCO)/2 = (2MHz/2) = 1MHz
P5SEL |= 0x30; // Select XT1

UCSCTL6 &= ~(XT1OFF); // XT1 On
UCSCTL6 |= XCAP_0 + XT1DRIVE_1; // External load cap
// Drive strength for 8 to 16MHz

__bis_SR_register(SCG0); // Disable the FLL control loop
UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx
UCSCTL1 = DCORSEL_5; // Select DCO range 8MHz operation
UCSCTL2 = FLLD_1 + 122; // Set DCO Multiplier for 8MHz
__bic_SR_register(SCG0); // Enable the FLL control loop

UCSCTL3 |= SELREF_0; // Set DCO FLL reference = XT1
UCSCTL4 = SELA_0 + SELS_3 + SELM_3; // Set MCLK = SMCLK = DCOCLK & ACLK=XT1(32768Hz)


//-----------------------------------------------------------------
// Configure ADC for Motor Current Monitoring
// With ADC10OSC range is from 4.2 to 5.4MHz
// With 50ksps for one sample at least 20 uSec is required.
//----------------------------------------------------------------

ADC10CTL0 &= ~ADC10ENC; // Disable ADC10
ADC10MCTL0 |= ADC10INCH_4; // P6.4(A4),AVCC and AVSS,

// 16 ADC clock for single conversion
// Sample and conversion not starsted
ADC10CTL0 |= ADC10SHT_2;

// ADC10SC bit for start of conversion
// Single channel, single conversion, SMCLK/MODOSC
ADC10CTL1 |= ADC10SSEL_3 + ADC10CONSEQ_0; // SMCLK(8MHz)
// ADC10CTL1 |= ADC10CONSEQ_0; // MODOSC CLK(4.2-5.4MHz)

// 10bit Result,50ksps
ADC10CTL2 |= ADC10RES + ADC10SR;
ADC10CTL0 |= ADC10ON; // Turn ON ADC
P6SEL |= 0x10; // P6.4 ADC option select
//P6DIR &= ~0x10; // P6.4 As Input


__bis_SR_register(GIE);

while(1)
{
ADC10CTL0 |= ADC10SC + ADC10ENC; // Start Sampling
while(ADC10CTL1 & ADC10BUSY); // Wait till sample & coversion
adc_val=ADC10MEM0;
}
}

Please suggest if anything wrong.

 

khodidas

  • How do you know it isn't reset? What did you do to get this information?
    (Sometimes the debugger is a bugger and things work fine if you don't try to debug them.)

    The only reason why it is never reset is that SMCLK has no frequency. THen the ADC is not clocked at all and requires endless time to do the conversion.

    However, ADCON should be the first bit you set. Before configuring the rest.

  • Jens,

     

    thanks for your reply. I rewrite code and is working fine now. New code is given below.

     
    P6SEL |= 0x10; // P6.4 ADC option select
       

    ADC10CTL0 &= ~ADC10ENC; // Disable ADC10

    // 16 ADC clock for sample of signal
    // Sample and conversion not starsted
    // Turn ON ADC
    ADC10CTL0 |= ADC10SHT_2 + ADC10ON;

    // ADC10SC bit for start of conversion
    // Single channel, single conversion, SMCLK/MODOSC
    ADC10CTL1 |= ADC10SSEL_3 + ADC10SHP + ADC10CONSEQ_0; // SMCLK(8MHz)
    // ADC10CTL1 |= ADC10CONSEQ_0 + ADC10SHP; // MODOSC CLK(4.2-5.4MHz)

    // 10bit Result
    ADC10CTL2 |= ADC10RES;

    ADC10MCTL0 |= ADC10INCH_4; // P6.4(A4),AVCC and AVSS,

     I think ADC10SHP was the issue. I also turned ADC10ON first as per your suggestion.

     

    khodidas

  • khodidas ghinaiya said:
     I think ADC10SHP was the issue

    Yes, you're right. If SHP isn't set, the sampling stage is controlled by the trigger (in your case the start conversion bit) and not times by the ADC10SHT_x setting and the clock.

    So in your case, the ADC has started sampling and waited for you to clear the ADC10SC bit so the conversion can begin. Shame on my, I should have noticed this. :)
    I really don't know why you have to set this bit so the ADC works in its simplest mode.It bugged me too when I started with the ADC12, so I wonder why I didn't notice that it was missing. Sorry.

  • sir,

    i started working on  MSP430.the problem is i am not able to write the code.i am trying to write code for converting analog to digital and send it through the serial communication.requesting for suggestions.

  • Why did you add your question to this thread instead of creating a new one? Your problem isn't related to teh original problem in this thread.

    However:

    I fyou don't know where to start, break down the problem into two parts. First implement sending data through serial connection. There are many samples available, depending on the hardware you use. Then develop a data format you want to use. The ADC produces a 16 bit binary data value. You may forward it as two bytes of 8 bit binary data through the serial connection, you may calculate a (floating point) voltage value form it first and send the calculaiton result as binary data, or you may convert the bninary data into a textual (human readable) ASCII string first (usning the sprintf function) and send the text data. Your serial send function must be able to handle binary data of multiple bytes, or sending a string (a zero-terminated array of characters). And of course the PC coutnerpart must be able to understand it (a terminal program like HyperTerm won't show binary values, but an app may prefer binary data instead of parsing a text again into a value)

    If you have problems with details of the implementation, please com eback and ask - and post your code then, so it can be checked.

**Attention** This is a public forum