You didn't mention which type of PWM you wanted, HWPM for continous PWM, or regular. Here is a quickie program that flashes a LED from full bright to dimly lit. It's good for an indication of some kind.
Install a LED on portb.0
If you had inputs on portb, like portb.1, and portb.2, then use TRISb=%00000110Code:T var byte' set-up the loop variable For t=1 to 20' amount of bright/dim flashes portb.0=1:pause 90:portb.0=0' full bright ON time then turn OFF---experiment with the ON time. PWM portb.0,20,80' the 20 is LED brightness, the 80 is it's ON time--Again experiment with the numbers, try changing the 20 to 50. TRISb=0' Once PWM is used on a pin, then that pin only wants PWM to be used. The TRISb resets the pin back to normal output. next t' end of loop
.
While PWM is operating, nothing else is being done. Same way with SOUND. When using a servo, when PWM stops, the servo no longer gets data causing it to lose it's position if it was under a load. To correct this you would need to use the HWPM.
Hope this helped.
Electroken




Bookmarks