PWM¶
Code Example¶
from periphery import PWM
# Open PWM chip 0, channel 10
pwm = PWM(0, 10)
# Set frequency to 1 kHz
pwm.frequency = 1e3
# Set duty cycle to 75%
pwm.duty_cycle = 0.75
pwm.enable()
# Change duty cycle to 50%
pwm.duty_cycle = 0.50
pwm.close()
API¶
-
class
periphery.PWM(chip, channel)[source]¶ Bases:
objectInstantiate a PWM object and open the sysfs PWM corresponding to the specified chip and channel.
Parameters: - chip (int) – PWM chip number.
- channel (int) – PWM channel number.
Returns: PWM object.
Return type: Raises: PWMError– if an I/O or OS error occurs.TypeError– if chip or channel types are invalid.LookupError– if PWM chip does not exist.TimeoutError– if waiting for PWM export times out.
-
PWM_STAT_RETRIES= 10¶
-
PWM_STAT_DELAY= 0.1¶
-
devpath¶ Get the device path of the underlying sysfs PWM device.
Type: str
-
chip¶ Get the PWM chip number.
Type: int
-
channel¶ Get the PWM channel number.
Type: int
-
period_ns¶ Get or set the PWM’s output period in nanoseconds.
Raises: PWMError– if an I/O or OS error occurs.TypeError– if value type is not int.
Type: int
-
duty_cycle_ns¶ Get or set the PWM’s output duty cycle in nanoseconds.
Raises: PWMError– if an I/O or OS error occurs.TypeError– if value type is not int.
Type: int
-
period¶ Get or set the PWM’s output period in seconds.
Raises: PWMError– if an I/O or OS error occurs.TypeError– if value type is not int or float.
Type: int, float
-
duty_cycle¶ Get or set the PWM’s output duty cycle as a ratio from 0.0 to 1.0.
Raises: PWMError– if an I/O or OS error occurs.TypeError– if value type is not int or float.ValueError– if value is out of bounds of 0.0 to 1.0.
Type: int, float
-
frequency¶ Get or set the PWM’s output frequency in Hertz.
Raises: PWMError– if an I/O or OS error occurs.TypeError– if value type is not int or float.
Type: int, float