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.

ADC10 usage for MSP430f2274

Other Parts Discussed in Thread: MSP430F2274

Hi,

I have some questions regarding about the ADC10 usage of MSP430f2274.

1)

In my case, I have 3 analog inputs I need to process continuously. Apparently, the analog inputs converted by the microcontroller do not behave as expected.

The following code is placed inside a while loop. Is this the correct way to process 3 different inputs? Is this known as the  'Single-Channel Single-Conversion Mode'? Or should I use 'Sequence-of-Channel Mode' to handle it?

ADC10CTL1 = INCH_0;                      // A0
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;
for(temp = 10; temp > 0; temp-- );      // delay to allow reference to settle
ADC10CTL0 |= ENC + ADC10SC;              // Start to perform sampling and conversion
for(temp = 10; temp > 0; temp-- );      // delay to allow reference to settle
value1= ADC10MEM;
   
ADC10CTL0 &= ~ENC;

ADC10CTL1 = INCH_1;                      // A1
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;
for(temp = 50; temp > 0; temp-- );      // delay to allow reference to settle
ADC10CTL0 |= ENC + ADC10SC;              // Start to perform sampling and conversion
for(temp = 50; temp > 0; temp-- );      // delay to allow reference to settle
value2 = ADC10MEM;

ADC10CTL0 &= ~ENC;

ADC10CTL1 = INCH_2;                      // A2
ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;
for(temp = 10; temp > 0; temp-- );      // delay to allow reference to settle
ADC10CTL0 |= ENC + ADC10SC;              // Start to perform sampling and conversion
for(temp = 10; temp > 0; temp-- );      // delay to allow reference to settle
value3 = ADC10MEM;
   
ADC10CTL0 &= ~ENC;

 

2)

Is it necessary to use the DTC to transfer conversion results from ADC10MEM? As you can see, I am using value1, value2 and value3 to transfer from ADC10MEM.

 

3)

Is it necessary to use following line of code while handling ADC10? I am only using A0, A1 and A2 for the inputs.

ADC10AE0 |= 0x07;

When I leave this line of code out, apparently, ADC can still be performed providing that I give:

P2DIR = 0x00;
P2OUT = 0x00;
P2SEL |= 0x00; 

From what I understand, ADC10AE0 |= 0x07; should be coded and P2DIR and P2SEL are 'don't care' when handling ADC10.

 

4)

Can someone explain what are the operators |= and &= ?

 

Any help is appreciated! I am stuck at this for a week already.

Thanks!

  • You do not need to use DTC, but you do need to allow the conversions to complete before you read ADC10MEM. Monitor the BUSY flag.

    Google "C language operators" to answer #4.

  • Hi Hek Liu:

    As mentioned in Wiki |= and &= are 'bitwise operators.'

    They are used to raise and lower single or more bits in any given byte and operate like this:

    |= is used to raise bits.  If a given bit in your target byte/word is 0 and you want to make it 1 then you present your raised bit (within a byte or word that is otherwise filled with zeros) and the machine or's it with your target byte or word.

    Since the target bit OR your '1' bit will result in a one the corresponding bit in the target byte/word is raised, is set to '1' just as you wanted.  No other bits in the target byte/word are changed.

    &= is used to lower or drop bits that are already raised (are in the 1 state).  If your bit is zero (in a byte/word which is otherwise full of ones) and the target bit is one, 1 AND 0 together will give a 0 in that target bit place and the bit is dropped.

    It is possible to raise or lower several bits at once with this move but you have to account for which bits are doing what very carefully or you can change other bits than you intend.

    The MSP430 and other TI chips use many different individual bits to control single functions like turning on the ADC and it's REF, etc.  Thus you will find yourself using these two operators fairly frequently.

    This 'C' line of yours:  ADC10CTL0 = SREF_1 + ADC10SHT_2 + REFON + ADC10ON + ADC10IE + REF2_5V;

    Is another way of setting individual and combinations of bits as it sets bits to one and enables the reference voltage source, turns on the ADC, enables the ADC interrupt and sets the exact REF voltage.  Eventually this 'C' line evolves into a fancy |=.  Turning everything off again likely goes to a carefully coded &=.

    The other frequently used bitwise operator is ^=.  This is the XOR operator.  It is used to flip bits to the opposite state no matter what state they are in before the command is given.  Note that in some '430 examples ^= is used to turn the LED on Dev boards on and off without caring whether it is on or off before the command.  That causes the LED to blink on and off from a single command.  Whatever state the bit is in to start with, 1 or 0, it is left in the opposite state after an ^= is run.  Again be careful to consider the whole byte/word when doing this so you don't change other bits accidentally.  

    Larry

  • I have had to reset the control registers between sampling a single channel to switch channels, not the right answer but it works. // Configure & sample INCH_0;

    ADC10CTL0 = 0;

    ADC10CTL1 = 0;

    //Configure & sample INCH_1;

    etc

    **********************

     Inside your interupt handler you can put a check to determine which input you are watching to direct your output

    if (ADC10CTL1 & INCH_0) // DO stuff for A0

    if (ADC10CTL1 & INCH_1) // DO stuff for A1

    if (ADC10CTL1 & INCH_2 // DO stuff for A2

     *****************

    |= is a bitwise "OR" P2OUT |= 0x02; is the same as P2OUT = P2OUT | 0x02;  its just a shorter notation, similar to the XXX++ usage for increment

    &= is likewise a "AND" function

  • Hi,

    if you want to have a look at an example showing the use of ADC10 and its DTC you may have a look at an example which I've uploaded to 'My Files' (http://e2e.ti.com/members/1371069/files/MSP430-16x2-LCD-Routines.zip.aspx). It sample P2.0 and P2.1 four times each; ADC results were handled by DTC.

    The example will work even if you don't comment out all the LCD related stuff (since this example is a for showing how to drive a 16x2 LCD using an MSP430). I think the code is well documented so you should have no problem in understanding it.

    Rgds
    aBUGSworstnightmare

  • Hi,

    The file you uploaded is moved. Can you please re-upload it? I specifically want to learn the LCD part.

    Thanks.

  • restlesssoul said:
    The file you uploaded is moved. Can you please re-upload it?

    Clock on his name, then on his files list and you'll find the files he has uploaded, independently of any path changes or updates:

    http://e2e.ti.com/members/1371069/files/MSP430-16x2-LCD-Routines_5F00_-usefull-Docu.zip.aspx

    Is likely what you are looking for.

  • Hi restlesssoul,

    Jens-Michael pointed you to the right direction already! I've added some information (data sheets on supported controllers) in the past and because of that the (old) link is no longer working.

    Rgds
    aBUGSworstnightmare

  • Thank you guys, I really appreciate your prompt response. I will look at these files.

  • 1)  The Efficient code written by you is good.But we can turn it into switch Loop also. your code size may be decreased.

            a) See that the above input voltage is maintained exactly  from the source(For ADC Sensing) & also please refer the reference voltage should be constant

         every-time.

           ---> Iam also using the same for different ADC's .But i used this with the help of a simple ADC Function in switch case for single sample for all ADC Values we read initally as to protect my device from failure.

     2)   No,  we can use the our global variable to store the value for continuous refering.

    3) We can use any one which we wish and find working perfectly.

    4)  The operator |= is used to increment the value in the register value to already exist value.

          &= operator is used to disable the value  to 0x0 so as to gain new value into the register used internally.

      *** You may mail to ravikumar.hotha@yahoo.co.in to resolve ur queries further.

     

**Attention** This is a public forum