MELABS has an example here
http://www.melabs.com/resources/samples/pbp/hardpwm.bas