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.

Reading multi-channels with ADC10

Other Parts Discussed in Thread: MSP430G2231, MSP430G2553

Hello,

I use the MSP430G2231 and I'm trying to get the temperatur and the supply voltage with the ADC10. The measurments are all ok if I measure only one channel but if I use it with the DTC the values from temperature and supply voltage measurment in the arry where i put them are in other places after each conversion.

And if I try to use the ADC without the DTC but with multi-channel i have the same problem. I really do't get what i'm doing wrong.

Here is my code:

#include "msp430x20x2.h"

static unsigned int res[11];

void adc_init(void){
    ADC10CTL0 &= ~ENC;
    ADC10CTL0 = SREF_1 + REFON +  ADC10ON + ADC10SHT_3 + ADC10IE + REF2_5V + MSC + REFBURST;  // use internal ref, turn on 2.5V ref, set samp time = 64 cycles REF2_5V +
    ADC10CTL1 = INCH_11 + CONSEQ_3 + ADC10DIV_1;        //Kanal auswählen; Art der Messung bestimmen;Teiler für ADC
    ADC10DTC0 =  ADC10CT;
    ADC10DTC1 = 0x0B;
    ADC10SA = (int)res;
    ADC10CTL0 &= ~ADC10IFG;
    ADC10CTL0 |= ENC + ADC10SC;;
}

#pragma vector=ADC10_VECTOR
__interrupt void adc10_isr(void) {
    static unsigned int Toffset=11;
    unsigned long temp_V = ((ADC10MEM/ 1024)*2.5);    //Ref 2.5 V Spannungsmessung
    unsigned long temp_C=(((2.5*((float)ADC10MEM + Toffset))/1023)-0.986)/0.00355;    //Temperatur berechnen
      ADC10CTL0 &= ~ADC10IFG;
}

Thanks

  • Thomas Kirchner said:
    unsigned long temp_V = ((ADC10MEM/ 1024)*2.5);    //Ref 2.5 V Spannungsmessung
        unsigned long temp_C=(((2.5*((float)ADC10MEM + Toffset))/1023)-0.986)/0.00355;    //Temperatur berechnen

    ADC can't do two parallel measurements at the same time. In IRQ routine you shall check which exactly channel is measured at the moment - voltage or temperature, then use ADC10MEM value accordingly. One more tip:  unsigned long voltage_mV = ((long)ADC10MEM * 2500) / 1024; Temperature conversion also can be done using fixed point math similar way.

  • From p557 of MSP430 User Guide slau144i:

    "22.2.6.4 Repeat-Sequence-of-Channels Mode
    A sequence of channels is sampled and converted repeatedly. The sequence begins with the channel
    selected by INCHx and decrements to channel A0. Each ADC result is written to ADC10MEM. The
    sequence ends after conversion of channel A0, and the next trigger signal re-starts the sequence.
    Figure 22-8 shows the repeat-sequence-of-channels mode."

    It doesn't look like you can just do Ch11-Ch10 because the sequence will continue to Ch0.

  • What I do know, but my  problem is  that, in my mesurments when it begins by channel 11 and its mesured for example 0x2EA and goes then down to channel A0 it should start when again with the  mesurment and if it didn't change it should again have the value 0x2EA but that isn't the case. Or if I do it with DTC and put the mesurments of all channels in an arry the values of temperature and voltage supply should be on the two first memory locations of the arry.

    Or is my understanding of the DTC wrong?

    If I'm correct while the ADC mesures the values will be first put in the ADC10MEM when transfered in the memory location I defined befor. And triggers an Interrupt when he has finished the mesurment of channel A0. And when starts anew.

  • " ADC10DTC1 = 0x0B;"

    You're transferring 11 conversion results, but the A/D is reading 24. (Edit - Should have said 12) If I'm understanding the state diagram in Fig 22-10 (p560), the last balloon shows that when your count of 11 goes to 0, the ADC10IFG is set to 1, and also the DTC  transitions to the balloon where x=n (i.e. the count is again set to 11, but also the start address is set to the initial value causing the A/D which is still on its way to channel 0 to overwrite data)

  • why does the ADC read 24 conversion results? There are only 11 channel. Could you explain that to me.

  • My mistake. I should have said 12 channels (Ch 11 to Ch 0).

  • OK, but thats unfortunately not the mistake thats causes my problem.

    Is my approach generally right?

    I think if it runs correct the mesurrment of channel 11 must be in the arry memory location [0], that from channel 10 in [1] and so forth. And by the next mesurments it will place the values of the channel mesurments in the same array memory locations.

  • Thomas Kirchner said:

    "I think if it runs correct the mesurrment of channel 11 must be in the arry memory location [0], that from channel 10 in [1] and so forth. And by the next mesurments it will place the values of the channel mesurments in the same array memory locations."

    Edit: Removed my response from the quote;

    The way I see it is that on the first go-around, the 12th A/D measurement (Ch 0) will overwrite the starting (first) ram location after the A/D has completed its first cycle count, then start with CH 11, CH 10, CH 9 ... Ch 2 going in the second, third, fourth, ... eleventh ram positions. Then on the third A/D cycle CH 1, CH0 will overwrite the first, second ram locations, because the remaining memory was filled when the A/D converted Ch 2.  And it will just ripple up with each cycle.

    I set ADC10DTC1 = 12 in your program and I get 722 in res{0] and 439 in res[1] using MSP430g2553 and halting the debugger. Starting the debugger and halting again, I get res[0] = 722, res[1] = 441 which tells me that I'm overwriting the same positions with the same channels.

  • Joseph Raslavsky said:

    "I think if it runs correct the mesurrment of channel 11 must be in the arry memory location [0], that from channel 10 in [1] and so forth. And by the next mesurments it will place the values of the channel mesurments in the same array memory locations."

    I set ADC10DTC1 = 12 in your program and I get 722 in res{0] and 439 in res[1] using MSP430g2553 and halting the debugger. Starting the debugger and halting again, I get res[0] = 722, res[1] = 441 which tells me that I'm overwriting the same positions with the same channels.

    [/quote]

    Now that I've run your program a few more times, I have to correct myself.The first time I stop the debugger I consistently get res[0] ~ 722 and res[1] ~ 441, but after restarting the debugger don't always get the correct overlay of data. Hopefully someone will chime it with an explanation.

  • Joseph Raslavsky said:
    The first time I stop the debugger I consistently get res[0] ~ 722 and res[1] ~ 441, but after restarting the debugger don't always get the correct overlay of data.

    When you stop the CPU with the debugger, this doesn't stop the ADC.

    To do so, you must run the ADC by a system clock rather than its default (unstoppable) ADC10OSC. And even then, it works only on those MSPs which allow clock control by the debugger. And even if you can stop the clock, this will invalidate any result that was currently converting (due to smapling capacitor charge dissipation by leakage currents)

  • Danke.

       I tried using SMCLK for the A/D and going to Project > Properties > Debug > MSP430 Properties > Clock Control and tried both allowing and stopping SMCLK and MCLK  on "Emulation Hold" and the data continued to be skewed in ram after the next Suspend - Resume, although the data maintained their correct relative positions. Just something to be aware of when using the debugger, I guess. I did see somewhere that the MSP430G2553 allowed clock control.

  • Joseph Raslavsky said:
    I did see somewhere that the MSP430G2553 allowed clock control.

    Well, AFAIK, on none of the  MSPs the clock control will include ADC10OSC,  MODOSC or VLO. So if a module uses these instead of SMLK or ACLK, it will always continue running. Same for all modules that are externally clocked (such as SPI slave or UART RX or externally clocked timer)

    You should always be aware that the debugger is intrusive. It will freeze the CPU core on a breakpoint, but not the rest of the world.

**Attention** This is a public forum