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.

msp430f5529 adc problem

Other Parts Discussed in Thread: MSP430F5529

Hi 

   i am using msp430f5529 , i  am able to  read  adc values from memory  but the values are not correct.  the code i have written as follows. i am  reading  adc value across pin5 of port 6. i am using external reference voltage.

P6SEL |= | BIT5 ;
ADC12CTL0 |= ADC12ON | ADC12SHT0_15 ;
ADC12CTL1 |= ADC12SHS_0 | ADC12CSTARTADD_5 | ADC12SHP | ADC12CONSEQ_0 |ADC12SSEL_0;
ADC12MCTL5 |= ADC12SREF_2| ADC12INCH_5 ;
ADC12IE |= ADC12IE5 ;
ADC12CTL0 |= ADC12ENC ;

while (1)

{

   ADC12CTL0 |= ADC12SC;    

}

  • arun j2 said:
    ADC12SREF_2

    So what is your external reference? How is it attached? Properly filtered?

    I don't see you setting up P5.0/P5.1 for external reference input. To avoid influence and increased current consumption on the digital part of the port pins, you should set P5SEL.0 when using VeREF.

  • Have u enabled the global interrupt ?

    Lookin at the code it seems u have retrieved values in ISR.

    Code :

     

    P6SEL |= | BIT5 ;
    ADC12CTL0 |= ADC12ON | ADC12SHT0_15 ;
    ADC12CTL1 |= ADC12SHS_0 | ADC12CSTARTADD_5 | ADC12SHP | ADC12CONSEQ_0 |ADC12SSEL_0;
    ADC12MCTL5 |= ADC12SREF_2| ADC12INCH_5 ; 
    ADC12IE |= ADC12IE5 ;
    ADC12CTL0 |= ADC12ENC ;

    ADC12CTL0 |= ADC12SC;    (CHANGES MADE)

    while (1)

    {

        //Enable global interrupts

    }

    // IN ADC ISR

    {

      int i;

    i = ADC12MEM5; 

    print(value of i);

    ADC12CTL0 &= ~ (ADC12ENC );

    ADC12CTL0 |= ADC12ENC ; //This step is required for next conversion

    }

    for details go thru the Family Guide

  • Hi Jens-Michael Gross

            I have setted the p5.0 pin and its also not working.My code as follows, i am able to read values at memory register ADC12MEM5  but the values are not constant , values are changing.

    P6DIR &= ~BIT5 ;

    P6SEL |= BIT5 ;

    P5SEL |= BIT0 ; 

    ADC12CTL0 |= ADC12ON | ADC12SHT0_15| ADC12SHT1_15 ; 
    ADC12CTL1 |= ADC12SHS_0 | ADC12CSTARTADD_5 | ADC12SHP | ADC12CONSEQ_0 | ADC12SSEL_0 | ADC12DIV_7 ;
    ADC12CTL2 |= ADC12TCOFF | ADC12RES_2 ;
    ADC12MCTL5 |= ADC12SREF_2 | ADC12INCH_5 ; 

    ADC12CTL0 |= ADC12ENC ; 


    while (1)
    {


    ADC12CTL0 |= ADC12SC; // Start conversion-software trigger

    while (!(ADC12IFG & BIT5));

    ADC12IFG &= ~BIT5;

    __no_operation(); // SET BREAKPOINT HERE


    }

  • Hi Nikhil ,

                  I am using ADC12SC  for conversion . so no need of these steps.

    ADC12CTL0 &= ~ (ADC12ENC );

    ADC12CTL0 |= ADC12ENC ; //This step is required for next conversion

  • arun j2 said:
    ADC12CTL0 &= ~ (ADC12ENC );
    ADC12CTL0 |= ADC12ENC ; //This step is required for next conversion

    On ADC12SHS_0, ADC12CONSEC_0 and ADC12SHP, there is no need to toggle ENC.
    After ADC12ENC has been set, setting ADC12SC will start the conversion. When the conversion is done 8and onyl then), ADC12SC will automatically reset, and setting it again will trigger the next conversion.

    On all other conversion modes (repeated or sequence, or if ADC12SHP isn't set), ADC10SC won't reset ad you have to manually clear it. (in case of ADC12SHP=0, clearing ADC12SC is required to end the sampling phase and start the conversion phase)

  • Hi jens-Michael Gross,

                         I am using single channel single conversion mode,so no need to toggle ENC. After setting ADC12ENC 

    i am doing conversion, i am getting values but values are not correct. If i change ADC12SHS i get different values. can u please let me know what would be the problem.I am using internal reference.

  • arun j2 said:
    If i change ADC12SHS i get different values.

    ADC12SCS controls whether ADC12SC (ADC12SHS_0) or a timer CCR output controls the conversion start and (if SHP is clear) the sampling time.

    arun j2 said:
    I am using internal reference

    You don't. You may want to, but you don't.

    ADC12MCTL5 |= ADC12SREF_2| ADC12INCH_5 ;

    This selects external reference on VeREF input pin. Also, I do not see you enabling the internal reference, so even if you were using ADC12SREF_1 for internal reference, it wouldn't work without the internal reference being configured.

    Use ADC12SERF_0 for using Vcc as reference. For first positive results. Then raise complexity by using the internal reference. :)

    BTW: there is no implicit relation between ADC12MCTL5 and using A5 input. You can sample A5 on MCTL0 or A7 on MCTL5. It is freely configurable.

  • Hi jens Michael Gross,

                    I am able to read values in memory but values are not  constant .My code as follows.I am using external reference,if anything going wrong in code please let me know.

    P6SEL |= BIT5 ;
    ADC12CTL0 = ADC12ON+ADC12SHT0_15; 
    ADC12CTL1 = ADC12SHP; 
    ADC12MCTL0 = ADC12SREF_2; 
    ADC12CTL0 |= ADC12ENC; 

    while (1)
    {
    ADC12CTL0 |= ADC12SC; 
    while (!(ADC12IFG & BIT0));

    __no_operation();

    }

  • Did you read my previous post? You still tell the ADC to use an external reference. If there is none (and you said you want to use the internal one, which you still do not enable), then no wonder that the results are not stable. They vary based on whatever noise is received on the external reference input pin.

  • Hi Jens-Michael,

    I am able to read ADC value but values are not correct. my code as follows. Please tell us where the flow going wrong.


    P6SEL |= BIT5; // TEMPERATURE AS peripheral
    REFCTL0 &= ~REFMSTR; // reference master control set to zero
    ADC12CTL0 |= ADC12SHT0_10 | ADC12ON | ADC12REFON | ADC12REF2_5V ; // ADC sample hold bit select,ADC enable, ADC reference voltage enable,ADC refernce voltage is 2.5v
    ADC12CTL1 |= ADC12CSTARTADD_5 | ADC12SHP | ADC12DIV_1 | ADC12CONSEQ_0 | ADC12SSEL_0 | ADC12SHS_0; ADC conversion start address,sample hold pulse mode,clock divided by 1,conversion sequence, clock source select,sample and hold select
    ADC12CTL2 |= ADC12REFOUT ; // ADC reference output
    ADC12MCTL5 |= ADC12SREF_1 | ADC12INCH_5 ; //ADC reference, channel input 5
    ADC12CTL0 |= ADC12ENC ; // ADC enable conversion


    while (1)

    {

    ADC12CTL0 &= ~ADC12ENC ;
    ADC12CTL1 |= ADC12CSTARTADD_5;
    ADC12MCTL5 |= ADC12SREF_1 | ADC12INCH_5 ;
    ADC12CTL0 |= ADC12ENC;
    ADC12CTL0 |= ADC12SC; // enable start conversion
    while (!(ADC12IFG & BIT5));
    gAdc_value_capture_temp = ADC12MEM5; // store data in variable
    ADC12IFG &= ~BIT5;

    }

    Regards

    Arun j
  • Before the while loop. wait for the reference to settle.
    Inside the while loop, remove the first 4 lines, they are superfluous, as you already configured them, and they don't change by themselves.

    When you set ADC12REFOUT (which is always required on some MSPs, and required for higher conversion frequencies on some others), then you need to solder a 10µF tantalum/100nF ceramic combo to the VREF+ pin to stabilize the reference. If you don't, the reference might be unstable.

**Attention** This is a public forum