CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

setting postscale directly for setup_timer_2 and PWM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
evsource



Joined: 21 Nov 2006
Posts: 129

View user's profile Send private message

setting postscale directly for setup_timer_2 and PWM
PostPosted: Mon Feb 12, 2007 7:04 pm     Reply with quote

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







PostPosted: Tue Feb 13, 2007 3:42 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 14, 2007 3:07 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 14, 2007 3:10 pm     Reply with quote

Read my reply to your previous posting of this question:
http://www.ccsinfo.com/forum/viewtopic.php?t=29786
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group