The PIC 18FXX2 microcontroller has a Capture/Compare/PWM unit. I understand what capture and PWM are used for. Capture can be used to time the duration of an event. PWM is of course used to generate rectangular waveforms of variable duty cycle. But, I do not understand what the compare function is used for. Is it used to, for example, generate a pulse of a particular duration?
Yes, the compare function can be used to generate very precise high-resolution and low-jitter pulses of various durations (there will be a minimum based on how quickly an interrupt to set the compare registers can be serviced, but there is no practical maximum to the pulse length since rollovers can be accommodated in firmware).
This is possible because the hardware can directly change the port pin state upon a match, and the processor need only set up the next match in time.
PWM is more for when you don't care so much about the period but want a precise ratio of on-to-off time.
Edit: as @gbulmer says the compare can be used to trigger a 'special event' which resets timer 1 and starts and A/D conversion (leaving the port pins untouched). It can also generate a software interrupt. In my experience (others may have different approaches) the most useful mode is to control the output pins directly and leave the counters free running with no resets or writes for cycle-perfect waveforms. The following options are available:
In order to extend the timer's range beyond a 16 bit rollover, a interrupt can be generated that does not alter the output pin, a software counter incremented and the next comparison set up. It's necessary to have a minimum amount of time between setting up the comparison and the next match or the timer could miss the match and roll over again before hitting the count. This requires careful thought and design- one of the costs of using a lower-end 8-bit microcontroller with 16-bit counters rather than 32-bit counters. With a few more bytes extension, the counters can be made to not roll over within a product or a human lifetime.