class TimerChannel – setup a channel for a timer

A TimerChannel represents one of the output-compare or input-capture channels of a Timer. Channels are not constructed directly; they are returned by Timer.channel(), which both configures the channel and hands back the wrapper object:

timer = pyb.Timer(2, freq=1000)
ch2 = timer.channel(2, pyb.Timer.PWM, pin=pyb.Pin.board.P1,
                    pulse_width_percent=25)

The methods below adjust the channel’s compare/capture register at runtime and install per-channel callbacks.

Constructors

class pyb.TimerChannel

TimerChannel objects are not constructed directly. Use Timer.channel() to obtain one.

Methods

callback(fun: Callable[[Timer], None] | None) None

Set the function to be called when the timer channel triggers. fun is passed 1 argument, the timer object. If fun is None then the callback will be disabled.

capture(value: int | None = None) int | None

Get or set the capture value associated with a channel. capture, compare, and pulse_width are all aliases for the same function. capture is the logical name to use when the channel is in input capture mode.

compare(value: int | None = None) int | None

Get or set the compare value associated with a channel. capture, compare, and pulse_width are all aliases for the same function. compare is the logical name to use when the channel is in output compare mode.

pulse_width(value: int | None = None) int | None

Get or set the pulse width value associated with a channel. capture, compare, and pulse_width are all aliases for the same function. pulse_width is the logical name to use when the channel is in PWM mode.

In edge aligned mode, a pulse_width of period + 1 corresponds to a duty cycle of 100% In center aligned mode, a pulse width of period corresponds to a duty cycle of 100%

pulse_width_percent(value: int | float | None = None) int | float | None

Get or set the pulse width percentage associated with a channel. The value is a number between 0 and 100 and sets the percentage of the timer period for which the pulse is active. The value can be an integer or floating-point number for more accuracy. For example, a value of 25 gives a duty cycle of 25%.