mikeoshea 0 Posted May 6, 2013 Share Posted May 6, 2013 I'm working on integrating an accelerometer(ADXL335) into my project. So I'm doing three single channel conversions, on the three axes. The first conversion I do gives me a normal reading for horizontal, ~450. The other ones give me ~880 and ~1020. I have switched the axes and the first one always gives me the correct value the others don't. The following code shows my ADC function. int Acc(char channel) { int res, ch; ch = channel * 0x1000; ADC10CTL0 &= ~ENC; ADC10CTL0 |= ADC10ON; ADC10CTL1 = ch + ADC10SSEL_3; ADC10CTL0 |= ENC + ADC10SC; while(ADC10CTL1&ADC10BUSY); res = ADC10MEM; ADC10CTL0 &= ~(ADC10ON + ENC); return res; } And my main code, #include "msp430g2553.h" #include "central.h" void main(void) { WDTCTL = WDTPW + WDTHOLD; //Watchdog Timer Disabled P1DIR =0xf8; //Initialise Pins and Special Functions P1SEL=0x00; P1IE=0x00; DCOCTL= CALDCO_1MHZ; BCSCTL1=CALBC1_1MHZ; int x, y, z, temp; P1OUT=0x00; while(1) { x=Acc(0); y=Acc(1); z=Acc(2); temp = Temp(); if (x>=400) P1OUT = BIT6; else if(y>=400) P1OUT = BIT5; else if(z>=400) P1OUT = BIT4; else {}; if(temp>=300) P1OUT= BIT3; else{}; __delay_cycles(1000); } } I'm not doing anything with the outputs so ignore them. Has anyone any ideas why one axis gives a sensible result but the other two don't? PS when the accelerometer is powered and the axis pins are not connected, the voltages read with a multimeter are correct. Quote Link to post Share on other sites
nemetila 12 Posted May 6, 2013 Share Posted May 6, 2013 I think you forgot to set the ADC10AE0 register. ADC10AE0x: ADC10 analog enable. These bits enable the corresponding pin for analog input. BIT0 corresponds to A0, BIT1 corresponds to A1, etc. Quote Link to post Share on other sites
mikeoshea 0 Posted May 6, 2013 Author Share Posted May 6, 2013 Thanks nemetila, I actually tried that shortly after posting here, doesn't make any difference. I read somewhere else that that register is only needed when doing sequence conversions whereas I am doing three single channel conversions. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.