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.

2 ADC channels for msp432

Hi guys,

I want to read in 2 ADC channels and afterwards calculating the difference between them.

My actual status is, I read in 1 ADC channel with an ADC interrupt which is started by a timer interrupt (every 5s) and now I want to update my project on a second ADC input.

Do I have to configure a second interrupt or could I use the differential mode when i configuring the ADC, for the first time?


Thanks,

Chris

  • Hi Christoph!

    You can do both, of course. You could configure another channel and read in both in a sequence, setting a flag inside the ISR signaling that there are new results and then process them to get the difference. But if the device is capable of doing differential measurements, why not use it.

    Dennis
  • Hi Dennis,

    thank you for your fast answer.

    But when I configure a second input channel how could I read out the information of the both seperated inputs from the ADC?

    For one input channel I use this, but I don't know how to go on with 2 inputs.

    wert=ADC14MEM0;                     //write ADC value to variable wert

  • Hi Christoph!

    You can configure a second channel and assign it to ADC14MEM1, for example. Or you can change the input multiplexer after reading the first channel so that your second channel is then written into ADC14MEM0 as well.

    Like this:

    1) Configure ADC to write channel 1 into ADC14MEM0
    2) Sample
    3) Inside ISR save result to a variable and change input multiplexer to write channel 2 into ADC14MEM0
    4) Sample
    5) Inside ISR save result to another variable and set a flag that there are two new results which can be processed now
    6) Inside the main() check for the flag and process data
    7) If processed, go to 1)

    Just as an idea. But you could also have a look into the user's guide on how to sample a sequence of channels.

    Dennis
  • hi dennis,
    I tried it like you suggested for the wheatstone measurement. The 2 inputs have the same voltage so the differential voltage has to be 0. When I read in the 2 inputs in differential mode I got a higher value (2020 as int) than when I read in 1 of the 2 inputs (700 as int). Could it be when eg. A1-A2. (A2>A1) and so the difference is negative or what could it be?
    I also used the analog inputs which are mentioned in the ADC14INCH_x.
  • Could you please show your initialization of the ADC module and add a schematic of your connections?
  • void ADCConfig(void)
    {
        ADC14CTL0 = ADC14SHT0_2 | ADC14SHP | ADC14ON;          // Sampling time, S&H=16, ADC14 on
        ADC14CTL1 = ADC14RES_2;                   // Use sampling timer, 12-bit conversion results
    
        ADC14MCTL0 |= ADC14INCH_2 | ADC14DIF;         
    
    
    }
     //GPIO Config
    P5SEL1 |= BIT3 | BIT2;                    // Configure P5.3/2 (A2/3) for ADC
    P5SEL0 |= BIT3 | BIT2;

  • But when I didn't connect anything to the 2 inputs I got the same results as when I connected it to the wheatstone measurement.
  • What happens if you short the two inputs or connect both to GND or VCC?

  • Your configuration looks OK to me. Can you show the rest of the code? Keep in mind that the ADC result is binary unsigned, means it has an offset of 8192 (at 14 bits).

    Dennis

  • I didn't check this yesterday.
    ok but when it has an offset of 8192 how it is possible that 1 channel has a value of nearly 800?
  • What does "1 channel" mean? What are you doing with the second channel while you feed a voltage into the first one?
  • As preparation I didn't wire anything to the board and read in A2 and A3.
    Afterwards I wired like shown in the figure above and then I got nearly 2000 for the ADCMEM0 value for the Uab in the wheatstone measurement, but it has to be 0V and therefore I thought nearly 0 for the integer value.
  • You can not leave one channel unconnected. Floating inputs pick up any crap from the surrounding. So when measuring differential and have one input unconnected, you will definitely get a wrong result. You can tie it to GND (Vref-) or VCC (Vref+) instead.

  • Yeah you're right, I forgot the floating inputs.
    So when I connect both inputs of ADC to GND or VCC the difference should be 0 and the ADCMEM0 should be 0 as well.
    But I don't know that the difference value is nearly 2000 when I connect it to the wheatstone measurement and you told that the offset is 8192.
    Thats a little bit confusing ;)
  • When both inputs are the same you have 8192 as result. When the negative input is higher than the positive, your output decreases down to a minimum of 0. If the positive input is higher than the negative one, your output increases up to a maximum of 16383. This is for full 14 bits of resolution.

    If you use 12 bit conversion resolution, what you do by setting ADC14RES_2,

    ADC14CTL1 = ADC14RES_2; // Use sampling timer, 12-bit conversion results

    your maximum value is 4095 and your midscale is 2048. So your result of nearly 2000 looks OK if your bridge is in balance.

    Dennis

  • ok than I had a error in my thoughts, because I meant that when both inputs have the same value the have the same value on the ADC input.
    And when the ADC is in the differential mode the ADCMEM0 = A2-A1 and I expected 0 or nearly 0.
  • Your thoughts aren't entirely wrong, except the result has an offset of the midscale of your resolution. You can switch the output of the result to signed binary (2's complement). This is done by setting the ADC14DF bit in ADC14CTL1.
  • Ok so when I want to calculate with this value I have to substract 2048 of this value to get the right value.
    But I don't have to respect the offset when I use only 1 input, without ADCDIF or am I wrong?
  • This is just a point of view. If you subtract 2048 from each result, you have -2048 for negative full-scale and +2047 for positive full-scale and in single-ended mode your result is 0 to 4095 (in 12 bit mode).

  • I didn't want to substract 2048 from each result but only for the ADCMEM0, so 0V is 0 for the ADCMEM register. (when I don't look on the polarity)
    And when I want to know if it is a positive or a negative result I have to use the version like you suggested.
  • Yes, we are talking about the same. With "from each result" I mean subtracting 2048 from the MEM register (which is the result of the differential measurement). And by doing so, you get 0 (int) for 0V difference.
  • Now I have found the table with the needed data also in the family user guide.
    But I have to say thank you for support, thanks dennis ;)
  • No problem at all - happy differential measuring!
  • hey dennis,
    I want to use more channels for the ADC.
    How could I configure and use the ADC with the multiplexer?
    Thanks

**Attention** This is a public forum