View previous topic :: View next topic |
Author |
Message |
evsource
Joined: 21 Nov 2006 Posts: 129
|
setting postscale directly for setup_timer_2 and PWM |
Posted: Mon Feb 12, 2007 7:04 pm |
|
|
I'm trying to get a PWM frequency of around 90HZ. The slowest I can get with a 8mHz crystal is about 500HZ
Code: | setup_timer_2(T2_DIV_BY_16,255,5); |
If you do the calculation, the Postscale of 5 should get it down to what I'm after. But changing the Postscale doesn't do anything.
How can I set the Postscale directly? I haven't really played around with configuring registers directly. I see in the datasheet that this is configured in the T2CON register, the TOUTPS3:TOUTPS0 bits (BTW, this is a 16F876A).
Any help would be appreciated. |
|
|
Ttelmah Guest
|
|
Posted: Tue Feb 13, 2007 3:42 am |
|
|
The postscale, does not affect PWM...
Read the chip's data sheet. The postscaler _only_ affects the frequency of interrupts. The clock feeding the PWM, comes from in front of the postscaler section of the hardware.
You need to think of another way of doing this. It depends on your chip, but on some latter PICs, the PWM can be fed from Timer3, which has a separate input. On these, you can generate a lower frequency clock and use this to feed the PWM. The alternative for such a low frequency, is to implement 'soft' PWM, using an interrupt at (say)1mSec intervals, and changing the output yourself.
Best Wishes |
|
|
evsource
Joined: 21 Nov 2006 Posts: 129
|
|
Posted: Wed Feb 14, 2007 3:07 pm |
|
|
What in the world is the postscale used for then if not for PWM frequency? Why even have this parameter in the set duty function if it doesn't affect anything? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|