PWM - Duty cycle - Is finer adjustment possible?

Thread Starter

atferrari

Joined Jan 6, 2004
3,930
Today I started to experiment with PWM in a 16F877. Got both PWM modules working in minutes.

While period can be finely ajusted with 10-bits precision, the duty cycle seems more complicate due to the two LSB in CCP1CON<5:4>.

I have no specific application in mind but when tried to increase/decrease the duty cycle value I've realized that trying to change it down to the LSB would demand too much code other than INCF / DECF.

For an eventual application requiring a fast adjustment, is it any way to do it or we have to accept adjusting only the value in CCPR1L?

Agustín Tomás
 

nerd256

Joined Nov 21, 2004
23
You can't modify the PWM duty-cycle to its 10-bit precision using only CCPR1L with the 16F87x series. However, with many other PICs, you can specify the justifiction of the 10-bit value, as in CCP1CON<5:4> can represent the LSBs or the MSBs.

However, when you're running this thing at 20MHz, a few extra lines of code won't make that much of a difference, as it takes a while for the CCP module to settle anyways.

Lets say the MSBs are in DCH, and the two LSBs are in DCL<5:4>
you can change the PWM with

movfw DCH
movwf CCPR1L
movfw CCP1CON
andlw b'11001111'
addwf DCL, W
movfw CCP1CON

However, you are correct in saying that INCF and DECF are slower, but the alternative is quite short
 

Thread Starter

atferrari

Joined Jan 6, 2004
3,930
Originally posted by nerd256@Apr 12 2005, 08:25 PM
However, when you're running this thing at 20MHz, a few extra lines of code won't make that much of a difference, as it takes a while for the CCP module to settle anyways.
Yes, that's the point! The time frame I am working in counts a lot!
Thanks.

Agustín Tomás
 
Top