Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

MSP430 Launchpad ADC help

$
0
0

Hi All,

 

I'm fairly new to programming microcontrollers / MSP430's so I apologize if I have missed something very obvious here.

 

Just to give you some background on what I'm trying to achieve here...on start up I want to read a value from the ADC and store it for use as a multiplier later. I only want a single reading on start up then I want to disable the ADC.

 

here is my code so far:

void main(void)       
{


WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer

    P1DIR = 0x41;                             // set P1 bit directions.
    P1OUT &= ~0x01;                           // LED off
    P1SEL = 0x0A;                            // Set P1.1 to TA0 // P1.3 for ADC input.

    BCSCTL1 |= DIVA_3;                        // ACLK/8

  ConfigureAdc();    //Call ADC function for single read...

    CCTL0 = CM_1 + SCS + CCIS_0 + CAP + CCIE; // Rising edge + CCI0A (P1.1)    //set up p1.1interrupt (for input pulse)
                                                                                // + Capture Mode + Interrupt

    TACTL = TASSEL_2 + MC_2;                  // SMCLK + Continuous Mode

    _BIS_SR(LPM0_bits + GIE); // LPM0 + Enable global ints

    while(1){


     //waits in this loop for an interrupt from p1.1 where it then measures length of On pulses and off pulses and calculates duty cycle.


    }
  }



void ConfigureAdc(void)        //ADC single conversion

{


ADC10AE0 |= 0x08; //P1.3 ADC option
ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON; // 16 clock ticks, ADC On, enable ADC interrupt
ADC10CTL1 = ADC10SSEL_3 + INCH_3; // set channel 3, SMCLK
ADC10CTL0 |= ENC + ADC10SC; // Enable and start conversion

ADC_value = ADC10MEM;    //copy value from ADC register to int 'ADC_value'


ADC10CTL0 &= ~ENC;      //disable ADC
               

}

 
Most of the code seems to be working although I'm always getting a reading of 0 from the ADC
 
when I had the ADC conversion as part of my p1.1 signal interrupt loop I could get a reading from it but it was slow. The problem with the conversion being slow is that it can miss the rising or falling edge of a pulse, this is why I want a single conversion on start up (like a calibration multiplier) then I can leave the ADC alone for the rest of the time.
 
can anyone give me a hand with getting the ADC reading to work?
 
Thanks in advance.
 
 

Viewing all articles
Browse latest Browse all 2077

Trending Articles