© 2004 Microchip Technology Inc. DS70061C-page 14-7
Section 14. Output Compare
Output
Compare
14
14.3.1.3 Single Compare Mode Toggle Output
To configure the output compare module for this mode, set control bits OCM<2:0> = ‘011’. In
addition, Timer 2 or Timer 3 must be selected and enabled. Once this Compare mode has been
enabled, the output pin, OCx, will be initially driven low and then toggle on each and every
subsequent match event between the Timer and OCxR registers. Referring to Figure 14-4 and
Figure 14-5, there are some key timing events to note:
• The OCx pin is toggled one instruction clock after the compare match occurs between the
compare time base and the OCxR register. The OCx pin will remain at this new state until
the next toggle event, or until a mode change has been made, or the module is disabled.
• The compare time base will count up to the contents in the period register and then reset to
0x0000 on the next instruction clock.
• The respective channel interrupt flag, OCxIF, is asserted 2 instruction clocks after the OCx
pin is toggled.
Figure 14-4: Single Compare Mode: Toggle Output on Compare Match Event (PR2 > OCxR)
Figure 14-5: Single Compare Mode: Toggle Output on Compare Match Event (PR2 = OCxR)
Note: The internal OCx pin output logic is set to a logic ‘0’ on a device Reset. However,
the operational OCx pin state for the Toggle mode can be set by the user software.
Example 14-1 shows a code example for defining the desired initial OCx pin state
in the Toggle mode of operation.
OCxIF
0500
0501 0502
0600
0500
TMRy
1 Instruction Clock Period
0600
0500
PRy
OCxR
0001
OCx pin
TMRy Resets Here
0000
0501 0502
Cleared by User
2 TCY
Note: An ‘x’ represents the output compare channel number. A ‘y’ represents the time base number.
OCxIF
0500
0000 0001
0500
0500
TMR2
Cleared by User
1 Instruction Clock Period
2 TCY
0500
0500
PR2
OCxR
0001
OCx pin
TMRy Resets Here
0000
0000 0001
Cleared by User
2 TCY
2 TCY
TMRy Resets Here
Note: An ‘x’ represents the output compare channel number. A ‘y’ represents the time base number.