pwm (Application)

The pwm app is used to configure the PWM output ports used for servo and ESC control.

pwm: usage:
pwm arm|disarm|rate|failsafe|disarmed|min|max|test|info  ...

  arm                      Arm output
  disarm                   Disarm output

  rate ...                 Configure PWM rates
    [-g <channel group>]   Channel group that should update at the alternate rate
    [-m <chanmask> ]       Directly supply channel mask
    [-a]                   Configure all outputs
    -r <alt_rate>          PWM rate (50 to 400 Hz)

  failsafe ...              Configure failsafe PWM values
  disarmed ...              Configure disarmed PWM values
  min ...                   Configure minimum PWM values
  max ...                   Configure maximum PWM values
    [-c <channels>]        Supply channels (e.g. 1234)
    [-m <chanmask> ]       Directly supply channel mask (e.g. 0xF)
    [-a]                   Configure all outputs
    -p <pwm value>         PWM value

  test ...                 Directly set PWM values
    [-c <channels>]        Supply channels (e.g. 1234)
    [-m <chanmask> ]       Directly supply channel mask (e.g. 0xF)
    [-a]                   Configure all outputs
    -p <pwm value>         PWM value

  info                     Print information about the PWM device

    -v                     Print verbose information
    -d <device>            PWM output device (defaults to /dev/pwm_output0)

Displaying PWM State

The pwm info will print out the current PWM pulse width values. If the -d argument is not specified, the tool uses the default PWM device /dev/pwm_output0.

nsh> pwm info
device: /dev/pwm_output
channel 1: 900 us (alternative rate: 400 Hz failsafe: 900, disarmed: 900 us, min: 1175 us, max: 1900 us)
channel 2: 900 us (alternative rate: 400 Hz failsafe: 900, disarmed: 900 us, min: 1175 us, max: 1900 us)
channel 3: 900 us (alternative rate: 400 Hz failsafe: 900, disarmed: 900 us, min: 1175 us, max: 1900 us)
channel 4: 900 us (alternative rate: 400 Hz failsafe: 900, disarmed: 900 us, min: 1175 us, max: 1900 us)
channel 5: 0 us (default rate: 50 Hz failsafe: 1500, disarmed: 0 us, min: 1000 us, max: 2000 us)
channel 6: 0 us (default rate: 50 Hz failsafe: 1500, disarmed: 0 us, min: 1000 us, max: 2000 us)
channel 7: 0 us (default rate: 50 Hz failsafe: 1500, disarmed: 0 us, min: 1000 us, max: 2000 us)
channel 8: 0 us (default rate: 50 Hz failsafe: 1500, disarmed: 0 us, min: 1000 us, max: 2000 us)
channel group 0: channels 1 2
channel group 1: channels 5 6 7 8
channel group 2: channels 3 4

The update rate can be only set per group. The channel groups are:

  • channel group 0: channels 1 2
  • channel group 1: channels 5 6 7 8
  • channel group 2: channels 3 4

If the -c argument is used all channels of any included group must be included, e.g. -c12 or -c125678.

Setting Update Rates

The PX4 PWM driver API supports two PWM pulse output rates; default and alternate. The default rate is 50Hz for maximum compatibility with normal R/C equipment, and the alternate rate can be set with the -u argument to the pwm command. Most drivers will accept alternate rates between 50 and 400Hz.

Often the update rate for several channels must be adjusted together. Channels whose rates must be the same for hardware reasons are referred to as channel groups. The channels in each channel group are listed at the bottom of the pwm info output.

nsh> pwm rate -g 0 -r 400

As default no channels are set to the alternate rate mask. This is in order to prevent a servo damage / fire, which can happen when setting 400 Hz accidentally to the wrong channels where analog servos are connected.

Test output

First disable the safety by pressing long on the safety switch before attempting to arm

To test the outputs of e. g. channel 1 and 3 and set them to the PWM value of 1200 us, type this:

nsh> pwm arm
nsh> pwm test -c 13 -p 1200
Translations of this page:


Quick Links

QR Code: URL of current page