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.

MSP430 How to set ADC12 Sampling rate

Other Parts Discussed in Thread: MSP430F2619

Hi,

I'm trying to set my ADC to sample at a 40kHz frequency. I saw I should use the timers to do so, so I set the Timer A for 40kHz.

Im not sure if I didn't get to set the timer A in the good way or if its my ADC's configurations that are wrong. The output in Pin 1.0 which I toggle to see the sampling rate is at 27,7kHz...

 Im using IAR.

Could you please get a look into my code and point the errors?

#include  <msp430F2619.h>
#include <msp430.h>
// Global variables
int adc[10] = {0}; //Sets up an array of 10 integers and zero's the values
int avg_adc = 0; int i=0; unsigned int timerCount = 0;

 
// Function prototypes
void adc_Setup();
void adc_Sam10();
 
void main()
{
   WDTCTL = WDTPW + WDTHOLD;   // Stop WDT
          BCSCTL1 = CALBC1_1MHZ;   // Set range  
          DCOCTL = CALDCO_1MHZ;
          BCSCTL2 &= ~(DIVS_3);   // SMCLK = DCO = 1MHz
         
          TACCTL0 = CCIE; //Timer A config
          TACTL = TASSEL_2 + MC_1;
          CCR0 = 25;
         
         
          P5SEL |= BIT5;
          P5DIR |= BIT5;
         
          
          P6SEL |= BIT3;     // ADC input pin P6.3
          P1DIR |= BIT1 
          P1OUT |= BIT1;


          adc_Setup();      // Fucntion call for adc_setup
          
        
          
 
   while(1)
   {       P1OUT ^= BIT1;                //to measure frequence of sampling
            adc_Sam10();  // Function call for adc_samp
                  
                  
   }
}
 
// ADC10 interrupt service routine
#pragma vector=ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{
  __bic_SR_register_on_exit(CPUOFF);        // Clear CPUOFF bit from 0(SR)
}

 
// ADC set-up function
void adc_Setup()
{
        ADC12MCTL0 = INCH_3 + SREF_0;
        ADC12CTL1 = CONSEQ_2 + INCH_3 + CSTARTADD_0 + SHP + SHS1 + ADC12SSEL_0;
        ADC12CTL0 = INCH_3 + ADC12ON + MSC + SHT0_0;

}
 
// ADC sample conversion function
void adc_Sam10()
{
    ADC12CTL0 |= ENC + ADC12SC;  // Enable Conversion and conversion start 
  
   
}

  • Barbara,

    Among other issues involving incorrect ADC initialization and neglect to use the timer trigger, you never enable interrupts or enter LPM0. Your code is looping continuously without being triggered by a timer or waiting for the ADC to complete conversions. Please review the MSP430x261x_adc12_11.c example provided by TI: www.ti.com/.../slac151

    Regards,
    Ryan

**Attention** This is a public forum