It was set to PID, but switching it to bang-bang didn't fix the problem. It turned out to be the MOSFET, which was getting quite hot. I replaced the RAMPS and it is working now.
Thanks for your help.
Thanks for your help.