Jump to content
43oh

ADC conversion problem


Recommended Posts

Hi!

I need some help with ADC in MSP430g2553, I have 3 buttons which you need to do readings and obtain digital values.

P1.1- Batterry

P1.2-temperature 

P1.4. Pin button Switch

 

In P1.3. Pin Switch button, I have 3 buttons which do the readings each using voltage dividers, but also need to know the load that still exists in the battery and take readings continuously.

how can I do this, since I have to be able to do 3 things at once, but separate values???

#define BATTERY_PIN     BIT1
#define TEMPERAT_PIN    BIT2
#define SWITCH_BUTTON   BIT4

void butonAdc(void)
{
   ADC10CTL1 = INCH_4 + ADC10DIV_0;
   ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;
   ADC10AE0 |= SWITCH_BUTTON;
}



void tempAdc(void)
{
   ADC10CTL1 = INCH_2 + ADC10DIV_0;
   ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;
   ADC10AE0 |= TEMPERAT_PIN;
}

void BattAdc(void)
{
   ADC10CTL1 = INCH_1 + ADC10DIV_0;
   ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;
   ADC10AE0 |= BATTERY_PIN;
}


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

Now how can I read separately each values?

Link to post
Share on other sites

hi biza,

 

define an Array: 

samples[3]

and then :

ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY);
ADC10SA = (unsigned int)samples;
ADC10CTL0 |= ENC + ADC10SC; // ENC = enable conversion, ADC10SC = Sampling and conversion start
__bis_SR_register(CPUOFF + GIE);        // LPM0, ADC10_ISR will force exit

In the interrupt:

#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
  __bic_SR_register_on_exit(CPUOFF);        // Clear CPUOFF bit from 0(SR)
}

and just read the values of samples[0..3]

 

Hope this helps.

Link to post
Share on other sites

You could use a state-machine like behaviour.

Since ADC10AE0 is dependent on which value you're actually reading, (are you sure you want it OR-ed with the pin value?) you could do a switch depending on that value in the interrupt to load the variable with the result.

Just make sure you never have more than one measurement running at the same time (your ADC can only sample a single value, not multiple in parallel).

#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR (void)
{
   __bic_SR_register_on_exit(CPUOFF);
   switch (ADC10AE0 & MASK)
   {
      case BATTERY_PIN:
         // load the adc result into battery variable
         break;

      case TEMPERAT_PIN:
         // load the adc result into temperature variable
         break;

      case SWITCH_BUTTON:
         // load the adc result into button variable
         break;
   }
}
Link to post
Share on other sites

Thank you for answering!

but it's possible obtain all values at same time, because, the temperature values, temperature values ??are read cycle, and it's possible that any time the user interrupts the process of reading through the button

Link to post
Share on other sites

Short answer: No.

 

Longer answer:

The principle of the ADC is that you select which analog input pin you'd like to read, then "store" that value (in a sample and hold circuit inside the ADC). Then the ADC will take a little while to match the digital representation with the held analog voltage.

This means there is no way to convert two values simultaneously unless you have two ADCs (which is different from a single ADC with multiple inputs).

The best way to solve this is to do the conversions very close together, so the samples are close enough to be named simultaneously.

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...