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.

Adding one more ADC channel to read inaddition to current channel



Hello,

I am currently sampling the sensor1 data with a ADC channel as shown below in the code with sampling at 500Hz and sensing data after collecting 500 samples in 1 sec through uart.

#include <msp430.h>
#define Smclk 1048576u /* default frequency */
#define Size 500 /* size of result buffer */

__no_init volatile unsigned results[Size];
volatile int oldest = 0;
volatile int filled = 0;

int _system_pre_init(void)
{
   WDTCTL = WDTPW | WDTHOLD;
   return(1);
}

void main( void )
{

// Initialize ADC12_A to sample internal-temperature-sensor
  REFCTL0 = REFMSTR + REFON;
  ADC12CTL0 = ADC12SHT0_4 + ADC12REFON + ADC12ON;
  ADC12CTL1 = ADC12SHS_1 + ADC12SHP + ADC12CONSEQ_2;
  ADC12CTL2 = ADC12PDIV + ADC12RES_2;
  ADC12MCTL0 = ADC12SREF_1 + ADC12INCH_10;
  P2SEL = BIT2;
  ADC12IE = ADC12IE0;
  ADC12CTL0 |= ADC12ENC;

// Set up TA0CC1 to generate a 500 Hz square wave to start ADC12 conversion
  TA0CCR0 = Smclk/(500) - 1;
  TA0CCR1 = TA0CCR0 - 20;
  TA0CCTL1 = OUTMOD_3;
  TA0CTL = TASSEL_2 + MC_1;

  while (1)
  {
    __bis_SR_register(CPUOFF + GIE);

// Do data processing here
// The oldest result is in results[oldest]
//   ...   ...  ...  ...
//   ...   ...  ...  ...
//   ...   ...  ...  ...
// This must be accomplished well within 2 msec.
// You may need to increase the core voltage and speed up MCLK

  }
}

#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR(void)
{
 if (oldest == 499)
           {
          oldest= 0;
           }
          else
          {
              oldest=oldest+1;
          }
      results[oldest]=ADC12MEM0;
    __bic_SR_register_on_exit(CPUOFF);
}

Now, I want to read data of  sensor2.The sensor1 and sensor2 will be collecting the pulse signals from different locations so I  need a method to simultaneoulsy (or any other similar method) to read  sensor1 and sensor2 so that I can check the variation of the pulse signals at different locations after obtaining the both.

Thanks.

  • stefan 12 said:
    I  need a method to simultaneoulsy (or any other similar method) to read  sensor1 and sensor2

    You can't simultaneously measure two sources using single ADC, you can measure them sequentially. What you shall do - run ADC twice as fast, 1000 samples/sec and switch input after each conversion.

  • you mean usage of single ADC channel for measuring two sources needs switching of inputs.

    1)Can you explain a bit of how to accomplish the switching between the inputs.

    2)Can I use two ADC channel  for measuring two sources.

    Can I know which one is the best way to use and what will be the difference between the two.

    Thanks.

  • stefan 12 said:
    you mean usage of single ADC channel for measuring two sources needs switching of inputs.

    No, that'll be a pain to do... unless you got a multiplexer chip, which would be a waste.

    Use two ADC channels instead. One for each sensor.

    There is a sample code in CCS about how to read from multiple ADC channel.

    You should look into that :)

  • I searched in CC430F5137   TI resource explorer but was not able to find sample code in CCS for reading mutltiple ADc channel.

  • stefan 12 said:
    I searched in CC430F5137   TI resource explorer but was not able to find sample code in CCS for reading mutltiple ADc channel.

    Check source Code examples: http://www.ti.com/lit/zip/slac458

    File: cc430x513x_adc12_09.c

  • Example for configuration of ADCTL for “Sequence of channel”:
     
    void AD_Init(void)
    {
           ADC10CTL0 = SREF_0+ADC10SHT_0+ADC10ON;  //Vcc is Voltagereference, AD On
           ADC10CTL1 = INCH_15+CONSEQ_1;                  //Highest Channe is A15, Sequence of channels conversion
           ADC10AE0 = 0xD8;                                      //A3, A4, A6, A7 active as AD-Input
           ADC10AE1 = 0xF0;                                      //A12, A13, A14, A15 actvie as AD-Input
    }
    Example for getting the values from the AD-Ins:
     
    void AD_Collect(unsigned short* vector)
    {
           unsigned char n;
           unsigned short vector_temp[16];
           ADC10CTL0 |= ENC;          //Conversion enabled
           for(n=16;n!=0;n--)                                    //Sequential reading of all AD-Ins - As highest In is A15, MC is reading 16 Times for 8 AD-Ins
           {
                 ADC10CTL0 |= ADC10SC;                          //Trigger for Conversion
                 ADC10CTL0 &= ~ADC10SC;                         //Reset Tigger
                 while((ADC10CTL0&ADC10IFG) == 0);       //wait until conversion is finished
                 ADC10CTL0 &= ~ADC10IFG;                        //Reset Interrupt Flag
                 vector_temp[n-1] = ADC10MEM;                          //Put value to vector
           }
     
           ADC10CTL0 &= !ENC;
     
    You can only choose the highest channel. Thus if you cannot use AD0 and AD1 but for example AD0 and AD5 you get the values up to AD5 and waste AD1-AD4 afterwards.
     
  • Innocentio Loe said:
    No, that'll be a pain to do... unless you got a multiplexer chip, which would be a waste.

    Actually, the MSP has a multiplexer built-in. This is how the different input channels are done. (except for a few MSPs with SD16/SD24 which have multiple one-channel ADCs instead of one with multiplexed inputs - those are explicitly designed for simultaneous sampling of voltage and current)

**Attention** This is a public forum