Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed from November 25 through December 2. Thank you for your patience.

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.

MSP430G2553 - 3 chanel ADC + Grace - Question

Hi everyone,

I need some help in my implementation. So far I can read value from the ADC10MEM reg. However, I need to read 3 pins (A0, A1 and A2). I configured the ADC whith the help of a Grace project and my configuration is the following:

ADC10CTL0 &= ~ENC;

ADC10CTL0 = ADC10IE + ADC10ON + ADC10SHT_2 + SREF_0;

 ADC10CTL1 = CONSEQ_1 + ADC10SSEL_2 + ADC10DIV_0 + SHS_0 + INCH_2;

ADC10AE0 = 0x7;

ADC10DTC0 = ADC10TB + ADC10CT;

ADC10DTC1 = 3;

 ADC10CTL0 |= ENC;

#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR_HOOK(void)
{
__bic_SR_register_on_exit(CPUOFF);
}

I attempt to use the ADC like this:

unsigned int values[3];

int main(void)

{
Grace_init(); // Activate Grace-generated configuration

while(1)
{
read();
control();
update();
}
}

void read(void)
{
ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & ADC10BUSY);
ADC10SA = values;

ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(CPUOFF + GIE);

}

The control() and update() functions are not important for the moment. Can anyone tell me please how can I read the thee pins successfully? When I try to debug the code as it is implemented, the Code Composer Studio points out an error that says: "A Value Of Type "unsigned int *" can not be assigned to entity of type "unsigned int" ". I know that this error may be caused by me due to lack of knowledge I am better C# programmer that C/C++ and this may be the big problem now. Can anyone provide me with code that can read all the three pins one after another

Furthermore I can provide you with a snap shot of the Grace project where I setup the ADC. Here it is:

  

Please suggest an approach in my scenario.

Thank you for your time and cooperation. 

  • I realize that the Grace project provides me with an example of using the ADC but i dont know what the LPM is and how to use it. Can someone point me in the right direction or provide me with code that can read 3 channels and move the measurements to an array where I can access it? The example says this:

    // ADC Start Conversion - Software trigger
    ADC10CTL0 |= ADC10SC;

    // Enter LPM3 with global interrupts enabled
    __bis_SR_register(LPM3_bits + GIE);

    // Execute the following after exit from LPM from within ADC10 ISR
    // >>>>>>>> Fill-in user code here <<<<<<<<

    // ADC10 Interrupt Handler
    unsigned short ADC10ISRHandler(void)
    {
    // Single sequence of channels conversion complete
    // Conversion results are stored in memort address specified in DTC

    return LPM3_bits; // Exit LPM3 on exiting ISR. Return 0 to remain in LPM.
    }

    But I dont know how to access the array with the measurements and If the measurements are done in correct way. When I try something like this:

    myVar = value[0];

    myVar2 = value[1];

    myVar = value[2];

    It seems that the CPU goes in an infinite loop and can not read the value from the memory. Am I doing something wrong or my C/C++ knowledge  is not enough?

     

  • pavel pavlov said:
    i dont know what the LPM is and how to use it

    LPM stands for Low Power Mode. On first level, LPM0, it stops MCLK, so the CPU instantly freezes. In case of an interrupt, MCLK is reactivated and the ISR is executed. Since the LPM control bits reside in teh processor status register, whcih is saved before entering an ISR, th eprevious LPM state is reactivated when the ISR exits: the CPU freezes again. Unless the ISR calls the intrinsic to exit LPM on ISR exit. (these intrinsics are compiler-specific, so see the compiler documentation).
    The higher LPMs then successively deactivate the DCO (which takes some toem to come up again when an interrupt comes, increasing interrupt latency) powering doen the DCO current source (more delay), shut down the SMCLK clock and finally the ACLK. There are even LPMs (4.5) which shut down the entire MCP except for the port logic, so a port pin interrupt can restart the MSP.

    pavel pavlov said:
    return LPM3_bits; // Exit LPM3 on exiting ISR. Return 0 to remain in LPM.

    Thsi looks strange. An ISR doesn't return anything and returning LPM3_bits won't do anything. So I guess, this funciton is just a subfunciton of the real ISR, adn the return value indicates teh real ISR whether to end LPM on its exit.

    About the ADC10, it is fully described in the MSP430x2xx users guide.

    Basically, you can operate the ADC10 to sample a sequence from channel x down to channel 0. (no way to change the order or to skip a channel!) and you can use the DTC to copy all conversion results to a memory locaiton of your choice (your array). You'll get an interrupt when the specified number of results has been moved by the DTC - which is an independent count of the number of channels the ADC10 will sample, so you need to properly match them.

    There are several threads about the ADC10 in this forum.

**Attention** This is a public forum