View previous topic :: View next topic |
Author |
Message |
bells_electronics
Joined: 05 Dec 2009 Posts: 40
|
PWM Problem |
Posted: Wed Jan 06, 2010 5:33 am |
|
|
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
|
|
Posted: Wed Jan 06, 2010 6:03 am |
|
|
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
|
|
Posted: Wed Jan 06, 2010 7:15 am |
|
|
Whats the size of the period is it 10-Bit or 8-bit? |
|
|
bells_electronics
Joined: 05 Dec 2009 Posts: 40
|
|
Posted: Wed Jan 06, 2010 8:21 am |
|
|
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
|
|
Posted: Wed Jan 06, 2010 9:17 am |
|
|
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
|
|
Posted: Wed Jan 06, 2010 9:24 am |
|
|
Can you run the chip from a 32Khz crystal as the master clock and therefore get a much lower PWM frequency? |
|
|
|