Funny that should work. Here's a few things to check.
Make sure you're using a separate power supply for your servo, and you have a common ground between them. Running a servo from your controller power supply can cause problems if you aren't using a hefty bench type power supply with a lot of filtering to remove motor noise.
Make sure you're using the correct voltage for your servo. These normally run on 4.8 to 6V. If you're trying to operate your servo from 9V that may be a problem. Most hobby type servos can't handle 9V, and a 5V control pulse from the PIC is going to look pretty weak to a servo operating at 9V.
I tested the above code example, and it works as expected with a Hitec HS311 servo operating at 5V with a 16F627. Note some servos will move 90 degrees right or left, so you can tweak the value in the Flush routine between 200 to 250 to extend the rotation range.
My HS311 moves full right with 250, and centers with 150.
Bookmarks