A Class which uses a Serial Wombat pin to measure the length of a pulse high and low time.
This class is used to measure the length of pulses in mS or in uS. On the Serial Wombat 4A/B the precision is about 8uS in uS mode, with an accuracy of +/- 2% because of variation in the Serial Wombat chip's internal oscillator.
This pinmode is useful for measuring RC Servo outputs, PWM frequency and duty cycle, or any other signal where the pulse width is relevant. It is designed to measure repetitive signals. It is not intended to read a number of differing independent pulse widths that come one after another, such as WS2812 or similar output.
Warning
Care must be taken when using this pinmode with high frequency ( > 5 kHz) signals or pins that may be left floating on the Serial Wombat 4A / 4B because the Serial Wombat 4A and 4B chip uses an interrupt internally to capture transition timestamps. Excessively frequent pin transitions may cause the interrupt handler to starve the main processing loop, impacting function of all pin modes and communications.
The Serial Wombat chip can be queried for overflow frames. If overflow frames are occuring, then the system is overloaded.
The Serial Wombat 4A and 4B chips can measure a maxium of 8 transitions per mS across all pulse input pins. More frequent transitions than this may result in incorrect measurements. The MeasurementOverflowOccurred flag is set if at any time more than 8 transitions occured without processing.
The Serial Wombat 18AB chip uses a DMA based sampling scheme with samples taken at 57600 Hz. It has lower resolution than the Serial Wombat 4A/B (17 uS resolution), but can measure up to 18 simultaneous pulse trains and is not subject to being overloaded by faster signals.
The number of pulses over time can be used for rough frequency measurements.
Consecutive High and low periods can be used to calculate duty cycle, although there is no indication whether high or low was most recent.