I did look at the code, not sure what additional advise I can give you beyond that which is being given in the many other threads discussing PID.
I do notice that your “velocity” is really the absolute encoder value and not velocity.
long GetVelocity ()
{
return( nMotorEncoder FROne ] );
}
<<snip>>
velocity = GetVelocity();
velocity is proportional to the change in encoder count, not the absolute encoder count.