This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

PWM output with stable frequency

PWM output with stable frequency

SDK: 15.3.0
Example: low_power_pwm
Device: EYSHJNZWZ (nRF52832)

I want to output PWM with a stable frequency.
In the above sample, PWM output with stable frequency was confirmed.

However, when the following processing was added, the frequency of the PWM output became unstable.
Perhaps the reason is that interrupt processing runs.

static	const	nrf_drv_timer_t	m_timer = NRF_DRV_TIMER_INSTANCE(2U);

static	void timer_init(void)
{
	ret_code_t	err_code;
	uint32_t	ticks;

	nrf_drv_timer_config_t timer_cfg	= NRF_DRV_TIMER_DEFAULT_CONFIG;

	err_code = nrf_drv_timer_init(&m_timer, &timer_cfg, e_timer_short_handler);
	APP_ERROR_CHECK(err_code);

	ticks = nrf_drv_timer_ms_to_ticks(&m_timer, 1U);
	nrf_drv_timer_extended_compare(&m_timer, NRF_TIMER_CC_CHANNEL0, ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

	nrf_drv_timer_enable(&m_timer);
}

Is there a way to perform stable PWM output regardless of other factors such as interrupts?
Is it possible to output PWM at the hardware level?

Parents Reply Children
  • >> For PWM in pwm_library / pwm_driver, it's the HFCLK that decides how stable the frequency is.
    >> The low_power_pwm library uses the app_timer (which in turn use RTC1 (uses LFCLK)). But the toggling is done in interrupt context, so other interrupts could affect the PWM timing.


    From the above, I recognize that there is no way to achieve stable PWM output with PWM with LFCLK (XTAL) as the clock source.
    Is my perception correct?

Related