Shop OBEX P1 Docs P2 Docs Learn Events
Problem with MMA7455 Accelerometer and SimpleIDE Terminal — Parallax Forums

Problem with MMA7455 Accelerometer and SimpleIDE Terminal

Hello,

I am using the MMA7455 3-Axis Accelerometer module (https://www.parallax.com/product/28526) on a Propeller Activity Board. I followed the SPI Example (http://learn.parallax.com/tutorials/language/propeller-c/propeller-c-simple-protocols/spi-example) and am using the provided code to take measurements on the z-axis. When I try to sample at 50Hz by changing the pause time from 500 to 20, the measurements in the SimpleIDE terminal cannot seem to keep up. The datasheet for the accelerometer says the chip can sample at up to 125Hz and 250Hz, depending on the bandwidth setting. Is the Propeller or SimpleIDE terminal the limiting factor or is there something I am doing wrong?

Thanks,
David

Comments

  • Hello,

    I am using the MMA7455 3-Axis Accelerometer module (https://www.parallax.com/product/28526) on a Propeller Activity Board. I followed the SPI Example (http://learn.parallax.com/tutorials/language/propeller-c/propeller-c-simple-protocols/spi-example) and am using the provided code to take measurements on the z-axis. When I try to sample at 50Hz by changing the pause time from 500 to 20, the measurements in the SimpleIDE terminal cannot seem to keep up. The datasheet for the accelerometer says the chip can sample at up to 125Hz and 250Hz, depending on the bandwidth setting. Is the Propeller or SimpleIDE terminal the limiting factor or is there something I am doing wrong?

    Thanks,
    David

    We can attempt to answer this, but I think we'll need to see your code. The terminal in SimpleIDE should be able to handle this, the UART library for communicating with the terminal shouldn't be having any issues, and the SPI library from communicating with your accelerometer shouldn't have any issues. Something seems off to me.
  • Hi David,

    Thanks for your response. Here is my code:

    /*
    MMA7455 Test Z Axis.c
    */

    #include "simpletools.h" // Include simpletools lib

    signed char z; // Z-axis value

    int main() // Main function
    {
    high(6); // CS line high (inactive)
    low(8); // CLK line low
    low(6); // CS -> low start SPI

    shift_out(7, 8, MSBFIRST, 7, 0b1010110); // Write MCTL register
    shift_out(7, 8, MSBFIRST, 1, 0b0); // Send don't-care bit
    shift_out(7, 8, MSBFIRST, 8, 0b01100101); // Value for MCTL register

    high(6); // CS -> high stop SPI
    pause(1);

    while(1) // Main loop
    {
    low(6); // CS low selects chip
    shift_out(7, 8, MSBFIRST, 7, 0b0001000); // Send read register address
    shift_out(7, 8, MSBFIRST, 1, 0b0); // Send don't-care value

    z = shift_in(7, 8, MSBPRE, 8); // Get value from register

    high(6); // De-select chip
    print("%c z = %d%c", HOME, z, CLREOL); // Display measurement
    pause(500); // Wait 0.5 s before repeat
    }
    }

    When I change pause(500) to pause(20) the SimpleIDE terminal cannot keep up and shows significant lag (5-10 sec). However, if you use pause(30) or higher, it seems to work fine.

    Thanks,
    David
  • DavidZemonDavidZemon Posts: 2,973
    edited 2016-09-13 18:26
    What memory model are you using? At first glance, I don't see anything wrong with this whether it's cmm or lmm, but if you're using XMM by chance, it's possible 20ms is too fast?

    Also, next time you might use the [ code ] tags. Or highlight your code and press the "C" button at the top of the text editor.

    I'll try running your code when I get home and see if I can recreate your issue.
  • I guess serial com does overflow.

    with just 20ms you send data faster as the output can send it to the terminal.

    At what baud rate you send/receive to the terminal?

    Enjoy!

    Mike
  • David:

    Sorry about that - here is the code with the tags:
    /*
      MMA7455 Test Z Axis.c
    */
    
    #include "simpletools.h"                          // Include simpletools lib
    
    signed char z;                                    // Z-axis value
    
    int main()                                        // Main function
    {
      high(6);                                        // CS line high (inactive)
      low(8);                                         // CLK line low
      low(6);                                         // CS -> low start SPI
    
      shift_out(7, 8, MSBFIRST, 7, 0b1010110);        // Write MCTL register
      shift_out(7, 8, MSBFIRST, 1, 0b0);              // Send don't-care bit
      shift_out(7, 8, MSBFIRST, 8, 0b01100101);       // Value for MCTL register
    
      high(6);                                        // CS -> high stop SPI
      pause(1);
    
      while(1)                                        // Main loop
      {
        low(6);                                       // CS low selects chip
        shift_out(7, 8, MSBFIRST, 7, 0b0001000);      // Send read register address
        shift_out(7, 8, MSBFIRST, 1, 0b0);            // Send don't-care value
    
        z = shift_in(7, 8, MSBPRE, 8);                // Get value from register
    
        high(6);                                      // De-select chip
        print("%c z = %d%c", HOME, z, CLREOL);        // Display measurement
        pause(500);                                   // Wait 0.5 s before repeat
      }
    }
    

    I am not sure how to check for the memory model but I am using the stock SimpleIDE configuration.

    Mike:

    I am using the 115200 baud rate.

    Thanks,
    David

  • David:

    Sorry about that - here is the code with the tags:
    /*
      MMA7455 Test Z Axis.c
    */
    
    #include "simpletools.h"                          // Include simpletools lib
    
    signed char z;                                    // Z-axis value
    
    int main()                                        // Main function
    {
      high(6);                                        // CS line high (inactive)
      low(8);                                         // CLK line low
      low(6);                                         // CS -> low start SPI
    
      shift_out(7, 8, MSBFIRST, 7, 0b1010110);        // Write MCTL register
      shift_out(7, 8, MSBFIRST, 1, 0b0);              // Send don't-care bit
      shift_out(7, 8, MSBFIRST, 8, 0b01100101);       // Value for MCTL register
    
      high(6);                                        // CS -> high stop SPI
      pause(1);
    
      while(1)                                        // Main loop
      {
        low(6);                                       // CS low selects chip
        shift_out(7, 8, MSBFIRST, 7, 0b0001000);      // Send read register address
        shift_out(7, 8, MSBFIRST, 1, 0b0);            // Send don't-care value
    
        z = shift_in(7, 8, MSBPRE, 8);                // Get value from register
    
        high(6);                                      // De-select chip
        print("%c z = %d%c", HOME, z, CLREOL);        // Display measurement
        pause(500);                                   // Wait 0.5 s before repeat
      }
    }
    

    I am not sure how to check for the memory model but I am using the stock SimpleIDE configuration.

    Mike:

    I am using the 115200 baud rate.

    Thanks,
    David

    SimpleIDE in its default configuration with this code and the print function will run unbuffered serial comms. That means you can't overflow the buffer on the Propeller side.

    Also, I booted ran this code and was not able to reproduce your issue. Can you please upload a full zip of your project using the menu Project -> Zip? Also, since I don't have a real MMA7455 accelerometer to plug in, I faked it by modifying the code to include an index variable that is printed at the start of the line. Without it, it would just keep printing "z = 0" :)
    /*
      MMA7455 Test Z Axis.c
    */
    
    #include "simpletools.h"                          // Include simpletools lib
    
    signed char z;                                    // Z-axis value
    
    int main()                                        // Main function
    {
      high(6);                                        // CS line high (inactive)
      low(8);                                         // CLK line low
      low(6);                                         // CS -> low start SPI
    
      shift_out(7, 8, MSBFIRST, 7, 0b1010110);        // Write MCTL register
      shift_out(7, 8, MSBFIRST, 1, 0b0);              // Send don't-care bit
      shift_out(7, 8, MSBFIRST, 8, 0b01100101);       // Value for MCTL register
    
      high(6);                                        // CS -> high stop SPI
      pause(1);
    
      int i = 0;
      while(1)                                        // Main loop
      {
        low(6);                                       // CS low selects chip
        shift_out(7, 8, MSBFIRST, 7, 0b0001000);      // Send read register address
        shift_out(7, 8, MSBFIRST, 1, 0b0);            // Send don't-care value
    
        z = shift_in(7, 8, MSBPRE, 8);                // Get value from register
    
        high(6);                                      // De-select chip
        print("%c%d z = %d%c", HOME, i++, z, CLREOL);        // Display measurement
        pause(20);                                   // Wait 0.5 s before repeat
      }
    }
    
  • samuellsamuell Posts: 554
    edited 2016-09-16 10:38
    Hello,

    I am using the MMA7455 3-Axis Accelerometer module (https://www.parallax.com/product/28526) on a Propeller Activity Board. I followed the SPI Example (http://learn.parallax.com/tutorials/language/propeller-c/propeller-c-simple-protocols/spi-example) and am using the provided code to take measurements on the z-axis. When I try to sample at 50Hz by changing the pause time from 500 to 20, the measurements in the SimpleIDE terminal cannot seem to keep up. The datasheet for the accelerometer says the chip can sample at up to 125Hz and 250Hz, depending on the bandwidth setting. Is the Propeller or SimpleIDE terminal the limiting factor or is there something I am doing wrong?

    Thanks,
    David

    Hi,

    I had the same issue with my primality program, which outputs the results very fast. Indeed, the SimpleIDE terminal doesn't keep up, showing intermittent blinking and omitting results in the process. I confirmed, both visually by the LEDs and using a scope, that the Activity Board was sending the results without interruption, and it was the terminal that was not updating properly. Seemingly, it is a buffering issue. My suggestion is to program to EEPROM and try using PuTTY to communicate. Worked like a charm for me.

    Kind regards, Samuel Lourenço
Sign In or Register to comment.