This is a tachometer program that I used with a optical encoder with 400 steps per revolution. It uses PID to control a motor with direct drive to the encoder at 2000 RPM
This requires the PID_v2 library I created to maintain stable PID control (PID_v1 is flawed).
I Posted earlier with an easier way to calculate RPM I seen this from another example I haven't adapted this RPM calculation to the new method but it works none the less.
(The board is an atmega328p (UNO) arduino at heart motor controller I created)