PIC32 Output Compare Overview

Last modified by Microchip on 2023/11/10 11:08

The Output Compare (OC) module is one of the peripherals in the PIC32 MCUs. Its operation requires a timer and one or two compare values. Users have the option to select either a 32-bit timer or a 16-bit timer. The timer can be programmed to count at a desired frequency and count up to a desired period value. The OC module compares the value of the timer with the compare values depending on the selected operating mode. When a compare match occurs between a timer value and compare values, the OC module outputs a change of state on its output pins in accordance with the chosen OC compare mode logic. Either a single pulse or a sequence of pulses may be generated.

Operating Modes

  • Single Compare Set High/Low modes: In these compare modes, a compare match between the timer and the buffer (primary compare value) sets the output High/Low. The output remains at the same state after compare match event unless the module is disabled or the mode is changed.
  • Single Compare Toggle mode: Output toggles state at every compare match event between the timer and the buffer (primary compare value)
  • Dual compare Single/Continuous Pulse modes: These modes require two compare values. Leading edge of output pulse is generated during compare match of the incrementing timer and the buffer (primary compare value). Trailing edge of output pulse results when a compare match occurs between the incrementing timer and the pulse width value (secondary compare value). The output may be a single pulse or a sequence of pulses.
  • Pulse-Width Modulation (PWM) modes: In this mode, output goes high when a compare match occurs between timer and the pulse width value (duty cycle). The output is reset back to its initial state when the timer resets after attaining its maximum count. The OC module also provides programmable interrupt generation on a compare match event. In PWM mode, hardware-based Fault detection and automatic output disable features are provided. The figure below shows a block diagram of the OC module. A compare match between the timer value and the compare values generates a pulse at the output.

output compare block diagram

The accompanying image shows a block diagram of the OC module with dedicated timers, present on some devices. It facilitates the use of multiple OC modules operating synchronously or the use of an asynchronous trigger to generate a pulse.

output compare dedicated timer

Learn More

For more details on the OC module for a specific PIC32 device, please view the family reference manual chapter for that device, for example: