Hi Folks
I looked at the 2.45 pbp manual and it says the max HPWM freq using any crystal is 32.767KHZ. Am I misreading the post or has this changed with the newer version? I would love to get HPWM working at 40KHZ for IR remote control apps.
Hi Folks
I looked at the 2.45 pbp manual and it says the max HPWM freq using any crystal is 32.767KHZ. Am I misreading the post or has this changed with the newer version? I would love to get HPWM working at 40KHZ for IR remote control apps.
The solution is to not use the PBP HWPWM command at all. Simply write to the registers directly. For example:
PR2 = $1F ' PWM register, 158 Khz@20Mhz, 7 bits
T2CON = %00000100 ' Prescale 1 - Needed for PWM
.
.
.
CCPR1L = PWMVal >>2 ' Divide Value by 4
CCP1CON.5=PWMVal.1
CCP1CON.4=PWMVal.0
Charles Linquist
I too, must admit I never use the HPWM command. I write to the registers directly just as Charles suggested. Most (if not all) of the PICs that have hardware PWM have an easy to follow 4 step procedure for setting the registers correctly. (e.g., for the 16F628A, see section 9.3.3). In addition to Charles' example check out MElabs example here
http://www.melabs.com/resources/samples/pbp/hardpwm.bas
(Yes, the calcs are a tad confusing at first, but once you get it you will never go back.)
Paul Borgmeier
Salt Lake City, Utah
USA
I find the formulas obfuscate things. Using the MElabs example, with OSC=4MHz each instruction cycle takes 1µS. The period for 1kHz is 1/1000=.001=1000µS=1000 instruction cycles. With the prescaler set to 4, 1000 becomes 250 and since it's Base0 it becomes 249. The duty cycle is the number of instruction cycles that the output is high. 20% of 1000 = 200 and 80% of 1000 = 800. All you are doing is defining the period and duty cycle in numbers of instruction cycles. Once you grasp what's involved you can do the calculations in your head.Originally Posted by paul borgmeier
Last edited by dhouston; - 15th June 2006 at 23:02.
Paul, Charles, dHouston: Thanks so much for not just answering my question but guiding me back to the literature so that I can figure out future questions for myself. I (and I'm sure Blind Al too) consider myself very lucky to have such expertise available.
- Jim
Bookmarks