The chapter covers in detail the counter and timer peripherals found on most microcontrollers. Diagrams of the peripheral with all the possible options such as gates, multiplexers, pre-scalers, and post-scalers are shown and explained.
Many C examples are included, with the math used to calculate various characteristics. This chapter also shows how timers and counters are integrated with interrupt processing. The concept of a virtual timer created with software is also included.
This chapter includes a detailed example of using a timer and interrupt to control a relay on the zero-crossing of an AC source.
Examples and exercises are for the popular PIC® microcontroller manufactured by Microchip.