4tronix / PiconZero

Initial commit
13 stars 11 forks source link

Read Pwm input #6

Closed mjhenkes closed 7 years ago

mjhenkes commented 7 years ago

This pull request adds the ability for the picon zero to read PWM input in two forms.

  1. PWM input can be read in and reported as the duty cycle.
  2. PWM input can be read in and reported as simply the Pulse Width. This is mainly for cases where there is a very large period and the duty cycle is not precise enough.

To use simply set the python function setInputConfig to 4 for Duty Cycle or 5 for PW. The period defaults to 2000 microseconds or can be set.

pz.setInputConfig(0, 5, period = 2200)

To get the value back use the read input function.

pz.readInput(0)

Behind the scenes in the Arduino code we use a new dependency EnableInterupt to capture the signal edges on the input pins, then measure the time between high and low edges to determine the pulse width. See Issue #4 for more explanation.

Fixes #4

mjhenkes commented 7 years ago

One other note. When the period is exceeded, If the input config is set to Duty Cycle (4) the duty cycle will be set based on the last edge, if low 0%, if high 100% . If the input config is set to PW (5) when the period is exceeded the input will be set to 0 as there is no pulse.