Shop OBEX P1 Docs P2 Docs Learn Events
Time measurment — Parallax Forums

Time measurment

RShirleyRShirley Posts: 12
edited 2005-07-15 16:16 in General Discussion
Hi Folks,
I am·new to the Javelin, so I hope i don't ask to many stupid questions. How can I get the elasped time between two marks using a Timer or between a mark and a read? Maybe using another object? I need the measure the elasped time between the leading edege of a 1 pps output from a GPS unit on one pin and an input on another pin to the millisecond or better.
Thanks, Russell

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-12 20:05
    A timer object has tickHi and tickLo fields that will tell you the current timer value.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-07-12 20:18
    I added·a method passedMS to my Timer class

    · /**
    ·· * Calculate the time passed since the last call to the <code>mark()</code> method.
    ·· * The returned value is in millisecond units.
    ·· *
    ·· * @return Passed time in milliseconds (unsigned)
    ·· * </code by Peter Verkaik (peterverkaik@boselectro.nl)>
    ·· */
    · public int passedMS() {
    ··· int l = tickLo(); //current time (unsigned)
    ··· int h = tickHi();
    ··· //calculate passed time = current time - mark time = current time + (- mark time)
    ··· //negate mark time
    ··· int lo = startLo ^ (short)0xFFFF;
    ··· int hi = startHi ^ (short)0xFFFF;
    ··· lo += 1;
    ··· if (CPU.carry()) hi++;
    ··· //add current to negated mark time
    ··· int ah = h;
    ··· int al = l + lo;
    ··· if (CPU.carry()) ah++;
    ··· ah += hi;
    ··· // now convert ah:al into milliseconds: timeMS = 569*ah + (al/115)
    ··· // fraction 1/115 = 0x023A
    ··· return (569*ah)+ UnsignedIntMath.umulf(al,0x023A);
    · }

    You find my adapted Timer classes here
    http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/core/
    math support classes here
    http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/math/

    There is also my ScaledTimer16 class that operates with userdefined units.

    regards peter

    ·
  • RShirleyRShirley Posts: 12
    edited 2005-07-14 16:23
    Thanks, I will give it at try.
  • RShirleyRShirley Posts: 12
    edited 2005-07-15 12:59
    Peter,
    When I complie I get this:
    [noparse][[/noparse]Java Error] Timer32.javs(105): Error:"UnsignedIntMath" is either a missplaced package name or a non-existent enity.
    What am I leaving out?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-07-15 14:13
    Sorry, that package wasn't uploaded.
    Now it is.
    http://groups.yahoo.com/group/JavelinCode/files/Javelin%20Stamp%20IDE/lib/stamp/math/
    Place it in the lib/stamp/math folder

    regards peter
    ·
  • RShirleyRShirley Posts: 12
    edited 2005-07-15 16:16
    That fixed it. Thanks
Sign In or Register to comment.