Quote:
Originally Posted by Daniel Jones
The PIC18F8520 actually has several hardware counter-compare modules which are connected to the first four motor ports. These can be used to generate a high resolution PWM signal from 0% duty to 100% duty at high frequencies (I think I used 40kilohertz). Since hardware is taking care of this, after you set a value your code can continue to do anything else and the signal will continue to be generated until it is told otherwise.
I attached some code that I used to drive an h-bridge motor controller via this method.
|
For those who are not familiar with MPLAB, the CustomPWM.c code was meant to be part of a project in MPLAB. For those curious in getting a working project you need to download the full project from VEX's software downloads.
http://www.vexrobotics.com/docs/VexCode_def_2008.zip
Once you have MPLAB opened, add the source files for CustomPWM.c & CustomPWM.h
Thanks for posting this awesome code !!! Kevin Watson also has some great interfacing examples,
http://www.kevin.org/frc/ but this is only for FRC 2008 & 2007 systems.