[ Environment ]
- Application: Lifesaver- Chip Series: nRF52832- SDK version: SDK14.2.0- Compiler: Keil V5
We have to keep changing the pwm frequency.
Reinit will cause a delay.
Can I change the PWM frequency without reinitializing the PWM?
I have a few follow up questions to help me understand the challenge:
Best regards,Rune Holmgren
Hi, Rune Holmgren
Thanks for your reply.
The PWM hardware is a high-frequency peripheral which can accurately drive a PWM signal even at high frequencies. It's intended for use-cases where the duty cycle is changing, so you have to uninitialize and reinitialize the hardware to change the frequency. It's worth noting that the uninitialization and reinitialization of the peripheral is quite fast, so for many applications this is not a problem. For the purposes of playing sound from a piezo the delay from initializing the reinitializing, the PWM module will not matter. The delay is to short to be perceived by a human ear. For your wireless charging application I do not know the specification, so you will have to check this out yourself.
An alternative to using the PWM module is using a timer and GPIO with PPI channels performing toggle operations at some frequency. The timer can run and after some period it will send an event directly to the GPIO to toggle a pin through a task. In this question you will find an answer by user Steven Wik where he explains how to set this up. The timer is more flexible than the PWM module, so it is often a good alternative. My manipulating NRF_TIMER2->CC runtime you can get different frequencies without the delay you get using the PWM peripheral.