Tachometer Interrupt Help

Our team currently has a tachometer attached to one of our wheels. We were using it to find the Rpm of the wheel, but the method we were using was very inaccurate, sometimes by up to 260 rpm difference. We decided that the best way to fix this was to cause an interrupt in the code every time the counter for the tachometer pulsed. That way we could measure more accurately. How exactly would we have to set that up so it runs a segment of code whenever the tach pulses?
Thanks for any help!

-Team 1277

There are interrupts, but my guess is that isn’t the best way to solve your problem. It would be better to take advantage of some of the features in the FPGA.

Can you describe your tachometer, what it outputs, and what your code is right now?

Currently, we have a counter hooked up to record the number of pulses from the tachometer, which is triggered by a bolt on the axial of the wheel. Currently, the code takes the finds the average rpm of a half second, based on the number of new ticks on the counter. This doesn’t work, because if we get only one tick, it reads 120 rpm, which is a big range for error.

After looking through the wpilibj api again, I found that there was counter.getPeriod(); Which would fix the whole problem most likely. If it does we won’t need to use the interrupt.

Thanks Anyway :smiley:

It may be better to use a quaduture encoder thats what we use and use the .getRate(); command

have you had any luck with the getPeriod method in the counter class? i’ve tried it but it doesn’t seem to work. it starts out with a value of infinity and never changes when i run it…

twiggzee, have you tried different speeds when running your device/tach? We found that until our shooter reached a certain speed getPeriod returned infinity. We also used setMaxPeriod to adjust the period so that we could measure shooter revolutions at the lowest speed we would ever use.
I didn’t see a way to find out what the original max period value was, either by calling a function or looking at wpilib src code.

-Maciej

that was it. tried it again, turns out that the getPeriod method only consistently gives a reading when our wheel is spinning more than 1200 rpm. anything below that we get either an “infinity” reading or an occasional reading when approaching 1200 rpm. thanks!

Maybe Java has a “SetMaxPeriod” like C++ does:

/**

  • Set the maximum period where the device is still considered “moving”.
  • Sets the maximum period where the device is considered moving. This value is used to determine
  • the “stopped” state of the counter using the GetStopped method.
  • @param maxPeriod The maximum period where the counted device is considered moving in
  • seconds.
    */
    void Counter::SetMaxPeriod(double maxPeriod)