Overview

Input Capture and Output Compare blocks provide hardware-based event timing and waveform generation capabilities for precise measurement and control applications. These peripherals operate independently of CPU execution, ensuring deterministic timing for frequency measurement, pulse width detection, servo control, and custom waveform generation.

Available Blocks

IC - Input Capture for Event Timing


OC HW - Hardware Output Compare


OC SW - Software Output Compare


Block Selection Guide

By Application

ApplicationRecommended BlockWhy?
Measure Input FrequencyIC (Input Capture)Hardware captures edge timing automatically
Measure Pulse WidthIC (Input Capture)Captures rising and falling edges
Generate PWMOC_HW (Output Compare)Lightweight alternative to dedicated PWM module
Generate Complex WaveformOC_SW (Software OC)Flexible interrupt-driven control
Servo ControlOC_HW (Hardware OC)Precise pulse generation with zero CPU overhead
Frequency CounterIC (Input Capture)Automatic edge counting and timing

By Performance Requirements

๐ŸŸข Zero CPU Overhead (Hardware-based, autonomous)

  • IC - Event capture happens automatically
  • OC_HW - Output changes controlled by hardware

๐ŸŸก Interrupt-Driven (Flexible but with CPU overhead)

  • OC_SW - Software logic for complex waveforms

IC vs OC Comparison

FeatureInput Capture (IC)Output Compare Hardware (OC_HW)Output Compare Software (OC_SW)
DirectionInput (measure)Output (generate)Output (generate)
CPU OverheadMinimal (interrupt per event)None (autonomous)High (interrupt per change)
Timing Accuracyยฑ1 timer tickยฑ1 timer tickยฑ1 timer tick + ISR latency
FlexibilityFixed modesFixed modesFull software control
Use CaseFrequency/pulse measurementSimple PWM, servo controlComplex waveforms

Hardware Resource Considerations

Input Capture (IC) Modules

  • Dedicated IC peripherals on most dsPIC/PIC32 devices
  • Typical availability: IC1-IC8 (device-dependent)
  • Cannot be used with PWM or OC on same timer
  • Requires timer resource for counting

Output Compare (OC) Modules

  • Dedicated OC peripherals on dsPIC/PIC32 devices
  • Typical availability: OC1-OC16 (device-dependent)
  • Can share timer with other OC modules
  • Requires timer resource for time base

Timer Sharing Rules

โŒ Cannot Share:

  • IC and PWM on same timer
  • IC and OC on same timer
  • Multiple IC modules on same timer

โœ… Can Share:

  • Multiple OC modules on same timer
  • OC and Timer Config blocks

Timing Accuracy

Input Capture Accuracy

  • Capture Latency: Typically 1-2 instruction cycles
  • Jitter: ยฑ1 timer tick (depends on timer resolution)
  • For high precision: Use fastest prescaler possible

Example: dsPIC33CK @ 100 MIPS, Prescaler=1

  • Resolution = 1 / 100 MHz = 10 ns
  • Max measurable period = 10 ns ร— 65536 = 655 ยตs

Output Compare Accuracy

  • Hardware OC: ยฑ1 timer tick (deterministic)
  • Software OC: ยฑ1 timer tick + interrupt latency (5-20 cycles typical)
  • For critical timing: Use Hardware OC (MCHP_OC_HW)

Recommendation: For motor control PWM, use dedicated PWM blocks instead of OC for better performance and features.


Typical Use Cases

Input Capture Applications

Frequency Measurement:

  • Tachometer for motor RPM sensing
  • External clock frequency detection
  • Pulse counting for flow meters

Pulse Width Measurement:

  • RC servo position feedback
  • Ultrasonic ranging (echo pulse width)
  • Duty cycle monitoring

Event Timing:

  • Encoder interface (non-quadrature)
  • Time-of-flight sensors
  • Timing between external events

Output Compare Applications

Simple Waveform Generation:

  • Servo control pulses (1-2 ms pulses at 50 Hz)
  • Stepper motor step pulses
  • General-purpose PWM (when PWM module unavailable)

Timed Events:

  • One-shot pulses for triggering external circuits
  • Delayed output changes
  • Periodic interrupts for software timing

Complex Waveforms:

  • Multi-phase waveforms with software coordination
  • Custom pulse patterns
  • Dynamic timing sequences

Device Family Support Summary

BlockdsPIC30FdsPIC33FdsPIC33EdsPIC33CdsPIC33APIC24PIC32SAM
IC (Input Capture)โœ…โœ…โœ…โœ…โœ…โœ…โœ…โš ๏ธ
OC_HW (Hardware)โœ…โœ…โœ…โœ…โœ…โœ…โœ…โš ๏ธ
OC_SW (Software)โœ…โœ…โœ…โœ…โœ…โœ…โŒโŒ

Legend: โœ… Full Support | โš ๏ธ Different Peripheral (TC/TCC capture/compare) | โŒ Not Available

Note: SAM ARM devices use different timer peripherals (TC/TCC blocks with capture/compare functionality, not dedicated IC/OC modules).


See Also

Related Block Categories:

  • Timers - For timer configuration and resource management
  • PWM Blocks - For advanced PWM generation (preferred for motor control)
  • Encoders - For quadrature encoder interfaces (QEI block)

Recommended Reading:

  • Input Capture: Use for non-quadrature encoders, tachometers, frequency counters
  • Output Compare: Use for servo control, simple pulse generation
  • For motor PWM: Use dedicated PWM blocks instead of OC

Example Projects:


๐Ÿ’ก Quick Selection Guide:

  • Need to measure something? โ†’ Input Capture (IC)
  • Need to generate simple pulses? โ†’ Output Compare Hardware (OC_HW)
  • Need complex waveforms? โ†’ Output Compare Software (OC_SW)
  • For motor control PWM โ†’ Use dedicated PWM blocks

IC - Input Capture Block

The MCHP_IC block captures hardware timer values when external events occur on input pins. It enables precise measurement of pulse widths, periods, โ€ฆ

Read more โ†’

OC HW - Output Compare (Hardware)

The MCHP_OC_HW block provides hardware-based output generation using the Output Compare (OC) peripheral. It generates PWM signals, toggles outputs, โ€ฆ

Read more โ†’

OC SW - Software Output Compare

The MCHP_OC_SW block provides interrupt-driven software output compare functionality. Unlike hardware OC which operates autonomously, this block uses โ€ฆ

Read more โ†’