+ Reply to Thread
Results 1 to 6 of 6

Thread: PWM - Duty cycle - Finer adjustment is possible?

  1. #1
    atferrari Good atferrari Good atferrari Good
    Join Date
    Oct 2003
    Location
    Buenos Aires - Argentina
    Posts
    571

    Default PWM - Duty cycle - Finer adjustment is possible?

    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 :?:


  2. #2
    Super Moderator Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent Nigel Goodwin Excellent
    Join Date
    Nov 2003
    Location
    Derbyshire, UK
    Posts
    29,730

    Default Re: PWM - Duty cycle - Finer adjustment is possible?

    Quote Originally Posted by atferrari
    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.
    PIC programmer software, and PIC Tutorials at:
    http://www.winpicprog.co.uk

  3. #3
    atferrari Good atferrari Good atferrari Good
    Join Date
    Oct 2003
    Location
    Buenos Aires - Argentina
    Posts
    571

    Default 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

  4. #4
    motion Newbie
    Join Date
    Jul 2003
    Location
    Quezon City.PH
    Posts
    560

    Default

    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>.
    "Having to do with Motion Control"

  5. #5
    motion Newbie
    Join Date
    Jul 2003
    Location
    Quezon City.PH
    Posts
    560

    Default

    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.
    "Having to do with Motion Control"

  6. #6
    atferrari Good atferrari Good atferrari Good
    Join Date
    Oct 2003
    Location
    Buenos Aires - Argentina
    Posts
    571

    Default Things I didn't consider

    Thanks Motion,

    More things to keep into account.

    Little by little, I am learning.

    Agustín Tomás

+ Reply to Thread

Tags for this Thread