using an interrupt to get rpm

Chagrin:
Well you're right about it being broken ;). For starters, you're never updating Input within loop().

You shouldn't be updating your RPM measurement every 20 counts. You're trying to smooth out the readings for the current RPM but you should leave that work to the PID library. If you're having problems with your optical sensing then you need to fix that or you will never get reliable control.

I would suggest that you simplify by setting Input to the time (milliseconds) between interrupts. Also adjust the value read from analogRead(setpointPin) to units that are equivalent to the milliseconds you want per revolution. Remember that the PID library tries to match the value of Input to Setpoint and the units for each variable must be equivalent.

It would also be helpful to know what range of speeds (what RPM will be typical) you're trying to achieve.

between 0-4000rpm. Thanks, when I get time I will redo and post the new code. I was just jumbling things around for testing and it ended up like this.. lol