PWM — Pulse Width Modulation interface

Enables access to the Pulse Width Modulation (PWM) module, to easily and accurately generate a PWM output signal of a given duty cycle and frequency.

Note

You need to be part of the pwm group of the OS running on the Beaglebone to be able to run PWM code as a non-root user. The default user created upon the Debian image installation should already be part of the group. Otherwise, you can use sudo usermod -a -G pwm userName to add userName to the group.

Adafruit_BBIO.PWM.start(channel, duty_cycle[, frequency=2000, polarity=0])

Set up and start the given PWM channel.

Parameters:
  • channel (str) – PWM channel. It can be specified in the form of of ‘P8_10’, or ‘EHRPWM2A’.
  • duty_cycle (int) – PWM duty cycle. It must have a value from 0 to 100.
  • frequency (int) – PWM frequency, in Hz. It must be greater than 0.
  • polarity (int) – defines whether the value for duty_cycle affects the rising edge or the falling edge of the waveform. Allowed values – 0 (rising edge, default) or 1 (falling edge).
Adafruit_BBIO.PWM.stop(channel)

Stop the given PWM channel.

Parameters:channel (str) – PWM channel. It can be specified in the form of of ‘P8_10’, or ‘EHRPWM2A’.
Adafruit_BBIO.PWM.set_duty_cycle(channel, duty_cycle)

Change the duty cycle of the given PWM channel.

Note:

You must have started the PWM channel with start() once, before changing the duty cycle.

Parameters:
  • channel (str) – PWM channel. It can be specified in the form of of ‘P8_10’, or ‘EHRPWM2A’.
  • duty_cycle (int) – PWM duty cycle. It must have a value from 0 to 100.
Adafruit_BBIO.PWM.set_frequency(channel, frequency)

Change the frequency of the given PWM channel.

Note:

You must have started the PWM channel with start() once, before changing the frequency.

Parameters:
  • channel (str) – PWM channel. It can be specified in the form of of ‘P8_10’, or ‘EHRPWM2A’.
  • frequency (int) – PWM frequency. It must be greater than 0.
Adafruit_BBIO.PWM.cleanup()

Clean up by resetting all GPIO channels that have been used by this program to INPUT, with no pullup/pulldown and no event detection.