Quote Originally Posted by Darrel Taylor View Post
There's a R-M-W (Read-Modify-Write) problem when OUTPUTting to a pin set to Analog. It adds a high frequency component to the PWM signal.
That's interesting... whilst I was reading up on the use of your code I could hear this high pitched (estimated 4 - 8 Khz) faint sound like you often hear eminating from a TV... placed my ear near the loco (which is standing still on the track) and its singing away !!

I presume that this is due to the fact that GPIO.2 is still set to analogue and not digital ??

What config settings should I use for CMCON and ANSEL to resolve this ?