You are on page 1of 1

using Timer 2 (Timer 1 cannot be used in PWM mode), the value loaded

into this register is calculated as follows: Also, PWM frequency =


1/[PWM Period] The PWM duty cycle is specified by writing to the
OCxRS register. The maximum PWM duty cycle resolution is calculated
using the following formula: where, FPB is the peripheral clock
frequency, and FPWM is the clock frequency of the PWM signal to be
generated. The specifications of this project are summarized below: •
Frequency of the PWM signal = 40 MHz (or, period = 0.025 × 10−3 s) •
Peripheral bus clock frequency = 80 MHz (or 0.0125 × 10−6 s) • Timer
to be used = Timer 2 • Timer 2 prescaler value = 1 • Duty cycle =
50%. The value to be loaded into period register PR2 is calculated as
follows: The maximum PWM resolution is calculated as follows: The
steps for configuring the PWM module for the above specifications are
given below (notice that since we are using output pin OC1, the
register OCxCON is the register OC1CON): • Calculate the PWM period
(0.025 × 10−3) • Calculate the PWM duty cycle (50%) • Use Timer 2 in
16-bit mode • Clear register OC1CON, bit 5 (OC32) for 16-bit
operation • Load PR2 with decimal 1999 • Load OC1RS low 16-bits with
duty cycle (50% duty cycle corresponds to 1999/2 = decimal 1000) • No
interrupts required • Set OCM bits of OC1CON to six to enable PWM
mode of operation • Select Timer 2 as the timer source • Clear TCKPS
bits of T2CON to set Timer 2 prescal

You might also like