Hello
I need to configure PWM on 16 MHz clock and i really don't know how to do this via device tree.
Hello
I need to configure PWM on 16 MHz clock and i really don't know how to do this via device tree.
I'll take a look at this and provide you with an answer tomorrow
Best regards,
Simon
Thought i would check the driver implementation in file pwm_nrfx.c.
It turned out that apart from assigning pins to individual channels, all other PWM configs are default and it is not possible to configure them from the device tree level.
Part of pwm_nrfx.c
#define PWM_NRFX_DEVICE(idx) \
static struct pwm_nrfx_data pwm_nrfx_##idx##_data; \
static const struct pwm_nrfx_config pwm_nrfx_##idx##config = { \
.pwm = NRFX_PWM_INSTANCE(idx), \
.initial_config = { \
.output_pins = { \
PWM_NRFX_OUTPUT_PIN(idx, 0), \
PWM_NRFX_OUTPUT_PIN(idx, 1), \
PWM_NRFX_OUTPUT_PIN(idx, 2), \
PWM_NRFX_OUTPUT_PIN(idx, 3), \
}, \
.base_clock = NRF_PWM_CLK_1MHz, \
.count_mode = PWM_NRFX_COUNT_MODE(idx), \
.top_value = 1000, \
.load_mode = NRF_PWM_LOAD_INDIVIDUAL, \
.step_mode = NRF_PWM_STEP_TRIGGERED, \
}, \
.seq.values.p_raw = pwm_nrfx_##idx##_data.current, \
.seq.length = NRF_PWM_CHANNEL_COUNT \
}; I agree with your findings, it does not seem like it is possible to set the PWM prescaler to 16 MHz yourself through the devicetree.
I took a closer look, to confirm this, and to figure out if it was possible to set it in any other way (API, Kconfigs etc..).
I can see that nrf_pwm.h-->nrf_pwm_configure() will set the PRESCALER register, and this function is called from two places:
So there are no ways to change the PRESCALER value directly, but you you can set the period using the function pwm_pin_set_cycles(), and the PRESCALER will be set automatically to an appropriate value.
Of course, you could run nrf_pwm_configure() directly from your application, but that is not the intended "Zephyr way" of doing it.
Another option is to use the nrfx drivers directly, that requires some more work than using the Zephyr drivers, but you get more control. Check out the sample zephyr/samples/boards/nrf/nrfx to get an understanding of how to use the nrfx api directly.
Best regards,
Simon
I agree with your findings, it does not seem like it is possible to set the PWM prescaler to 16 MHz yourself through the devicetree.
I took a closer look, to confirm this, and to figure out if it was possible to set it in any other way (API, Kconfigs etc..).
I can see that nrf_pwm.h-->nrf_pwm_configure() will set the PRESCALER register, and this function is called from two places:
So there are no ways to change the PRESCALER value directly, but you you can set the period using the function pwm_pin_set_cycles(), and the PRESCALER will be set automatically to an appropriate value.
Of course, you could run nrf_pwm_configure() directly from your application, but that is not the intended "Zephyr way" of doing it.
Another option is to use the nrfx drivers directly, that requires some more work than using the Zephyr drivers, but you get more control. Check out the sample zephyr/samples/boards/nrf/nrfx to get an understanding of how to use the nrfx api directly.
Best regards,
Simon