hello Nordic
i work with nrf52840 with zephyr 2.6.9 (ncs 1.7.1)
in ncs in zephyr/drivers/pwm/pwm_nrfx.c, in function
pwm_period_check_and_set
there is the following code
/* Try to find a prescaler that will allow setting the requested period
* after prescaling as the countertop value for the PWM peripheral.
*/
prescaler = 0;
countertop = period_cycles;
do {
if (countertop <= PWM_COUNTERTOP_COUNTERTOP_Msk) {
data->period_cycles = period_cycles;
data->prescaler = prescaler;
data->countertop = (uint16_t)countertop;
nrf_pwm_configure(config->pwm.p_registers,
data->prescaler,
config->initial_config.count_mode,
data->countertop);
return 0;
}
LOG_INF("countertop = %u, msk - %u, prescaler - %u", countertop, PWM_COUNTERTOP_COUNTERTOP_Msk, prescaler);
countertop >>= 1;
++prescaler;
} while (prescaler <= PWM_PRESCALER_PRESCALER_Msk);
// LOG_INF("countertop = %u, msk - %u", countertop, PWM_COUNTERTOP_COUNTERTOP_Msk)
LOG_ERR("Prescaler for period_cycles %u not found.", period_cycles);
return -EINVAL;
if i want to set the period to 1 sec with 16Mhz fixed cycle, according to:
static int pwm_nrfx_get_cycles_per_sec(const struct device *dev, uint32_t pwm,
uint64_t *cycles)
{
/* TODO: Since this function might be removed, we will always return
* 16MHz from this function and handle the conversion with prescaler,
* etc, in the pin set function. See issue #6958.
*/
*cycles = 16ul * 1000ul * 1000ul;
return 0;
}
then i should be able to use
#define PWM_PRESCALER_PRESCALER_DIV_1 (0UL) /*!< Divide by 1 (16 MHz) */
from modules/hal/nordic/nrfx/mdk/nrf52840_bitfields.h
but the if statement in the function compares the countertop (which is set to period cycle (aka 16M) in line 65) to 32767, why ???? ????
i am surly missing something
hope to read from you soon
best regards
Ziv