16F886 PWM help

Status
Not open for further replies.

Mosaic

Well-Known Member
Hi:

I'm looking at the data sheet and I find that :
1) The PR2 register sets the frequency based on Fosc (8Mhz in my case)
2) The Pulse width is based on the (CCPR2L : ccp2con (5:4)) * Tmr2 prescale / 8Mhz
3) The duty cycle is based on ( CCPR2L : ccp2con (5:4))/(4(1+PR2))

So it seems I cannot alter the duty cycle without also either altering the frequency (PR2) or the pulse width (CCPR2L : ccp2con (5:4))

Is this correct? Duty cycle change forces a change to the pulse width or a change to the frequency?

If so then I have to do s'ware PWM to alter the duty cycle BY ITSELF.
 
PR2 plus the prescaler of timer2 set the frequency.
CCPRL set the duty cycle. Min is zero, max is PR2. The 2 additional bits in CCPCON are fine tuning bits and define when to switch depending on the internal divide by 4 cycle.

Note, the pulse width IS the duty cycle or rather Period/PulseWidth = DutyCycle. Changing the duty cycle (CCPRL) can never change the frequency.

Mike.
 
Last edited:
What will change the pulse width? As well as what?

If you mean CCPRL then that is what it's supposed to do!!

Mike.
 
Last edited:
How do you plan on changing the Duty Cycle without changing the Pulse Width or the Frequency??

If you want to change the duty cycle, then by definition either the Frequency or the Pulse Width must change.
 
Well consider this: 10Hz Frequency.

1% pulsewidth is 1 ms pulsewidth, a 100 ms Period. This is the pulse width I am speaking of, not the on time.

1% duty => 1 pulse width on & 99 pulse widths off.....pulse width is still 1 ms. Period still 100ms, freq still 10Hz.

99% duty cycle => 99 pulse widths on and 1 pulse width off...pulse width still 1 ms.Period still 100ms, freq still 10Hz.

The On time pulse is just a set of sequential discrete 1ms pulses.


Neither this discrete pulse width nor the frequency have to change to alter the duty cycle......This is what I am asking about.

I guess I am looking at it thru a 1 ms interrupt s'ware lens. I suppose if we consider a single dynamic pulse the 'on time' then the pulse width MUST change to alter the duty.

Anyway..explaining myself helped me see the light!
 
Last edited:
In your second example the pulse width is 99ms. Unless the PWM is inverted, in which case the duty cycle would be 1%.

In this example, the pulse width is directly tied to the duty cycle; If you have a 20ms pulse and a 100ms period, then the pulse width is 20ms and the duty cycle is 20%.

edit: posted before I saw your edit
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…