hardware_pwm
Library FunctionsTo use this library, add following to the C/C++ file,
#include <hardware/pwm.h>
and following to the CMakeLists.txt
file.
target_link_libraries(projectName pico_stdlib hardware_gpio hardware_pwm)
Following are some of the most commonly used functions for configuring the PWM peripheral.
uint8_t pwm_gpio_to_slice_num(uint8_t pinNo)
Get the PWM slice number for a GPIO number.
pinNo
can be any GPIO number, i.e. 0 through 29.uint8_t pwm_gpio_to_channel(uint8_t pinNo)
Get the PWM channel number for a GPIO number.
pinNo
can be any GPIO number, i.e. 0 through 29.pwm_set_clkdiv_int_frac(uint8_t sliceNum, uint8_t divInt, uint8_t divFrc)
Configure the clock divider integer and fractional values.
sliceNum
is the PWM slice number that you may want to configure.divInt
is the 8-bit integer part of the clock divider, 1 through 255.divFrc
is the 4-bit fractional part of the clock divider, 0 through 15.pwm_set_wrap(uint8_t sliceNum, uint16_t top)
Configure the counter wrap value.
sliceNum
is the PWM slice number that you may want to configure.top
is the 16-bit counter wrap value, 0 through 65535.pwm_set_chan_level(uint8_t sliceNum, uint8_t chanNum, uint16_t cc)
Configure the counter compare value.
sliceNum
is the PWM slice number that you may want to configure.chanNum
is the channel number of the slice that you may want to configure.cc
is the 16-bit counter compare value, 0 through 65535.pwm_set_enabled(uint8_t sliceNum, bool enabled)
Enable or disable the PWM output.
sliceNum
is the PWM slice number that you want to enable or disable.enabled
must be a boolean value, i.e. 0
to disable the output and 1
to enable the output.