One way is to use HPWM, here is an example.

http://www.picbasic.co.uk/forum/showthread.php?t=20921