x-y confusion in MEMS demo

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
chibby
Posts: 66
Joined: Wed Oct 22, 2014 11:20 am

x-y confusion in MEMS demo

Post by chibby »

I don't know whether this is some hardware variation anomaly but the MEMS demo has the LEDS on the accelerometer all confused.

Current SVN has x and y inverted and one of the axes responding in the opposite manner to the other one.

The following code make tipping the board left and right light up the left-most and right-most LEDs. It changes the reaction to be consistent on both pairs: highest side of the board lights up.

Code: Select all

    /* Calculating average of the latest four accelerometer readings.*/
    y = ((int32_t)xbuf[0] + (int32_t)xbuf[1] +
         (int32_t)xbuf[2] + (int32_t)xbuf[3]) / 4;
    x = ((int32_t)ybuf[0] + (int32_t)ybuf[1] +
         (int32_t)ybuf[2] + (int32_t)ybuf[3]) / 4;

    /* Reprogramming the four PWM channels using the accelerometer data.*/
    if (y < 0) {
      pwmEnableChannel(&PWMD4, 2, (pwmcnt_t)-y);
      pwmEnableChannel(&PWMD4, 0, (pwmcnt_t)0);
    }
    else {
      pwmEnableChannel(&PWMD4, 0, (pwmcnt_t)y);
      pwmEnableChannel(&PWMD4, 2, (pwmcnt_t)0);
    }
    if (x < 0) {
      pwmEnableChannel(&PWMD4, 1, (pwmcnt_t)-x);
      pwmEnableChannel(&PWMD4, 3, (pwmcnt_t)0);
    }
    else {
      pwmEnableChannel(&PWMD4, 3, (pwmcnt_t)x);
      pwmEnableChannel(&PWMD4, 1, (pwmcnt_t)0);
    }


OK , it's only a demo and it does demonstrate the RTOS functionality but it seems like it was written by someone who did not have access to the hardware. It would look a bit sharper if the LEDs came on in a logical way.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: x-y confusion in MEMS demo

Post by Giovanni »

There are two revisions of the board, one of them has the MEMS rotated.

Giovanni
chibby
Posts: 66
Joined: Wed Oct 22, 2014 11:20 am

Re: x-y confusion in MEMS demo

Post by chibby »

Thanks, I suspected there may be different versions. For the record the above code matches board version MB887C, which I think is still the current version.
Post Reply