Rich Testardi

m52221demo board accelerometer strangeness

Discussion created by Rich Testardi on Dec 11, 2007
Latest reply on Nov 6, 2008 by Roger Wolff
Hi,
 
I bought an m52221demo board and it all works fine except the accelerometer occasionally seems to get "stuck"...  Even the original flashed demo program didn't control the mouse (via the accelerometer), like it was supposed to.
 
Once the accelerometer gets stuck, I read either near 0v or near 3.3v for the X, Y, and Z outputs...  I've confirmed right at the chip that these signals are coming from the accelerometer (before the series resistor) and not being driven down by GPIO outputs or anything.  I've also confirmed the accelerometer is not in sleep mode.  This doesn't happen often, but when it does, the only way for me to get the accelerometer unstuck is to power off and on again, sometimes more than once.
 
I am wondering if I might just have a bad accelerometer, but I am also concerned a bit of the m5221demo schematic, which seems to indicate the low-pass filter (I assume) caps are right at the pins, with no intervening series resistor...  The m5221demo schematic shows:
 
 
Whereas, the 7260 datasheet recommends:
 
 
(If these pictures didn't come thru, they are in the first and second attachments, as well.)
 
The (heavily trimmed) program I am using is below.
 
Has anyone else seen an issue like this, or do you see something I'm doing wrong?
 
Thanks for any help/advice!!!
 
-- Rich
 
#include "support_common.h"
#include <stdio.h>
#define assert(x)  if (! (x)) { printf("ouch!\r\n"); *(char *)0 = 0; }
static int g;
void ms(int n)
{
    int i;
   
    while (n--) {
        for (i = 0; i < 2000; i++) {
            g++;
        }
    }
}
int main(void)
{
    int i;
    int x, y;
   
    // AN 4, 5, 6 are primary; others are gpio output
    MCF_GPIO_PANPAR = 0x70;
    MCF_GPIO_DDRAN = 0x8f;
   
    // TC is gpio output
    MCF_GPIO_PTCPAR = 0;
    MCF_GPIO_DDRTC = 0xf;
   
    // UB is gpio output
    MCF_GPIO_PUBPAR = 0;
    MCF_GPIO_DDRUB = 0xf;
   
    // initialize accelerometer
    MCF_GPIO_PORTUB = 0x8;  // disable sleep mode; 1.5g sensitivity
   
    // initialize adc to read accelerometer
    MCF_ADC_CTRL1 = 0x0000;  // once sequential
    MCF_ADC_CTRL2 = 0x0005;  // divisor for 48 MHz
    MCF_ADC_ADLST1 = 0x0654;  // channels 4 = x; 5 = y; 6 = z;
    MCF_ADC_ADLST2 = 0x0000;
    MCF_ADC_ADSDIS = 0xf8;
    MCF_ADC_ADHLMT0 = 0x7ff8;  // disable high limits (should be default)
    MCF_ADC_ADHLMT1 = 0x7ff8;
    MCF_ADC_ADHLMT2 = 0x7ff8;
   
    MCF_ADC_POWER = 0x00d0;  // enable adc
   
    i = 0;
    while (1) {
        MCF_ADC_CTRL1 = 0x2000;  // start once sequential
       
        ms(500);
        x = MCF_ADC_ADRSLT0;  // read x and y
        y = MCF_ADC_ADRSLT1;
       
        printf("%d: x = 0x%x; y = 0x%x\r\n", i++, x, y);
       
        // set the LEDs
        if (x < 0x3000 || x > 0x5000) {
            MCF_GPIO_PORTTC |= 0x01;  // x axis gravity
        } else {
            MCF_GPIO_PORTTC &= ~0x01;
        }
        if (y < 0x3000 || y > 0x5000) {
            MCF_GPIO_PORTTC |= 0x02;  // y axis gravity
        } else {
            MCF_GPIO_PORTTC &= ~0x02;
        }
        MCF_GPIO_PORTTC ^= 0x08;  // blink
    }
}

Outcomes