5.3 Timing, Measurement, and Waveforms
Timer/Counter (TC)
The PIC16F, PIC18F and PIC32CM Timer/Counter peripherals are utilized for timing, waveform generation, input capture, and event handling. Both MCUs support multiple timer types with varying features for precise timing and waveform control.
While PIC32CM has timer modules that offer most of these features, both PIC16F and PIC18F require additional peripherals for capture/compare (CCP/ECCP) and waveform generation (CCP/ECCP/PWM). Newer PIC18F devices also feature PWMs that do not require external timers. The table below compares the features of the PIC16F, PIC18F, and PIC32CM MCUs.
| Feature | PIC16F Timers | PIC18F Timers | PIC32CM Timers |
|---|---|---|---|
| Timer Variants | Timer0 (8-bit), Timer1/3/5 (16-bit),
Timer2/4/6/8/12 (8-bit) Signal Measurement Timer (SMT) | Timer0 (8-bit), Timer1/3/5 (16-bit),
Timer2/4/6/8/12 (8-bit) Signal Measurement Timer (SMT) Universal Timer (UTMR) | Timer/Counter (TC,
16/32-bit) Timer/Counter for Control (TCC) |
| Resolution | 8-bit, 16-bit, 24-bit (SMT), | 8-bit, 16-bit, 24-bit (SMT), 32-bit (cascaded UTMR) | 8-bit, 16-bit, or 32-bit (selectable) |
| Prescaler | Programmable | Programmable | Programmable |
| Capture/Compare Channels | CCP/ECCP | Up to 7 (through CCP/ECCP) | Up to four |
| PWM Generation | Through (Enhanced) Capture/Compare/PWM - (E)CCP Standalone PWMs | Through (Enhanced) Capture/Compare/PWM - (E)CCP Standalone PWMs | Through TCx, TCC |
| PWM Modes | Standard Enhanced (Half/Full-Bridge) Steering | Standard Enhanced (Half/Full-Bridge) Steering | Single/Dual-Slope |
| Special Modes | SMT for relative timing | Hardware Limit Timer (HLT) for fault
detection SMT for relative timing UTMR chaining | Circular buffer, multiple output events |
| Signal Measurement | SMT | SMT and UTMR | Frequency Meter, advanced TC |
| Buffering | Double buffering for PWM duty cycle only | Double buffering for PWM duty cycle only | Double-buffered period/compare/capture |
| Fault Protection | Auto-shutdown/Restart | Auto-shutdown/Restart | Recoverable/non-recoverable fault sources |
| Event System | N/A | Inter-peripheral triggering through Signal Routing Port (SRPORT) for newer devices | Integrated for input/output events, synchronization |
| Direct Memory Access (DMA) | N/A | Supported | Supported |
| Interrupts | Overflow Compare Match Input Capture Gate Event | Overflow Compare match Input capture Gate Event | Overflow Compare match Input capture Error Fault |
| Waveform Extensions | Through Complementary Output Generator (COG) | Through Complementary Waveform Generator (CWG) | Timer Counter for Control Applications (TCC) |
| RTC/ Calendar Timer | Using TMR1 | Using TMR1 or a dedicated RTCC module | Dedicated RTC module |
Advanced Waveform Generators
The PIC16F/PIC18F Complementary Output/Waveform Generator (COG and CWG) peripherals have similar features to the PIC32CM Waveform Extensions for precise and safe waveform control in advanced motor, power, LED control, and similar applications. COG and CWG provide reliable complementary PWM generation for PIC16F/PIC18F applications, with COG offering more advanced features in select PIC16F devices. PIC32CM WEX delivers a comprehensive, event-driven waveform generation system for modern, high-performance embedded designs.
The table below compares the features of PIC16F, PIC18F, and PIC32CM.
| Feature | PIC16F COG | PIC16F/PIC18F CWG | PIC32CM WEX |
|---|---|---|---|
| Peripheral Type | COG (Complementary Output
Generator) CWG (Complementary Waveform Generator) | CWG (Complementary Waveform Generator) | WEX (Waveform Extension) |
| Complementary Outputs | Supported | Supported | Supported |
| Output Distribution | Steering modes (Synchronous/Asynchronous) | Steering modes (Synchronous/Asynchronous) | Output Matrix (OTMX) with multiple routing modes |
| Dead-Time Insertion | Dual independent 6-bit rising and
falling timers Double-buffered | Dual independent 6-bit rising and
falling timers Double-buffered | Four DTI units Common register 8-bit resolution Double-buffered |
| Swap Functionality | Handled through mode selection or direction change logic | Handled through mode selection or direction change logic | Waveform swap option with double buffer support |
| Pattern Generation | Relies on steering mode for static levels | Limited to manual output overrides | Double-buffered Dithering support |
| Dithering | N/A | N/A | Supported |
| Port Override/Disable | PPS routing | PPS routing | N/A |
| Fault Protection | Auto-shutdown
Auto-restart | Auto-shutdown
Auto-restart | Fault protection for safe and deterministic shutdown |
| PWM Resolution | Moderate (typically 10-12 bits) | Moderate (typically 10 bits) | High (up to 16 bits or more) |
Real-Time Counters (RTC)
The PIC16F and most PIC18F devices rely on TMR1 for basic RTC functionality, while some PIC18F and all PIC32CM families provide a dedicated, feature-rich RTC peripheral for modern embedded timekeeping needs. The table below compares the features of PIC16F, PIC18F, and PIC32CM.
| Feature | PIC16F RTCC/TMR1 | PIC18F RTCC/TMR1 | PIC32CM RTC |
|---|---|---|---|
| RTC Peripheral | RTCC TMR1 with 32.768 kHz crystal | RTCC TMR1 with 32.768 kHz crystal | RTC |
| Counter Resolution | Binary Coded Decimal (BCD) format for time/date | Binary Coded Decimal (BCD) format for time/date | 32-bit (or two 16-bit) |
| Prescaler | 2-bit programmable (Timer1) | 2-bit programmable (Timer1) | 10-bit programmable |
| Compare Registers | Alarm registers for Sec/Min/Hour/Day/Month/WD | Alarm registers for Sec/Min/Hour/Day/Month/WD | 2 (32-bit) or 4 (16-bit mode) |
| Period Register | N/A | N/A | One |
| Maximum Timeout (32.768 kHz) | More than 100 years (1s resolution) | More than100 years (1s resolution) | More than 136 years (1s resolution) |
| Clock/Calendar Mode | Supported (time/date, leap year correction) | Supported (time/date, leap year correction) | Supported (time/date, leap year correction) |
| Clock Correction | Periodic auto-adjust | Periodic auto-adjust | Digital frequency (prescaler) correction/tuning |
| Periodic Interrupt Timer (PIT) | Alarm repeat counter (up to 255 times) | Alarm repeat counter (up to 255 times) | Integrated periodic wake-up/event functionality |
| Interrupts/Events | Alarm Match, Timer Overflow | Alarm Match, Timer Overflow | Overflow, alarm/compare, prescaler, periodic |
| Clear on Match | Available, resets counter to zero/initial date upon alarm match | Available, resets counter to zero/initial date upon alarm match | Optional on alarm/compare match |
| Timekeeping | Hardware clock and calendar or Software-implemented (TMR1-based) | Hardware clock and calendar or Software-implemented (TMR1-based) | Hardware clock and calendar, alarms, backup registers |
| Low-Power Operation | TMR1 or RTCC can run in Sleep/Deep Sleep | TMR1 or RTCC can run in Sleep/Deep Sleep | RTC runs in Standby/Off |
| Alarm/Wake-up Function | RTC alarm TMR1 interrupt | RTC alarm TMR1 interrupt | Multiple alarms, Event triggers |
| Backup Battery Support | Supported | Supported | Supported |
| Event System Integration | N/A | N/A | Supported |
