Shop OBEX P1 Docs P2 Docs Learn Events
Mesmic 2125 accelerometer — Parallax Forums

Mesmic 2125 accelerometer

Don FrenchDon French Posts: 126
edited 2005-09-16 01:46 in General Discussion
Now that I have my compass module working fairly well, I have a problem with the Mesmic 2125 accelerometer.· I got it to work perfectly with the example code·for the BS2, but on the Javelin I get nothing back but zero values.· I am only trying to read the X axis and am only interested in the raw value.· I thought this single line of code should do the trick:

·int value =· CPU.pulseIn(20000, CPU.pin7, true);

It appears to be wired up correctly and pins 3 and 4·are tied together and go to ground, so I don't know why I am not getting any results.· Could it be something about the CPU.pulseIn() method that is different than the BASIC PULSEIN?

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-09-07 08:17
    I think the time units are different, so you must change the count value

    to reflect the same time.

    regards peter
  • Don FrenchDon French Posts: 126
    edited 2005-09-07 16:38
    Thanks, Peter. I came to that very realization while walking to work today. I don't have the BASIC refernence here, but I don't seem to remember having to or even being able to set the timing in the PULSEIN operation. Not knowing what to set it at for the Javelin, I guess I will write a loop to find the range at which it returns a non-zero value and pick the center point of that range.
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-09-07 17:05
    A return value of 0 indicates no start edge was detected.

    A standard BS2 has a 2 uS unit, the javelin has a 8.68 uS unit and may not

    detect pulses smaller than 8.68 uS (the BS2 would detect those).

    regards peter
  • Don FrenchDon French Posts: 126
    edited 2005-09-07 19:52
    Are you saying that it is might not be possible to use this module with the Javelin?
  • diafysaldiafysal Posts: 92
    edited 2005-09-07 20:39
    Check out this code.
    But if I remember it right there is an error in the code.
    "findDutyFactor" in "Accelerometer.java" have the line:
    return ( (50 * onTime) / (t2Time / 2) );
    



    It can give wrong values (if I remeber it right).
  • Don FrenchDon French Posts: 126
    edited 2005-09-07 21:02
    Great stuff!· Thanks.·
  • Don FrenchDon French Posts: 126
    edited 2005-09-08 04:10
    When I got home from work I tried your code with no success. Both gForceX and gForceY are always -408. And both duty cycles are always -1. Maybe this is related to the bug in the code?

    So, next I tried running a loop that sets the timeout value to every possible value between 0 and 32000. I never got anything but 0 for output on the X pin. (I was not interested in the Y pin and didn't have it connected.) But for grins I connected the Y pin and tried the the same loop with it pin and I got a non-zero value when timeout got to 300. So, this makes me think that the X pin on the Mesmic isn't working. But there was one more thing to try before returning it (can you do that?). And that was to change the Javelin I/O pin used for the pulsing the X pin. And guess what? It worked! It seems my Javelin I/O pin 7 is dead. (Which sucks, but at least my accelerometer module now works!)
  • automatonautomaton Posts: 12
    edited 2005-09-16 01:46
    The problem in the "findDutyFactor" method "Accelerometer.java" is a divide error. If you use 32bit integers you can solve this problem.
    You can find the 32bit integer class here:
    http://www.parallax.com/javelin/applications.asp#AN011

    So to fix the error returned by the line "return ( (50 * onTime) / (t2Time / 2) );" You coud do the following with that entire method

    public int findDutyFactor( char axis )
    {
    Int32 dutyfactor= new Int32(0);
    int onTime = 0;

    switch (axis)
    {
    case 'x': dutyfactor.set(0,findPulseWidth( txPin )*50);
    break;

    case 'y': dutyfactor.set(0,findPulseWidth( tyPin )*50);
    break;

    default: System.out.println("Error: Invalid Axis");
    break;
    }

    dutyfactor.divide(t2Time/2);
    return dutyfactor.low;
    }

    You will, of course, have to have the Int32 class from the above link and the import line below in the Accelerometer class
    import stamp.math.Int32;

    That should fix that error
Sign In or Register to comment.