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.

msp430 adc pin configuration

Other Parts Discussed in Thread: MSP430G2231

hi,

I am using msp430g2231.  i am very new to this.  I am trying the programs given in the sample program list.   I am trying the adc program.  There are 7 pins for analog in the launch pad.  can someone say me which pin is configured as adc pin in the given adc program and also say how to configure an adc pin.

cheers,

Hari

  • What example are you referencing?  You haven't cited a name or the zip file archive you are using.  This makes it difficult for anyone to speculate on which ADC channel input is being used.

    Secondly, I would suggest you familiarize yourself with the MSP430G2231 datasheet and MSP430x2xx Family User's Guide, both found on the MSP430G2231 Product Folder.

    I would also suggest you utlize the Launchpad Wiki Portal on the TI Embedded Processing wiki site.  A link to this site is also found on the MSP430G2231 Product Folder in the Support and Community section.

  • i am referring adc example in the example programs list. i am using a 14 pin ic.

    heres the coding:

    /*#include <msp430g2231.h>
    volatile long tempRaw;
    void FaultRoutine(void);
    void main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
    P1DIR = 0x41; // P1.0 & 6 outputs
    P1OUT = 0; // LEDs off
    if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
    FaultRoutine(); // If cal data is erased
    // run FaultRoutine()
    BCSCTL1 = CALBC1_1MHZ;  // Set range
    DCOCTL = CALDCO_1MHZ; // Set DCO step + mod
    BCSCTL3 |= LFXT1S_2; // LFXT1 = VLO
    IFG1 &= ~OFIFG; // Clear OSCFault flag
    BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3; // MCLK=DCO/8,SMCLK=DCO/8
    while(1)
    {
    ADC10CTL1 = INCH_1 + ADC10DIV_0; // Temp Sensor ADC10CLK
    ADC10CTL0 = SREF_1 + REF2_5V + ADC10SHT_3 + REFON + ADC10ON;
    _delay_cycles(5); // Wait for Ref to settle
    ADC10CTL0 |= ENC + ADC10SC; // Samp and convert start
    P1OUT = 0x40; // P1.6 on (green LED)
    _delay_cycles(100); // Wait for conversion
    ADC10CTL0 &= ~ENC; // Disable ADC conversion ADC10CTL0 &= ~(REFON + ADC10ON); // Ref and ADC10 off
    tempRaw = ADC10MEM; // Read conversion value
    P1OUT = 0; // green LED off
    _delay_cycles(125000); // delay 1 second
    }
    }
    void FaultRoutine(void)
    {
    P1OUT = 0x01; // red LED on
    while(1); // TRAP
    }
    */
    /*#include <msp430g2231.h>
    unsigned int res[2]; //for holding the conversion results
    void main (void)
      //code for connecting to AP
      //reading voltage
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      ADC10CTL1 = INCH_2 + CONSEQ_1;            // A2/A1/A0, once multi channel
      ADC10CTL0 = REF2_5V + ADC10SHT_2 + MSC + REFON + ADC10ON + ADC10IE; //2.5 reference voltage
      ADC10AE0 = 0x6;                          // P1.1,2 ADC option select
      ADC10DTC1 = 0x2;                         // 2 conversions
      P1DIR |= 0x01;                            // Set P1.0 output
      for (;;)
      {
        P1OUT |= 0x01;                          // Set P1.0 LED on
        ADC10CTL0 &= ~ENC;
        while (ADC10CTL1 & BUSY);               // Wait if ADC10 core is active
        ADC10SA = (int)res;                        // Data buffer start
        ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion ready
        __bis_SR_register(CPUOFF + GIE);        // LPM0, ADC10_ISR will force exit
        P1OUT &= ~0x01;                         // Clear P1.0 LED off
      }
    }
    #pragma vector=ADC10_VECTOR
    __interrupt void ADC10_ISR(void)
    {
        //code from reading from res and sending it to AP
      __bic_SR_register_on_exit(CPUOFF);        // Clear CPUOFF bit from 0(SR)
    }*/
    #include  "msp430g2231.h"
     
    #define     LED0                  BIT0
    #define     LED1                  BIT6
    #define     ADC_CHANNELS     2  //We will sample 2 channels
    unsigned int samples[ADC_CHANNELS];
    unsigned int out;
    unsigned long pwr=0;
    //void ConfigureAdc(void)
    //{
    //  /* Configure ADC  Channel */
    //  ADC10CTL1 = INCH_1 + ADC10DIV_3 ;         // Channel 1, ADC10CLK/4
    //  ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;  //Vcc & Vss as reference
    //  ADC10AE0 |= BIT1;                         //P1.1 ADC option   
    //}
    void ConfigureAdc(void)
    {
      /* Configure ADC  Channels */
      ADC10CTL1 = INCH_2 + ADC10DIV_0 + CONSEQ_3 + SHS_0;   //Multi-channel repeated conversion starting from channel 2
      ADC10CTL0 = SREF_0 + ADC10SHT_2 + MSC + ADC10ON + ADC10IE;
      ADC10AE0 = BIT2 + BIT1;
      ADC10DTC1 = ADC_CHANNELS;    //ADC_CHANNELS defined to 2  
    }
    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT 
      BCSCTL1 = CALBC1_1MHZ;                    // Set range
      DCOCTL = CALDCO_1MHZ;
      BCSCTL2 &= ~(DIVS_3);                  // SMCLK = DCO = 1MHz 
      P1DIR |= LED0 + LED1;  
      P1SEL |= BIT1;                             //ADC Input pin P1.1         
      P1OUT &= ~(LED0 + LED1); 
      
      ConfigureAdc();   
      __enable_interrupt();                     // Enable interrupts.
      while(1)
      {   
        __delay_cycles(1000);                   // Wait for ADC Ref to settle
        ADC10CTL0 &= ~ENC;
      while (ADC10CTL1 & BUSY);
      ADC10SA = (unsigned int)samples;
        ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
        __bis_SR_register(CPUOFF + GIE);        // LPM0 with interrupts enabled   
        
        if (samples[0]*samples[1] > pwr+1000)
        {
    pwr = ((unsigned long)samples[0])*((unsigned long)samples[1]);
    out = samples[0] + 100;
           P1OUT &= ~(LED0 + LED1);
           P1OUT |= LED0;
        }
        else if (samples[0]*samples[1] < pwr-1000)
        {
        pwr = ((unsigned long)samples[0])*((unsigned long)samples[1]);
           P1OUT &= ~(LED0 + LED1);
           P1OUT |= LED1;
           //pwr = pwr - 2200;
           out = samples[0] - 200;
         }
      } 
    }
    // ADC10 interrupt service routine
    #pragma vector=ADC10_VECTOR
    __interrupt void ADC10_ISR (void)
    {
      __bic_SR_register_on_exit(CPUOFF);        // Return to active mode
    }
    can you now tell me which pin is configured as adc pin?

  • It appears you have concatenated 3 examples in this last post (considering you have at least 3 instances of #include "msp430g2231.h" and 3 main() routines).

    Which one are you asking about?

    Also, have you reviewed the comments at the beginning of these examples to see if it provides clarity as to what the example is attempting to illustrate?

    And, instead of posting the code, can you provide just the file name of the example and the zip archive literature number so I can pull it down myself and look at it?  This helps in citing your source.

     

**Attention** This is a public forum