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

PWM Problem

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



Joined: 05 Dec 2009
Posts: 40

View user's profile Send private message

PWM Problem
PostPosted: Wed Jan 06, 2010 5:33 am     Reply with quote

hello everyone
i am using PIC16F876A i want to ask 3 Question regarding PWM,
Code:
 
  setup_ccp1(CCP_PWM);//configure CCP1 as a PWM
  setup_ccp2(CCP_PWM);
  setup_timer_2(T2_DIV_BY_x, period, postscale);
                                where x = 1,4,16 


Q#1:: I want two PWM channels of Different frequencies ?????
Q#2:: it is possible to have a PWM frequency below 10Hz
Q#3:: what does this postscale do ?? its value is from 1 to 16
Ttelmah
Guest







PostPosted: Wed Jan 06, 2010 6:03 am     Reply with quote

1) Not on the 876A. Some of the later chips allow a second timer to be used for PWM channels.
2) Depends on your master clock frequency. The maximum division available, is 4*256*16. On most master clocks, you won't even get down anywhere near 10Hz. With a 4Mhz master clock for example, the minimum PWM frequency, will be 244.14Hz.
However, remember that the 'point' of the hardware PWM, is to generate _high frequencies_, that could not easily be done in software. For low frequencies, you can easily generate a PWM, using a timer interrupt. There have been low frequency PWMexamples posted here in the past. Use something like a 100Hz 'tick' interrupt, and you could easily do 1Hz PWM, with 100 different widths....
3) In many applications, it is important for some operations to occur synchronously to the PWM. The chip therefore has the ability to generate an interrupt, when the PWM count resets. Because the frequency of this will often be too high for an interrupt to be used, you can specify how many cycles of the PWM, should occur between interrupts.

Best Wishes
bells_electronics



Joined: 05 Dec 2009
Posts: 40

View user's profile Send private message

PostPosted: Wed Jan 06, 2010 7:15 am     Reply with quote

Whats the size of the period is it 10-Bit or 8-bit?
bells_electronics



Joined: 05 Dec 2009
Posts: 40

View user's profile Send private message

PostPosted: Wed Jan 06, 2010 8:21 am     Reply with quote

What would be the frequency if I use these Values ??? is it 100Hz or what ??
Code:

  setup_ccp1(CCP_PWM);
  setup_timer_2(T2_DIV_BY_16, 624, 1);
Ttelmah
Guest







PostPosted: Wed Jan 06, 2010 9:17 am     Reply with quote

The maximum divider for Timer2, is 256 (maximum input value of 255), so you can't use 624...
The resulting PWM frequency value is always going to depend on your CPU clock, so we cannot answer for any useable value, without knowing this.

Best Wishes
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Wed Jan 06, 2010 9:24 am     Reply with quote

Can you run the chip from a 32Khz crystal as the master clock and therefore get a much lower PWM frequency?
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