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.

CCS/MSP430G2553: ADC Sequencing Issue

Part Number: MSP430G2553

Tool/software: Code Composer Studio

Hello,

I am unable to understand issue in my code and due to that I am not getting proper ADC count.

Hardware configuration:

  1. MCU MSP430G2553 is running at 1MHZ.
  2. A1,A2,A3 are ADC inputs (P1.1,P1.2, P1.3)
  3. Applied 2.4VDC at A1 pin.
  4. ADC reference voltage is same as supply voltage.

Code:

#include <msp430.h>
#include "main.h"
#include <stdint.h>

unsigned int ADC[10];

int main(void)
{
	// Clock-------------------------------------------------------------------------------
	WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
	  if (CALBC1_1MHZ==0xFF)		      // If calibration constant erased
	       {
	          while(1);                            // do not load, trap CPU!!
	       }
	DCOCTL = 0;
	BCSCTL1 = CALBC1_1MHZ;		// Set range
	DCOCTL = CALDCO_1MHZ;
	BCSCTL2 &= ~(DIVS_3);			// SMCLK = DCO = 1MHz


//ADC ------------------------------------------------------------------------------------

	ADC10CTL1 =INCH_3+CONSEQ_1 +ADC10SSEL_3;
	ADC10CTL0 =SREF_0 + ADC10SHT_0 + MSC+ ADC10ON + ADC10IE;
	ADC10AE0 |= 0x0E;                    
	ADC10DTC1 = 3;			                            // Three conversions.
	ADC10SA = ADC;                                      // ADC10 data transfer starting address.
	while (ADC10CTL1 & ADC10BUSY);              		// Wait if ADC10 core is active
	ADC10CTL0 |=ENC + ADC10SC;          				//start conversation
	
	while(1);
}


// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
	ADC10CTL0 &= ~ADC10IFG;       	 // clear interrupt flag
	ADC10SA = ADC;     				// ADC10 data transfer starting address.
	ADC10CTL0 |=ENC + ADC10SC;       //start conversation
}

Result:

ADC[0]=34 

ADC[1]=35

ADC[2]=167

Questions:

1. If I am applying 2.4volt then why I am not getting equivalent count 2.4*1023/3= 818? What is missing in my configuration? Please guide.

2. Will this ADC array store value in sequence for used channel only like ADC[0]= count for A1 channel, ADC[1]= count for A2 channel and so on? Or it will always start from A0 (even if I am not using)?

Please guide.

Thanks.

  • I missed one line in code:
    __enable_interrupt(); // Enable interrupts.
    while(1);
    Please consider it and it will be really helpful if you can provide suggestions to fix the above issue.

    Thanks
  • Hi Krunal,

    I would suggest you to take the code examples as reference. A code for single sequence mode is here: dev.ti.com/.../

    You can firstly run this code and then modify for your channel and configuration.
  • Hello Wei,

    I have tested it and it is working fine but I am interested in non blocking method i.e using interrupt. Can you please guide me how to do the same thing using interrupt.

    Thanks
  • 1) (a) If this is a Launchpad: How do you have the J4 ("bridge") jumpers, particularly RXD/TXD, set? (b) Your SHT is quite short (4usec), which might not give the sampling capacitor enough time. Run the formula in SLAU144J Sec 22.2.5.1 and/or just increase SHT and see what happens.

    2) The ADC (in the Sequence modes) counts down from INCH, so ADC[0] = A3, ADC[1] = A2, ADC[2] = A1. It will convert A0, but since DTC1=3 the result will sit quietly in ADC10MEM and be forgotten. This is one of those "happens to work" things, at the intersection of SLAU144J Figs 22-6 and 22-10; one consequence is that when you get to the ISR the ADC may or may not have finished. I suggest you set DTC1=4 (adopt ADC[3]) to assure ADC10IFG means what you intend.
  • Thanks for the explanation, now it is more clear and getting ADC counts within range.

    After considering previous feedback, still I have one problem related to memory address in which resultant value (i.e. 800) is shifting to another memory location.

    My expected result is as below and if i do single step debugging it is working fine.

    ADC[0]=0;

    ADC[1]=0;

    ADC[2]=800;

    ADC[3]=0;

    If I do free run and pause the debugging. I am getting

    ADC[0]=800;

    ADC[1]=0;

    ADC[2]=800;

    ADC[3]=0;

    Or

    ADC[0]=0;

    ADC[1]=800;

    ADC[2]=800;

    ADC[3]=0;

    What could be the reason? please guide.

    Thanks for help.

  • I've also observed this in the F2, and I'm pretty sure it has to do with some clocks being stopped at a breakpoint and some not. MCLK is certainly stopped at a breakpoint, and the DTC is dependent on it. If the ADC clock (I usually use ADC10OSC, but this is probably also true of SMCLK) keeps running while you're at a breakpoint, the ADC will overrun ADC10MEM and when the DTC (MCLK) starts again it will be looking at the "wrong" value.

    Since the DTC is reset every time you assign ADC10SA (see also SLAU144J Fig 22-10), it ought to correct itself the next time around.

    This effect becomes more noticeable if the ADC is running all the time (high probability of a breakpoint while it's running); in my applications this is a rarity, rather my ADC sampling is fixed-rate (timer based) with a relatively large amount of slack time between samples.

**Attention** This is a public forum