Variable frequency PWM using MikroC + PIC16F887
When I was doing a project on a robot,I found out that the MikroC PWM library doesn’t support variable frequency values for the PWM frequency. I needed to use such variable values to drive servo motor according to the feedback. Hence,I tried to find some other libraries I can use (I know it’s easy to write from scratch,but why show we reinvent the wheel?)
After googling,I found this excellent PWM library for MikroC by Barton J. Dring.You can get it from his site,Dring Engineering Services PWM page
You just have to include two functions setPWMFreq(...) & setPWMDuty(...) ,from their in your code.Then you can simply call swtPWMFreq(..) function when you need to generate a PWM signal as,
setPWMFreq(unsigned long Fpwm, unsigned long Fosc, unsigned int dutyPercent);
Here I’m going to show how to run a servo motor using PWM,
include functions setPWMFreq(...) & setPWMDuty(...) in the beginning
|
Configuration bits:
Here are some useful pages on PIC PWM
Here is a video of running my servo motors using similar code
Comments