Shop OBEX P1 Docs P2 Docs Learn Events
tachometer — Parallax Forums

tachometer

bulkheadbulkhead Posts: 405
edited 2006-08-25 18:30 in General Discussion
I'm trying to use my Javelin as a tachometer for a small side project. Right now I am using CPU.count( ), however the problem is since it can only count in a maximum period of 284.4ms, so the smallest RPM reading it can get is roughly 211 rpm. Is there a way to measure rpm slower than this?

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-08-25 18:30
    You can try manual mode:

    t = new Timer();
    while (CPU.readPin(CPU.pin0)) ; //wait until pin0 goes low
    t.mark();
    while (!CPU.readPin(CPU.pin0)) ; //wait until pin0 goes high
    while (CPU.readPin(CPU.pin0)) ; //wait until pin0 goes low
    int passed = t.passedMS();

    passedMS is a method in 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();
    ··· int r;
    ··· h = h - startHi; //calculate passed time = current time - mark time
    ··· if (startLo != 0) {
    ····· l = l - startLo;
    ····· if (!CPU.carry()) h--;
    ··· }
    ··· // now convert h:l into milliseconds: timeMS = 569*h + (l/115)
    ··· r = (569*h)+(l/115);
    ··· if (l<0) r += 569;·· //l is really unsigned, so if l<0 (0x8000-0xFFFF) l/115 equals ((65536+l)/115) = 569 + l/115
    ··· return r;
    · }

    That gives you the number of milleseconds for an entire LOW+HIGH period.

    regards peter
Sign In or Register to comment.