Skip to content

Commit 0261d7d

Browse files
nordic-krchdanieldegrasse
authored andcommitted
drivers: pwm: nrfx: Add option to glitch free 100% duty cycle
IDLEOUT presence in PWM means that there are 3 sources from which PWM pin can be driven: - GPIO setting when PWM peripheral is disabled. - IDLEOUT setting when PWM is enabled. - PWM Sequence when it is in use. IDLEOUT setting cannot be changed after enabling PWM so it is configured to the initial state of the pin. It means that if duty cycle is 100%, GPIO output is set to 1 but initial pin state was 0 (IDLEOUT setting) there will be a glitch between disabling a PWM sequence and disabling a PWM peripheral. By default, PWM driver tries to disable PWM peripheral if all channels are 0% or 100% duty cycle to safe power. When IDLEOUT feature is present there will be a short glitch on channels with 100% duty cycle. In order to avoid that CONFIG_PWM_NRFX_NO_GLITCH_DUTY_100 option is added (enabled by default). When option is enabled 100% duty cycle is achieved by PWM sequence and not by driving a GPIO pin. It will consume more power in cases where all channels are 0% or 100% with at least one channel set to 100% duty cycle. Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 28cfb3f commit 0261d7d

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

drivers/pwm/Kconfig.nrfx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ config PWM_NRFX
2020
select PINCTRL
2121
help
2222
Enable support for nrfx Hardware PWM driver for nRF52 MCU series.
23+
24+
config PWM_NRFX_NO_GLITCH_DUTY_100
25+
bool "No glitches when using 100% duty"
26+
depends on $(dt_compat_any_has_prop,$(DT_COMPAT_NORDIC_NRF_PWM),idleout-supported,True)
27+
default y
28+
help
29+
Due to how IDLEOUT feature in PWM works it is possible to see a glitch on a channel
30+
with 100% duty cycle when all other channels switches to 0% or 100%. Enabling this
31+
option ensures that there are no glitches but it also means that 100% duty cycle
32+
on any channels requires PWM peripheral to be active.

drivers/pwm/pwm_nrfx.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ static int pwm_nrfx_set_cycles(const struct device *dev, uint32_t channel,
240240
/* Constantly active (duty 100%). */
241241
/* This value is always greater than or equal to COUNTERTOP. */
242242
compare_value = PWM_NRFX_CH_COMPARE_MASK;
243+
needs_pwm = pwm_is_fast(config) ||
244+
(IS_ENABLED(NRF_PWM_HAS_IDLEOUT) &&
245+
IS_ENABLED(CONFIG_PWM_NRFX_NO_GLITCH_DUTY_100));
243246
} else {
244247
/* PWM generation needed. Check if the requested period matches
245248
* the one that is currently set, or the PWM peripheral can be
@@ -279,20 +282,8 @@ static int pwm_nrfx_set_cycles(const struct device *dev, uint32_t channel,
279282
if (inverted) {
280283
out_level ^= 1;
281284
}
282-
/* Output of fast PWM instance is directly connected to GPIO pads,
283-
* thus it cannot controlled by GPIO. Use regular 0%/100% duty cycle
284-
* playback instead.
285-
*/
286-
#ifdef PWM_NRFX_FAST_PRESENT
287-
if (pwm_is_fast(config)) {
288-
nrfx_pwm_simple_playback(&config->pwm, &config->seq, 1,
289-
NRFX_PWM_FLAG_NO_EVT_FINISHED);
290-
} else {
291-
#else
292-
{
293-
#endif
294-
nrf_gpio_pin_write(psel, out_level);
295-
}
285+
286+
nrf_gpio_pin_write(psel, out_level);
296287
}
297288

298289
data->pwm_needed &= ~BIT(channel);

0 commit comments

Comments
 (0)