Introduction
Author: Justin Bauer and Jonah Lerner, Microchip Technology Inc. |
Many times it is desirable to quantify the pulse width of a periodic signal, such as a servo motor or duty cycle of a pulse-width modulated signal. There are other instances where a pulse that is non-periodic needs to be measured, such as those found in a Capacitive Discharge ignition circuit. This application note describes six different methods to measure a pulse of both periodic and non-periodic waveforms as well as six methods for calculating a duty cycle of a periodic waveform using an 8-bit PIC® device.
Depending on the microcontroller chosen and what peripherals are being used, the design may require a more obscure solution then anticipated, which is why this document includes numerous methods. Some of the methods mentioned in this document utilize the Configurable Logic Cell (CLC) and Numerically Controlled Oscillator (NCO). These are core independent peripherals that can be found on newer microcontrollers and provide a hardware-based solution with minimal software overhead.
All of the methods in this application note include associated software routines. The end result of each may differ from the results given in the document for numerous reasons, such as the clock speed of the PIC microcontroller, software optimization, and general environment setup.