# Question on dsPIC33F PWM Period and Duty Cycle Calculation

On the Microchip dsPIC33F family, the PWM period PTPER is calculated as:

PTPER = (FCY/FPWM)*(PTMR Prescaler Value) - 1

where PTMR is the input clock to the PWM and FCY = Fosc/2, FCY being the instruction cycle frequency and Fosc the main clock frequency. It is specified that the input clock to PTMR is Fosc/4 (ref. doc: DS70165D-page 178). Does this mean that the period is calculated in instruction cycle clock ticks, or twice the instruction cycle clock ticks? Does this information relate to why multiply PTPER by 2 in the following line of code (taken from Microchip Application Note AN957):

PDC1 = (int)(((long)(PTPER*2)*(long)DutyCycle) >> 15); // why multiply PTPER by 2?
PDC2 = PDC1;                      // PDCx is the duty cycle register for PWMx channel
PDC3 = PDC2;                      // x = 1,2,3


In my understanding, the factor of 2 shouldn't be there. A more complete version of this code was posted yesterday at this forum: Help understanding the code

• The clock prescaler beings used is 1:1 – Adeel Apr 8 '15 at 9:45