Can you first describe how it goes unstable?
Does it oscillate?
Does it overshoot?
Is settling time not satisfactory?
Hmmm… it seems like you need to ramp up your derivative term as you get closer to the wall…
You’ll have to describe what happens specifically though..
PID control systems are notoriously difficult to tune. However it is difficult to give an opinion without specific details of your system. I gave a paper at Minos '02 on the subject (posted on my website http://www.wgmarshall.freeserve.co.uk/ together with an 8051 code fragment). This is for lateral position control, but I have since developed one for velocity control.