PID controlled motor controller (based on measured RPM instead of PWM)

Are you trying to control RPM or torque?