MSP430g2553 ADC not working

Status
Not open for further replies.

Elimathew

Member level 5
Joined
Jun 21, 2011
Messages
88
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
India
Activity points
1,894
Hey got my new msp430 lauchpad was working with adc here is simple program to get the analogue value from P1_0(A0) convert it and output it to Port2 but I not getting it to work after looking inot datasheet and sample code too.The ouptut seems to high all the tie I vary the potentiometer from 0 to 3.3
Code:
#include <msp430.h> 

/*
 * main.c
 */

void main(void) {


 WDTCTL = WDTPW + WDTHOLD; // disable watch dog timer
BCSCTL1 = CALBC1_1MHZ;                    // Set range
DCOCTL = CALDCO_1MHZ;
P2DIR |= 0X3F;  //output to Port2 only using P2_0 to P2_5 to test for time being
ADC10CTL1 |= 0X04; // single channel continous conversion
ADC10CTL0 |= ADC10SHT_2 + ADC10ON + MSC ; //sample and hold time, adc on, cont. sample
ADC10AE0 |= 0X01;//Enable A0 get the analogue input
ADC10CTL0 |= ENC + ADC10SC; //start conversion

    while(1)
    {
   int x;

   while ((ADC10CTL1 & ADC10BUSY) == 0x01);//wait till adc is busy
    x=ADC10MEM;
  P2OUT |=(char)(x/100);
     
 
    }

}
 

Try this code
Code:
while(1)
{
	int x;

       __delay_cycles(1000); 

       ADC10CTL0 |= ENC + ADC10SC;

       while ((ADC10CTL1 & ADC10BUSY) == 0x01);

       x = ADC10MEM;

      P2OUT |=(char)(x/100);

}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…