This repository has been updated and moved to here
Please use the new repository!
OLD TEXT:
Most microcontrollers have hardware to produce Pulse Width Modulation (PWM) signals. But sometimes it is useful to be able to read PWM signals and determine the period, pulse width and duty cycle.
Based on the method to measure pulses with PIO code as described here, a PWM Input can be made.
In pseudo-code the algorithm is as follows:
loop:
reset the 'timer'
loop:
decrement timer
test for falling edge
record timer value as pulse width (actually, (0xFFFFFFFF - x)*2*1/125MHz is the pulse width)
loop:
test for rising edge
decrement timer
record the timer value as period (actually, (0xFFFFFFFF - x)*2*1/125MHz is the peropd)