Jump to content
43oh

Recommended Posts

hi everyone, 

 

i'm sampling from single channel ADC and send the data over UART. 

now i need to two channel simultaneously and send the data.

 

for one channel my code is below:

-----------------------------------------------

 ADC10CTL1 = INCH_5 + ADC10DIV_3 ;         // Channel 5, ADC10CLK/4
 ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;  //Vcc & Vss as reference
 ADC10AE0 |= BIT5;

 ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start, single measure! 

 

while(1)           {
      if(!((P1IN & BUTTON)==BUTTON)) 
      {
         ADC10CTL0 |= ENC + ADC10SC;
         value1 = ADC10MEM>>2; // used only 8 bits of 10bits adc conversion...
 while ((UCA0STAT & UCBUSY)); // Wait if line TX/RX module is busy with data
         UCA0TXBUF = value1;
              }
  }
}
-------------------------------------------------

can you please help me to make following changes...

 

i need to use p1.4 and p1.5 for ADC conversion (two channel), and the ADC referance voltage should be 2.5V or lower.

 

thank you all...

Link to post
Share on other sites

 

Look at this example, you will only need to make few small changes.

ADC10CTL1 = INCH_5 + CONSEQ_1;
ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;
ADC10DTC1 = 0x02;
ADC10AE0 |= 0x30;

 

Thank you a lot RobG! it worked pretty well...

Here is my code who needs to see....

 

 

 

#include  <msp430g2553.h> // System define for the micro that I am using
 
#define RXD        BIT1 // Check your launchpad rev to make sure this is the case. Set jumpers to hardware uart.
#define TXD        BIT2 // TXD with respect to what your sending to the computer. Sent data will appear on this line
#define BUTTON     BIT3
 
unsigned int adcValues[2] = {0,0}; // ADC buffer
 
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;         // Stop Watch dog timer
 
BCSCTL1 = CALBC1_16MHZ;
DCOCTL = CALDCO_16MHZ;
 
P1DIR &=~BUTTON;                  // Ensure button is input (sets a 0 in P1DIR register at location BIT3)
 
P1OUT |=  BUTTON;                 // Enables pullup resistor on button
P1REN |=  BUTTON;
 
P1SEL = RXD + TXD ;               // Select TX and RX functionality for P1.1 & P1.2
P1SEL2 = RXD + TXD ;              //
UCA0CTL1 |= UCSSEL_2;             // Have USCI use System Master Clock: AKA core clk 16MHz
 
UCA0BR0 = 130;                    // 16 MHz 9600, see user manual
UCA0BR1 = 6;                      //
 
UCA0MCTL = UCBRS0;                // Modulation UCBRSx = 1
UCA0CTL1 &= ~UCSWRST;             // Start USCI state machine
 
// Set ADC
ADC10CTL1 = INCH_5 + CONSEQ_1;
ADC10CTL0 = SREF_1 + REFON + ADC10SHT_2 + MSC + ADC10ON + ADC10IE;
ADC10DTC1 = 0x02;
ADC10AE0 |= 0x30;
 
while (1)
{
if ( ! ((P1IN & BUTTON) == BUTTON)) // Was button pressed?
{
ADC10CTL0 &= ~ENC;
while (ADC10CTL1 & BUSY);
 
ADC10SA = (unsigned int)adcValues;
ADC10CTL0 |= ENC + ADC10SC;
 
while ((UCA0STAT & UCBUSY)); // Wait if line TX/RX module is busy with data
UCA0TXBUF = adcValues[0];
while ((UCA0STAT & UCBUSY)); // Wait if line TX/RX module is busy with data
UCA0TXBUF = adcValues[1];
}
}
}
 
// ADC10 interrupt service routine
#pragma vector = ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF);        // Clear CPUOFF bit from 0(SR)
}
Link to post
Share on other sites

Show also this example:

#include <msp430g2553.h>

unsigned int adcValues[6] = { 0, 0, 0, 0, 0, 0 };

void main(void) {
  WDTCTL = WDTPW + WDTHOLD; // Stop WDT

  BCSCTL1 = CALBC1_1MHZ;
  DCOCTL = CALDCO_1MHZ;

  P2DIR |= BIT2;
  P2OUT &= ~BIT2;

  ADC10CTL1 = INCH_5 + CONSEQ_1;
  ADC10CTL0 = ADC10SHT_2 + MSC + ADC10ON + ADC10IE;
  ADC10DTC1 = 0x06;
  ADC10AE0 |= 0x3F;

  CCTL0 = CCIE; // CCR0 interrupt enabled
  CCR0 = 180; // sample every ~1.5ms
  TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, upmode

  _bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}

// Timer A0 interrupt service routine
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A(void) {

  ADC10CTL0 &= ~ENC; // disable conversion
  while (ADC10CTL1 & BUSY)
    // make sure ADC is done
    ;
  ADC10SA = (unsigned int) &adcValues[0]; // set data buffer start address
  ADC10CTL0 |= ENC + ADC10SC; // start sampling and conversion
}

// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void) {

  //ADC is done, do something with adcValues

  if (adcValues[0] > 500) { // A5 is in adcValues[0], A0 in adcValues[5]
    P2OUT |= BIT2;
  } else {
    P2OUT &= ~BIT2;
  }
}
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...