You are viewing an older revision! See the latest version

Accurately measuring duty cycle

Specification

  • To measure the average duty cycle in a PWM/pulse train
  • To accept a minimum high of 3uS
  • To measure to the highest accuracy easily attainable with the mbed
  • To measure signals with frequency 1Hz - 100kHz

Implementation

The LPC1768 (and indeed many others) include Counter/Timer periferal blocks which make this task rather easy. They have the facility to capture the timer value on certain pin toggle events (the CAPn.0/1 inputs). The timer can be configured to count up by ones every clock; record when the signal goes low and record when it goes high again, and have interrupts on either of these events.

Unfortunately the two capture functions (cap 1 and 0) can only work on seperate pins (with a register for storing the value for each) so to measure both high and low going times one is required to short two pins together. In this example we are using Timer 2 and therefore pins 30 and 29


All wikipages