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.

MSP430F5659: ADC count value issue

Part Number: MSP430F5659
Other Parts Discussed in Thread: TIDA-00648

hello,

I  am using MSP430f5659 microcontroller to interface 4-20 mA level sensor. I am using multiple channel read Adc code example of ti ie. msp430f665x_adc_06.c. when sensor is at fixed height it should show a fixed count value but it is showing a range of value (eg: 804-824 for a fixed value). I am using reference voltage as AVCC and AVSS which is 3.3v and gnd . Please suggest some solution to count variation problem.

  • Hello,

    Be sure to have a 470 nF capacitor at Vcore and 10 uF + 100 nF decoupling capacitors at each AVCC pin. Also note the 12-Bit ADC Linearity Parameters Using AVCC as Reference Voltage Table from the Datasheet.

    Regards,
    Ryan
  • hello Ryan,

    Thanks for the response.

    But i am not able to get the stable adc count value as i have studied the datasheet. I have tried both configuration AVCC and AVSS as reference and internal vref as ref voltage.

    I am using adc values on 3 channel. Currently i am checking the count values on P6.2 pin.

     my code is given below: using ref as internal vref

          P6DIR &=~( BIT0 + BIT1 + BIT2 );
          P6SEL |= BIT0 + BIT1 + BIT2;                   // Enable A/D channel inputs p6.0, p6.1, p6.2
          ADC12CTL0 &= ~ADC12ENC;
          REFCTL0 &= ~REFMSTR;                      // Reset REFMSTR to hand over control to
                                                    // ADC12_A ref control registers
          ADC12CTL0 = ADC12ON|ADC12SHT03|ADC12REFON|ADC12REF2_5V| ADC12MSC;
                                                    // Turn on ADC12, Sampling time
                                                    // On Reference Generator and set to
                                                    // 2.5V
          ADC12CTL1 = ADC12SHP|ADC12CONSEQ_1|ADC12DIV_1;                // Use sampling timer, single sequence
          ADC12CTL2 = ADC12RES_2 |ADC12REFOUT;                                          //ADC12_A resolution 12 bit
          ADC12MCTL0 = ADC12INCH_0 |ADC12SREF_1;                                        // ref+=AVcc, channel = A0, Vr+=Vref+ and Vr-=AVss
          ADC12MCTL1 = ADC12INCH_1 |ADC12SREF_1;                                       // ref+=AVcc, channel = A1, Vr+=Vref+ and Vr-=AVss
          ADC12MCTL2 = ADC12INCH_2 |ADC12EOS | ADC12SREF_1;                // ref+=AVcc, channel = A2,
          ADC12CTL0 |= ADC12ENC;

    using AVCC as ref voltage :

          P6DIR &=~( BIT0 + BIT1 + BIT2 );
          P6SEL |= BIT0 + BIT1 + BIT2;                   // Enable A/D channel inputs p6.0, p6.1, p6.2
          ADC12CTL0 &= ~ADC12ENC;
          ADC12CTL0 = ADC12ON+ADC12MSC+ADC12SHT0_3;     // Turn on ADC12, extend sampling time
                                                        // to avoid overflow of results, 16 ADC12CLK cycles
          ADC12CTL1 = ADC12SHP+ADC12CONSEQ_1+ADC12DIV_1;           // Use sampling timer, single sequence
          ADC12CTL2 = ADC12RES_2;                        //ADC12_A resolution 12 bit
          ADC12MCTL0 = ADC12INCH_0;                        // ref+=AVcc, channel = A0
          ADC12MCTL1 = ADC12INCH_1;                         // ref+=AVcc, channel = A1
          ADC12MCTL2 = ADC12INCH_2+ADC12EOS;                 // ref+=AVcc, channel = A2
          ADC12CTL0 |= ADC12ENC;

    I do not know how many clock cycles needed to complete the conversion, so I have tried upto 32 clock cycles.

    Is there any mistake in the code? Please suggest some solution.

  • I have used all these capacitors.
  • but it did not solve my issue. I have tried using avcc as a refe and internal voltage 2.5 voltage as a ref voltage. But it did not work well. I am still getting a huge difference between count value.
    My code is given below: voltage AVCC as a ref

    P6DIR &=~( BIT0 + BIT1 + BIT2 );
    P6SEL |= BIT0 + BIT1 + BIT2; // Enable A/D channel inputs p6.0, p6.1, p6.2
    ADC12CTL0 &= ~ADC12ENC;
    ADC12CTL0 = ADC12ON+ADC12MSC+ADC12SHT0_15; // Turn on ADC12, extend sampling time
    // to avoid overflow of results, 16 ADC12CLK cycles
    ADC12CTL1 = ADC12SHP+ADC12CONSEQ_1+ADC12DIV_1; // Use sampling timer, single sequence
    ADC12CTL2 = ADC12RES_2+ADC12SR; //ADC12_A resolution 12 bit
    ADC12MCTL0 = ADC12INCH_0; // ref+=AVcc, channel = A0
    ADC12MCTL1 = ADC12INCH_1; // ref+=AVcc, channel = A1
    ADC12MCTL2 = ADC12INCH_2+ADC12EOS; // ref+=AVcc, channel = A2
    ADC12CTL0 |= ADC12ENC;

    internal voltage 2.5v as a ref:

    P6DIR &=~( BIT0 + BIT1 + BIT2 );
    P6SEL |= BIT0 + BIT1 + BIT2; // Enable A/D channel inputs p6.0, p6.1, p6.2
    ADC12CTL0 &= ~ADC12ENC;
    REFCTL0 &= ~REFMSTR; // Reset REFMSTR to hand over control to
    // ADC12_A ref control registers
    ADC12CTL0 = ADC12ON|ADC12SHT03|ADC12REFON|ADC12REF2_5V| ADC12MSC;
    // Turn on ADC12, Sampling time
    // On Reference Generator and set to
    // 2.5V
    ADC12CTL1 = ADC12SHP|ADC12CONSEQ_1; // Use sampling timer, single sequence
    ADC12CTL2 = ADC12RES_2 |ADC12REFOUT; //ADC12_A resolution 12 bit
    ADC12CTL2 = ADC12RES_2 |ADC12SR; //ADC12_A resolution 12 bit
    ADC12MCTL0 = ADC12INCH_0 |ADC12SREF_1; // ref+=AVcc, channel = A0, Vr+=Vref+ and Vr-=AVss
    ADC12MCTL1 = ADC12INCH_1 |ADC12SREF_1; // ref+=AVcc, channel = A1, Vr+=Vref+ and Vr-=AVss
    ADC12MCTL2 = ADC12INCH_2 |ADC12EOS | ADC12SREF_1; // ref+=AVcc, channel = A2,
    ADC12CTL0 |= ADC12ENC;

    Please help me to find out the solution of the problem.
  • I do not see anything particularly wrong with the code. There could still be a hardware issue present here (you should have a delay for your reference to start). Is it possible for you to share your schematic? Try to run examples msp430f665x_adc_[02,09].c and see if these result in the same variance. Increase your sample-and-hold time if possible. You may need to take an average of multiple samples if you still aren't getting the desired results.

    Regards,
    Ryan
  • hello Ryan,

    Sorry i can not share the schematic but I am using a resistance of 165 ohm in series to the sensor's output to convert a 4-20mA current  to voltage of max up to 3.3V. This voltage is given to microcontroller's P6.2 pin directly.

    I have checked the current  received from the sensor and converted voltage which goes into micro controller. Current and converter voltage is fixed at a certain height.

    I don't see any problem with the circuit then why my count values are varying.

  • Have you measured the voltage of the input pin for variance when the ADC is operational? You may require a voltage follower or other external circuitry to avoid impedance mismatch, among other possible issues. Have you referred to SLAY030, TIDA-00648 or TIDA-0095? e2e.ti.com/.../279996

    Regards,
    Ryan
  • Hello Ryan,

    I have checked voltage reading on adc pin of controller and it is not fluctuating. I have also tried the voltage follower circuitry before MCU. 

    I am not getting stable values, what are the other option i can use to get the stable values . 

    Is there any software issue?

  • Hi Shaifali,

    I do not see any software issues but you can evaluate TI code examples to see if these produce similar voltage deltas. Are you using the ADC12/REF calibration reference values from the TLV? What reference setup works better, VCC or the 2.5 V internal Vref?

    Regards,
    Ryan
  • hello,

    I have tried all the codes related to adc on three different hardwares. I have done averaging of 2000 values but deviation in the count is still there and it is large (sometime 4 or sometime it comes 18) Is there any circuit recommended for adc ?

  • Hello Shaifali,

    10 uF + 100 nF capacitors are recommended at each VCC pin, plus the same capacitance at VREF if using an external reference. You may require a higher-resolution peripheral such as the SD24 found on MSP430I20xx/MSP430F67xx devices to achieve the accuracy you require.

    www.ti.com/.../slaa694a.pdf
    www.ti.com/.../TIDM-SERVER-PWR-MON

    Regards,
    Ryan
  • I think your issue is related to hardware. Noise is something that you can never fully remove. It is just part of the real world of physics. What you should consider is the acceptable level of noise. Once you determine that level, you will need to look into all noise contributors in your circuit. Once you have them identified, you can design filters (or even modify the SNR) to make better readings.
    Hint: this involves more than just adding capacitors at the ADC inputs of the MCU.

**Attention** This is a public forum