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.

ADC in MSP430G2553

Other Parts Discussed in Thread: MSP430G2553, MSP430WARE

The code given below gives the reading of ADC10MEM at static level only and doesn't give the reading if the input is changes. I want it to be changed at every level i change the input. I am using potentiometer shows the output of particular level if I change the voltage then i have re run the code. Can anybody help.

#include "msp430g2553.h"
#include "intrinsics.h"
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // stop WDT


// ADC configuration,V+ref=3V,V-ref=0V,Channel=A0
ADC10CTL0 = ADC10ON + ADC10IE; // Vref Vr+=3v,Vr-=VSS,
// S&Htime = 4 X ADCCLK,ADC10 on,ADC interrupts enabled
ADC10CTL1 = ADC10DIV_7; // INCH =0000->A0,ADCCLK src = ADC10CLK,
// ADCCLK/8,Single Channel Single Conversion
ADC10AE0 = INCH_0; // channel A0

ADC10CTL0 |= ENC + ADC10SC; // Start Conversion

_BIS_SR(LPM0_bits +GIE); // Go to LPM0,interrupts enabled
}

/***************************************************************************/
/* interrupt vectors for MSP430 */
/***************************************************************************/

#pragma vector = ADC10_VECTOR
__interrupt void adc10_interrupt(void)
{
ADC10CTL0 |= ENC + ADC10SC; // Start Conversion again
}

 

  • Hello,

    Following are the options to suffice your requirement :-

    1. Put your adc code in while loop
    2. Use timer in LPM 3 mode
    3. Use switch input in LPM 4 mode

    You can refer ADC, Timer and Switch examples. Also I would suggest you to use uart to print adc values which will make your life simple during testing.

    Regards
    Ayush J
  • Hi Sanjeev!

    In your code I cannot see that you read the ADC result. Or do you only look at the ADC10MEM register?

    Dennis
  • Can u please send me a link of an example so that i can understand it clearly.
  • SANJEEV KUMAR GAUTAM said:
    Can u please send me a link of an example so that i can understand it clearly.

    Here you go.

  • You can refer examples from msp430ware. It is very good source for learning.
  • sir i have used the code written below but it is not displaying my output on LCD can u help ASAP
    #include "msp430g2553.h"

    unsigned int ADC_value=0;

    void ConfigureAdc(void);

    void main(void)
    {

    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    BCSCTL1 = CALBC1_1MHZ; // Set range DCOCTL = CALDCO_1MHZ;
    BCSCTL2 &= ~(DIVS_3); // SMCLK = DCO = 1MHz
    P1SEL |= BIT3; // ADC input pin P1.3
    ConfigureAdc(); // ADC set-up function call
    __enable_interrupt(); // Enable interrupts.


    while(1)
    {
    __delay_cycles(1000); // Wait for ADC Ref to settle
    ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
    __bis_SR_register(CPUOFF + GIE); // Low Power Mode 0 with interrupts enabled
    ADC_value = ADC10MEM; // Assigns the value held in ADC10MEM to the integer called ADC_value

    }

    InitializeLcm();
    __delay_cycles(1000000);

    ClearLcmScreen();
    __delay_cycles(1000000);


    PrintStr(ADC_value);
    __delay_cycles(1000000);
    }

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

    // Function containing ADC set-up
    void ConfigureAdc(void)
    {

    ADC10CTL1 = INCH_3 + ADC10DIV_3 ; // Channel 3, ADC10CLK/3
    ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE; // Vcc & Vss as reference, Sample and hold for 64 Clock cycles, ADC on, ADC interrupt enable
    ADC10AE0 |= BIT3; // ADC input enable P1.3
    }
  • can u also send me the codes of GSM and LCD module. thanks in advance.
  • No I cant. Note that code I provided is made by TI. Try to use search on forum or just google

**Attention** This is a public forum