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.

MSP430G2553: MSP430 ADC

Part Number: MSP430G2553
Other Parts Discussed in Thread: MSP430G2253, , MSP430WARE

Hello,

     My project has two Analog outputs. I am using MSP430G2253 Microcontroller to do two ADC conversions. I am not getting correct ADC conversion values . Will you Please help me.

Code:

void main()

{

xxxxxxxxxx

xxxxxxxx

xxxxxxxxx

while(1)

{

adc_temp();

calc_temp();

__delay_cycles(50000);

adc_signal();

calc_value();

__delay_cycles(50000);

}

}

void adc_temp()
{
ADC10CTL0 &= ~ENC;
ADC10CTL0 = ADC10ON + ADC10SR + ADC10SHT_0 + SREF_0;
ADC10CTL1 = CONSEQ_0 + ADC10SSEL_0 + ADC10DIV_0 + SHS_0 + INCH_4;
ADC10CTL0 |= ENC;
}

void adc_signal()
{
ADC10CTL0 &= ~ENC;
ADC10CTL0 = ADC10ON + ADC10SR + ADC10SHT_0 + SREF_0;
ADC10CTL1 = CONSEQ_0 + ADC10SSEL_0 + ADC10DIV_0 + SHS_0 + INCH_5;
ADC10CTL0 |= ENC;
}

calc_temp()

{

ADC10CTL0 |= ENC + ADC10SC;
temp_value = ADC10MEM;
__delay_cycles(5000);

xxxxxxxxx;

xxxxxxxxx

xxxxxxxxx

}

calc_value()

{

ADC10CTL0 |= ENC + ADC10SC;
signal_value = ADC10MEM;
__delay_cycles(5000);

xxxxxxxxx;

xxxxxxxxx

xxxxxxxxx

}

  • Hello Mukhramuddin,

    You may have to increase your sample and hold time for correct results. We do have example code available on how to sample the internal temp sensor using the ADC. Navigate to the TI Resource Explorer -> Software -> MSP430Ware -> Devices -> MSP430G2xx -> MSP430G2553 -> Peripheral Examples -> Register Level -> msp430g2x33_adc10_temp.c . TI Resource Explorer can be found within CCS or at dev.ti.com .
  • Hello Jace,

                  Thanks for the reply. I want to use two external ADC (may be three ADC in future).

     

  • Hello Jace,

    Thanks for the reply.

    P1.1 and P1.2 used for UART communincation

    P1.3, P1.4 and P1.5 for ADC conversions.


    Will you please let me know the mistakes in the code.

    Thanks.
  • In your functions,

    You are starting the ADC conversion, but reading the sample values even before the sampling & conversion is done.

    For a valid sampling & conversion either you have to use a busy wait loop or use ADC10 interrupt(ADC10IE).

    calc_temp() & calc_value(),

    follow as below,

    Busy wait Loop:

    calc_temp(){
    
    ADC10CTL0 |= ENC + ADC10SC;
    
    while (ADC10CTL1 & ADC10BUSY);
    
    temp_value = ADC10MEM;
    
    __delay_cycles(5000); //This is not necessary unless you are using it for something else than ADC purpose
    
    }

    Or

    Interrupt:

    init(){
    
    ;
    
    ;
    
    ADC10CTL1 |= <ADC input channel>;
    
    ADC10AE0 |= <Analog enable>
    
    ;
    
    ;
    
    }
    
    calc_temp(){
    
    ADC10CTL0 |= ADC10IE;//enable ADC interrupt
    
    ADC10CTL0 |= ENC + ADC10SC;
    
    <CPU sleep>
    
    }
    
    __interrupt void ADC10_ISR(void)
    
    {
    
    temp_value = ADC10MEM;
    
    <wakeup CPU>
    
    }

    About your comment "P1.1 and P1.2 used for UART communincation",

    You can reconfigure these channels through PxSEL & PxSEL2 registers.

  • Hi Chethu,

    Thanks for the reply and information. I will try this today. Thank you.

    Thanks and Regards,
    M.Mohammed

**Attention** This is a public forum