tachometer
bulkhead
Posts: 405
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
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