|
I have no idea what it could be used for, but if your looking for Slow
Speed PWM, this might help.
If your looking for pulses in the range of 1-2 ms at a fixed frequency of 50 Hz,
for controlling Servo Motors try the PWPS (Pulse Width Position Servo) program
instead. The problem, is that the Hardware PWM is
limited by a minimum frequency. In the case above, 1221hz is the lowest
frequency available for HPWM. This limitation is due to the use of Timer2
with the Capture/Compare module.
Timer 2 is an 8 bit timer with a maximum prescaler of 1:16 Let's take a
look at the math. @ 20 Mhz, the prescaler is fed with FOSC/4 or 5 Mhz, so each
clock pulse is 0.0000002 sec. (1/5,000,000) or .2 us
With a maximum prescaler of 1:16 Timer2 will be clocked every 3.2
us (.2 us * 16)
Since Timer2 is an 8bit timer, the maximum count is 255 plus 1 to overflow the
timer.
Therefore, the maximum period is (3.2 us * 256) or 819.2
us, which gives us 1220.7 Hz
(1/0.0008192)
The integer math of PICs then limits it to 1221 Hz @
4 Mhz you can get as low as 245 Hz, but at 40 Mhz it goes up to 2442 Hz. At
first I thought that we could switch over to Timer1 which is a 16 bit timer to
gain some Low Freq Response, but then figured out that the CCP modules are only
8 bit as well, so there's no difference in the final result. Although the
CCP is capable of 10 bit PWM, it's really only 8 bits, with the upper bits
controlling the prescaler, and since we've already taken the maximum prescaler
into account it doesn't help at all. There is a method where you can use the
16-bit "Compare" mode of the CCP module to do the job. The CCP
would constantly monitor Timer1 for a match and then generate an
interrupt. You would then change the compare value to the other half of
the cycle, and wait for the next interrupt (rinse and repeat). This
method would need to use both the CCP module and a Timer (1 or 3). But
since it can be accomplished with just the Timer by itself, I figured it would
be better to save the CCP module for other uses, like a separate HPWM at a
different frequency. This program
will produce PWM signals in the following ranges, depending on OSC frequencies
of:
|