![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Hi all I have some few questions regarding PWM.
The PWM period = (PR2+1) * 4 * 1/OSC * TMR2 PS Does the result in seconds or in uS? Ex: If I use PR2 = 255 & Pre Scalar = 16 & XT = 4Mhz the result will be 4096 is this in seconds or in uS? Data sheet says CCPR1L is a 10 bit resolution for PWM function. But the two lower bits from CCP1CON register (bit 4,5). Can I use only CCPR1L as a 8 bit resolution by ignoring the two lower bits of Duty cycle register? Thanks |
|
|
|
|
|
|
(permalink) |
|
This PIC PWM calculator might help.
http://www.micro-examples.com/public...alculator.html |
|
|
|
|
|
|
(permalink) |
|
the result in us , and u could ignored the 5,4 bits , because its the LSbs ......
__________________
Wrong!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
|
|
(permalink) |
|
OK Thanks for the reply,
The thing is when I just load a value to CCPR1L & ignoring the 5,4 bits of CCP1CON register, For example if I load d'1' to CCPR1L will it count from 1 or will it wait until the two lower bits overflows from the CCP1CON 5,4 bits.In this case it will be d'4'. Any idea? |
|
|
|
|
|
|
(permalink) |
|
Hi,
They are still the same. If you're using 8-bit, by loading 1 into CCPR1L, the duty cycle will be 1/256 % If you're using 10-bit, by loading 4 into CCPR1L:CCP1CON[5:4], the duty cycle will be 4/1024 % = 1/256 % Same.
__________________
Superman returns..
|
|
|
|
|
|
|
(permalink) |
|
Suraj143:
Q1)If I use PR2 = 255 & Pre Scalar = 16 & XT = 4Mhz the result will be 4096 is this in seconds or in uS? The number is 0.004096 seconds, this can be read anyway you like. Though usually the answer will reflect the range it is in. For example, if the decimal must move 6 times to the right to reach the first non-zero digit then it will read as uSec. In this case will move 3 times to the right: 0.004096 seconds = 4.096 mSec Q2)The thing is when I just load a value to CCPR1L & ignoring the 5,4 bits of CCP1CON register, For example if I load d'1' to CCPR1L will it count from 1 or will it wait until the two lower bits overflows from the CCP1CON 5,4 bits.In this case it will be d'4'. Any idea? The duty cycle registers CCPR1L (8 MSBs) and the CCP1CON <5:4> (2 LSBs) do not count automatically and there is no overflow-though you can program them to count up/down or to any value you like. If you desire to vary only the CCPR1L register and for example set the CCP1CON <5:4> bits both low then the dutycycle will increment/decrement in values of 4, for example, if we start with 1 in the CCPR1L register and CCP1CON <5:4> bits both low (default), then the dutycycle 10 bit register value is 4: dutycycle;(CCPR1L:CCP1CON <5:4>)=(0000000100) now if we increment the CCPR1L register, we will have; dutycycle;(CCPR1L:CCP1CON <5:4>)=(0000001000) the duty cycle value is now 8, though the CCPR1L register value incremented from 1 to 2. In other words the 2 LSBs of the dutycycle allow for a higher resolution in the dutycycle. If you use only 8 bits of the dutycycle register then you are actually using the 2 LSBs in CCP1CON <5:4> along with the first 6 bits of the CCPR1L register. If the full 8 bits of the CCPR1L register are used - then you are using the full 10 bits of the dutycycle, regardless of what the CCP1CON <5:4> bits are set at, (just a lower resolution) as shown in the formula: PWM (dutycycle)=(CCPR1L:CCP1CON<5:4>)Tosc(TMR2 PSV) Last edited by second286; 15th April 2008 at 10:00 AM. |
|
|
|
|
|
|
(permalink) |
|
I see thanks for clearing the idea.
Even if I load 1 to CCPR1L & CCP1CON <5,4> bits both low the result will be still in 10 bits.So the register value is 4. If I permanently set those CCP1CON <5,4> bits both low then the minimum value I can load is 4.If I connect a LED to the output the led will still be very dim. There are another three steps to fade the LED smoothly to zero.4,3,2,1,0 (fully off). Tell me am I right? |
|
|
|
|
|
|
(permalink) | |
|
Quote:
Oh my god. |
||
|
|
|
|
|
(permalink) |
|
What I got is in PWM module all the calculations done in 10bits.If I need 8 bits I have to wright upto first 6bits of CCPR1L register with the CCP1CON <5:4> bits.
|
|
|
|
|
|
|
(permalink) |
|
Suraj143:
What I got is in PWM module all the calculations done in 10bits.If I need 8 bits I have to wright upto first 6bits of CCPR1L register with the CCP1CON <5:4> bits. Yes! If you actually need a true 8 bit resolution then you must go through the extra work in programming to take into account the 2 dutycycle LSBs. There are another three steps to fade the LED smoothly to zero.4,3,2,1,0 (fully off). Tell me am I right? Yes you are right! Again though going from the minimum of 4 to 0, assuming the CCP1CON <5:4> bits are kept low will not show a smooth dimming. |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| PWM signal problem | iznalgnaij | Robotics Chat | 4 | 25th March 2008 12:40 PM |
| PIC PWM outputs? | Andy1845c | Micro Controllers | 33 | 30th November 2007 03:06 AM |
| PWM using software AtoD | jeremygaughan | Micro Controllers | 11 | 27th November 2007 11:11 PM |
| needed: Microcontroller help | iONic | Micro Controllers | 22 | 6th October 2007 01:30 PM |
| School Bell Controller Final Project - PIC16F628A | Gayan Soyza | Micro Controllers | 21 | 1st October 2007 11:47 AM |