Forums

Help with ADC

Started by naray23 March 16, 2010
Hi all
I am a newbie to MSP430 and currnetly working on the MSP430F5438 experimenters board.I am trying to write an ADC code but it is not worrking.I am trying to read the accelerometer on the board.
Here is the code
void ADC_Initialise(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
P6DIR |=0x01;
P6OUT |=0x01; //Switch on VCC of acclerometer
P6SEL |= 0x0006;
P6DIR &=~(0x0006); //X on P6.1 and Y on P6.2

ADC12CTL0 |= ADC12SHT12|ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 =0;
ADC12CTL1 |= ADC12CSTARTADD_1|ADC12SHP|ADC12SSEL_0; // Use sampling timer
ADC12CTL2 = ADC12RES_0;//8 bit
ADC12MCTL0 = ADC12INCH_1;

// ADC12IE |= ADC12IE1; // Enable interrupt
ADC12CTL0 |= ADC12ENC;
//P7SEL |= 0x0020; // P6.0 ADC option select
//P7DIR &=~(0x0020);

}
this is part of the main code

if(serial_byte_avail())
{
ch =getchar() ;
if(ch == 'A')
{
ADC12CTL0 |= ADC12SC; // Start sampling/conversion
while(ADC12CTL1 & ADC12BUSY);
UCA1TXBUFC12MEM1;
}

}
Problem is i am only getting 0xFE as the output even though i move the board.Please help me if i have made some silly mistake in the code or can someone please send a working ADC code.

Thank you and Regards
Gopalakrishnan.N

Beginning Microcontrollers with the MSP430

I am not sure, but have you checked the input voltage levels? Are they in the range specified by the datasheet?
Try measuring some lower voltage first.

________________________________
De: naray23
Para: m...
Enviadas: Terça-feira, 16 de Março de 2010 11:05:15
Assunto: [msp430] Help with ADC


Hi all
I am a newbie to MSP430 and currnetly working on the MSP430F5438 experimenters board.I am trying to write an ADC code but it is not worrking.I am trying to read the accelerometer on the board.
Here is the code
void ADC_Initialise( void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
P6DIR |=0x01;
P6OUT |=0x01; //Switch on VCC of acclerometer
P6SEL |= 0x0006;
P6DIR &=~(0x0006); //X on P6.1 and Y on P6.2

ADC12CTL0 |= ADC12SHT12|ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 =0;
ADC12CTL1 |= ADC12CSTARTADD_ 1|ADC12SHP| ADC12SSEL_ 0; // Use sampling timer
ADC12CTL2 = ADC12RES_0;/ /8 bit
ADC12MCTL0 = ADC12INCH_1;

// ADC12IE |= ADC12IE1; // Enable interrupt
ADC12CTL0 |= ADC12ENC;
//P7SEL |= 0x0020; // P6.0 ADC option select
//P7DIR &=~(0x0020);
}

this is part of the main code

if(serial_byte_ avail())
{
ch =getchar() ;
if(ch == 'A')
{
ADC12CTL0 |= ADC12SC; // Start sampling/conversion
while(ADC12CTL1 & ADC12BUSY);
UCA1TXBUF=ADC12MEM1 ;
}
}

Problem is i am only getting 0xFE as the output even though i move the board.Please help me if i have made some silly mistake in the code or can someone please send a working ADC code.

Thank you and Regards
Gopalakrishnan. N

____________________________________________________________________________________
Veja quais são os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.com



The one thing that jumps out at me is that you are writing a 12 bit ADC value to an 8 bit UART register.

UCA1TXBUF=ADC12MEM1 ;

You will need to break ADC12MEM1 value into two 8 bit values and then send it out the UART as 2 separate writes. The conversion result is stored in the upper 12 bits of the ADC12MEM1 register with the lowest 4 bits always being read as 0's. If you are getting 0xFE all the time then I would guess you are only seeing the upper byte of the conversion.

HTH,
Barry

--- In m..., Barbara wrote:
>
> I am not sure, but have you checked the input voltage levels? Are they in the range specified by the datasheet?
> Try measuring some lower voltage first.
>
>
>
>
>
> ________________________________
> De: naray23
> Para: m...
> Enviadas: Terça-feira, 16 de Março de 2010 11:05:15
> Assunto: [msp430] Help with ADC
>
>
> Hi all
> I am a newbie to MSP430 and currnetly working on the MSP430F5438 experimenters board.I am trying to write an ADC code but it is not worrking.I am trying to read the accelerometer on the board.
> Here is the code
> void ADC_Initialise( void)
> {
> WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
> P6DIR |=0x01;
> P6OUT |=0x01; //Switch on VCC of acclerometer
> P6SEL |= 0x0006;
> P6DIR &=~(0x0006); //X on P6.1 and Y on P6.2
>
> ADC12CTL0 |= ADC12SHT12|ADC12ON; // Sampling time, ADC12 on
> ADC12CTL1 =0;
> ADC12CTL1 |= ADC12CSTARTADD_ 1|ADC12SHP| ADC12SSEL_ 0; // Use sampling timer
> ADC12CTL2 = ADC12RES_0;/ /8 bit
> ADC12MCTL0 = ADC12INCH_1;
>
> // ADC12IE |= ADC12IE1; // Enable interrupt
> ADC12CTL0 |= ADC12ENC;
> //P7SEL |= 0x0020; // P6.0 ADC option select
> //P7DIR &=~(0x0020);
>
>
> }
>
> this is part of the main code
>
> if(serial_byte_ avail())
> {
> ch =getchar() ;
> if(ch == 'A')
> {
> ADC12CTL0 |= ADC12SC; // Start sampling/conversion
> while(ADC12CTL1 & ADC12BUSY);
> UCA1TXBUF=ADC12MEM1 ;
> }
>
>
> }
>
> Problem is i am only getting 0xFE as the output even though i move the board.Please help me if i have made some silly mistake in the code or can someone please send a working ADC code.
>
> Thank you and Regards
> Gopalakrishnan. N
>
>
>
>
>
> ____________________________________________________________________________________
> Veja quais são os assuntos do momento no Yahoo! +Buscados
> http://br.maisbuscados.yahoo.com
>
>
>