Chapter 18

Timers/Counters

Abstract

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.

Keywords ...

Get Embedded C Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.