M50 erratic idle

525i 1991. This morning it started, idled too quickly (about 1000RPM or just over, normally 600-700), and had a very jerky on-off throttle response.
It's done that before but not in the last year and it's never lasted all the way to work before (20 miles).
Starting up 9 hours later it again idled at 1000-1500. I pulled the plug off the throttle position sensor and the revs shot up to about 3000. Put it back and it slowed down, then went up to 3000 again, and this time removing and replacing the plug made no difference. Jiggling the wires made no difference.
After a few miles it settled down again and was the same as it was this morning, ie jerky and idle slightly too high.
I've tested the TPS on an analogue meter and it seems perfect. What else could it be?
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
Add image file

Motorsforum.com is a website by car enthusiasts for car enthusiasts. It is not affiliated with any of the car or spare part manufacturers or car dealers discussed here. All logos and trade names are the property of their respective owners.