Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PWM - Duty cycle - Finer adjustment is possible?

Status
Not open for further replies.

atferrari

Well-Known Member
Most Helpful Member
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 :?:
 
atferrari said:
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 :?:

You seem to be forgetting the speed a PIC runs at?. If you're clocking the PIC at 20MHz you should be easily able to update all 10 bits in under 2uS. This should be much more than fast enough for any possible application?.

But on the other hand, do you require 10 bit anyway?, and assuming you did? (or thought you did!), updating it far faster than it needs to be is simple.
 
Thanks Nigel

Yes, I forgot I can run it up to 20 MHz. :)

Being a theoretical question (plus my lack of experience in this - an so many other aspects of micros) I had no valid reference to say "too much" or "enough".

By no means I am asking you to write any code but could you please tell me what is the best way to make an easy update of duty cycle, if 10 bits resolution is needed?

Using a 16-bit shadow register seems TOO MUCH, isn't it?

Gracias for your time.

Agustín Tomás
 
Because the duty cycle control is transferred to the slave register only at the end of a PWM period, the rate of change of the PWM duty is no faster than once every 51.2usec (@10-bit resolution) even if you found an efficient way to alter CCP1CON<5:4>.
 
Using a 16-bit shadow register seems TOO MUCH, isn't it?

You'd need one anyway for computation purposes if you wanted to do any thing useful out of the PWM module.
 
Things I didn't consider

Thanks Motion,

More things to keep into account.

Little by little, I am learning. :)

Agustín Tomás
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top