Skip to content

Commit c0a15c8

Browse files
ananglcarlescufi
authored andcommitted
drivers: pwm_nrfx: Correct prescaler value for undivided clock
When there is no need to divide the PWM clock (i.e. the requested period cycles fit the 15-bit PWM counter), the prescaler value should be 0, not 1. Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent 636a7af commit c0a15c8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/pwm/pwm_nrfx.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ static u32_t pwm_period_check_and_set(const struct pwm_nrfx_config *config,
5757
/* See if there is a prescaler that will make it work: */
5858
bool matching_prescaler_found = false;
5959

60-
/* Go through all available prescaler values on device.
60+
/* Go through all available prescaler values on device (skip 0
61+
* here as it is used in the 'else' block).
6162
* nRF52832 has 0-7 (Div1 - Div128)
6263
*/
63-
for (u8_t prescaler = 0;
64+
for (u8_t prescaler = 1;
6465
prescaler <= PWM_PRESCALER_PRESCALER_Msk;
6566
prescaler++) {
6667
u32_t new_countertop = period_cycles >> prescaler;
@@ -82,10 +83,10 @@ static u32_t pwm_period_check_and_set(const struct pwm_nrfx_config *config,
8283
return -EINVAL;
8384
}
8485
} else {
85-
/* If period_cycles fit with standard prescaler,
86-
* set it directly
86+
/* If period_cycles fit the PWM counter without dividing
87+
* the PWM clock, use the zero prescaler.
8788
*/
88-
data->prescaler = 1U;
89+
data->prescaler = 0U;
8990
data->countertop = period_cycles;
9091
data->period_cycles = period_cycles;
9192
}

0 commit comments

Comments
 (0)