Jump to content
43oh

ADC changing channels


Recommended Posts

Hi together,

with my MSP430G2553 at a MSP430 Launchpad I managed it, to do some ADC of ONE voltage.

What I have to do, if I want to messure TWO different voltages at the "same time"?

I copied the code for ONE voltage and set it in line after changing the channel, but it doesn't work.

I hope somebody could understand my problem :?

Thanks

Greetings

HeKe

Link to post
Share on other sites

There are two ways you can do this: single channel or sequence.

Single channel - sample first, switch to second, sample second, switch to first, and so on.

Sequence - samples all channels from the one selected by INCHx all way down to channel A0. Each result is written to memory.

The problem with sequence, you must start at A0 and all channels must be consecutive.

 

You will find examples of both methods in this thread.

Link to post
Share on other sites
  • 2 weeks later...

Thanks for your answers, but the problem still exists.

The ADC with each single channels works fine, but when I want to switch in loop from channel 1 to 2 to 1 to 2...

channel 2 has always the value of channel 1! :cry:

void loop() {

ADC10CTL1 = INCH_1+CONSEQ_0; // input A1

ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start

 

U = ADC10MEM * 0.003515625;

 

delayMilliseconds(800);

 

ADC10CTL1 = INCH_2+CONSEQ_0; // input A2

ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start

 

I = ADC10MEM * 3.515625; }

Greetings

HeKe

Link to post
Share on other sites
  • 2 weeks later...

Is that the whole loop? Any chance when you write to U and I the ADC hasn't finished measuring yet? (Depends on your MCLK frequency; looks like you're using the internal ADC clock, ~ 5 MHz, but the sampling takes a few clock cycles If you're using ~1 MHz, you might reach the assignment statement before the ADC is done.) I've been using

while(ADC10CTL1 & ADC10BUSY);

to let the ADC finish measuring before writing the value.

Link to post
Share on other sites
  • 3 years later...

Hmm I am struggling with this one, I am trying ot read 2 different voltage values,
 

for(;
  {
      ADC10CTL1 = INCH_0 + CONSEQ_0;         // Channel 0, 
      ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;  // Vcc & Vss as reference, Sample and hold for 64 Clock cycles, ADC on, ADC interrupt enable
      ADC10AE0 |= BIT0;                         // ADC input enable P1.0
      __delay_cycles(1000);                // Wait for ADC Ref to settle
      ADC10CTL0 |= ENC + ADC10SC;            // Sampling and conversion start
      __bis_SR_register(CPUOFF + GIE);    // Low Power Mode 0 with interrupts enabled
      sensor1 = ADC10MEM;                // Assigns the value held in ADC10MEM to the i

      __delay_cycles(1000);


      ADC10CTL1 = INCH_1 + CONSEQ_0;         // Channel 1
            ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;  // Vcc & Vss as reference, Sample and hold for 64 Clock cycles, ADC on, ADC interrupt enable
            ADC10AE0 |= BIT1;                         // ADC input enable P1.1
            __delay_cycles(1000);                // Wait for ADC Ref to settle
            ADC10CTL0 |= ENC + ADC10SC;            // Sampling and conversion start
            __bis_SR_register(CPUOFF + GIE);    // Low Power Mode 0 with interrupts enabled
            sensor2 = ADC10MEM;                // Assigns the value held in ADC10MEM to the i

            __delay_cycles(1000);

 
With this code sensor1 and sensor2 (IR sensors) changes but simultaneously
 
Where is my mistake ?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...