Elimathew
Member level 5
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);
}
}