Datasheet
PIC24FJ64GA104 FAMILY
DS39951C-page 158 2010 Microchip Technology Inc.
14.3 Pulse-Width Modulation (PWM)
Mode
In PWM mode, the output compare module can be
configured for edge-aligned or center-aligned pulse
waveform generation. All PWM operations are
double-buffered (buffer registers are internal to the
module and are not mapped into SFR space).
To configure the output compare module for
edge-aligned PWM operation:
1. Configure the OCx output for one of the
available Peripheral Pin Select pins.
2. Calculate the desired on-time and load it into the
OCxR register.
3. Calculate the desired period and load it into the
OCxRS register.
4. Select the current OCx as the synchronization
source by writing 0x1F to SYNCSEL<4:0>
(OCxCON2<4:0>) and ‘0’ to OCTRIG
(OCxCON2<7>).
5. Select a clock source by writing to the
OCTSEL2<2:0> (OCxCON1<12:10>) bits.
6. Enable interrupts, if required, for the timer and
output compare modules. The output compare
interrupt is required for PWM Fault pin utilization.
7. Select the desired PWM mode in the OCM<2:0>
(OCxCON1<2:0>) bits.
8. If a timer is selected as a clock source, set the
TMRy prescale value and enable the time base by
setting the TON (TxCON<15>) bit.
FIGURE 14-2: OUTPUT COMPARE BLOCK DIAGRAM
(DOUBLE-BUFFERED, 16-BIT PWM MODE)
Note: This peripheral contains input and output
functions that may need to be configured
by the Peripheral Pin Select. See
Section 10.4 “Peripheral Pin Select
(PPS)” for more information.
OCxR and DCB<1:0> Buffers
Comparator
OCxTMR
OCxCON1
OCxCON2
OC Output Timing
OCx Interrupt
OCx Pin
(1)
OCxRS Buffer
Comparator
and Fault Logic
Match
Match
Trigger and
Sync Logic
Clock
Select
Increment
Reset
OC Clock
Sources
Trigger and
Sync Sources
Reset
Match Event
OCFA/OCFB/CxOUT
OCTSELx
SYNCSELx
TRIGSTAT
TRIGMODE
OCTRIG
OCMx
OCINV
OCTRIS
FLTOUT
FLTTRIEN
FLTMD
ENFLTx
OCFLTx
OCxR and DCB<1:0>
OCxRS
Event
Event
Rollover
Rollover/Reset
Rollover/Reset
DCB<1:0>
Note 1: The OCx outputs must be assigned to an available RPn pin before use. Please see Section 10.4 “Peripheral Pin
Select (PPS)” for more information.