PWM input support
The new features and capababilities for moteus just keep coming! Here is another relatively straightforward one available in firmware release 2026-01-21, support for PWM (pulse-width-modulated) inputs. If an appropriate pin is configured, moteus can report the period and duty cycle of a PWM input to applications. This can be used to monitor the fan RPM for the moteus cooling fans on moteus-c1, moteus-n1, or moteus-x1, or could be used to read the value of a RC receiver output. Read on to learn how to use it and what the limitations are:
Configuration and use
Configuration is relatively straightforward. First select the PWM input type for the pin in question:
aux2.pins.3.mode 12 # pwm_input
Then enable PWM input on that auxiliary port.
aux2.pwm_input.enabled 1
In tview, the resulting period and pulse-width can be viewed at:
aux2.pwm_input.period_us
and
aux2.pwm_input.pulse_width_us
If you then want to measure the RPM of a connected fan in python, you could do:
qr = moteus.QueryResolution()
qr.aux2_pwm_input_period_us = moteus.F32
c = moteus.Controller(query_resolution=qr)
results = await c.query()
fan_period_us = results.values[moteus.Register.AUX2_PWM_INPUT_PERIOD]
fan_rpm = 60000000 / (fan_period_us * 2)
Limitations
As designed, moteus can only support one PWM input per auxiliary port and that input must be configured on a pin listed as supporting PWM or hardware quadrature in the pinout diagrams.
The period is reported in microseconds, and can only be sensed up to 65535 microseconds, although in practical applications, you would not want to rely on sensing periods that close to the limit.
In tview, the duty cycle is reported in microseconds, although over the register procotol, and thus the python and C++ libraries it is reported as a fraction between 0 and 1. However, the resolution is only to the nearest microsecond. So for instance, a typical RC servo outputs a pulse that is 1.5ms when centered, 1ms at one extreme and 2ms at the other extreme. Since the duty cycle is only measured to the nearest microsecond, that means there are only 1000 discrete duty cycle values that can be measured for that input waveform.