Jump to content

Recommended Posts

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;
  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
  int x, y, z, temp;

    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;

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. 

Link to post
Share on other sites

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...