ABSTRACT

Microcontrollers need to have internal resources to accurately measure time. Each programmable integrated circuit (PIC) microcontroller has at least one basic timer module called Timer0, although the majority of medium-end PICs can have two additional timers: Timer1 and Timer2. The chapter describes the structure, function, and programming of each one of the capture/compare/pulse width modulation modules, and illustrates with examples of how they work and how they are programmed. Each one of the timers in a medium-end programmable integrated circuit microcontroller is based on an 8-bit or 16-bit incrementing synchronous counter. These counters can be programmed to count internal or external pulses. Timer0 can be configured to count machine cycles or to count external pulses. When counting machine cycles it is said to operate as a timer. When counting external pulses, it is said that it operates as a counter.