From 9c6d9a7fe0e93c789d5b796acc91d7d97fd338a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Sun, 13 Dec 2015 00:23:40 +0100 Subject: [PATCH] cc2538: pwm: Fix clock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The peripheral core clock of the general-purpose timers used by the PWM driver is the system clock, not the I/O clock. Signed-off-by: Benoît Thébaudeau --- cpu/cc2538/dev/pwm.c | 4 ++-- cpu/cc2538/dev/pwm.h | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cpu/cc2538/dev/pwm.c b/cpu/cc2538/dev/pwm.c index 7fb6fc61f..837efcb14 100644 --- a/cpu/cc2538/dev/pwm.c +++ b/cpu/cc2538/dev/pwm.c @@ -135,10 +135,10 @@ pwm_enable(uint32_t freq, uint8_t duty, uint8_t timer, uint8_t ab) } /* Get the peripheral clock and equivalent deassert count */ - interval_load = sys_ctrl_get_io_clock() / freq; + interval_load = sys_ctrl_get_sys_clock() / freq; duty_count = ((interval_load * duty) + 1) / 100; - PRINTF("PWM: IO %luHz: %lu %lu\n", sys_ctrl_get_io_clock(), + PRINTF("PWM: sys %luHz: %lu %lu\n", sys_ctrl_get_sys_clock(), interval_load, duty_count); /* Set the start value (period), count down */ diff --git a/cpu/cc2538/dev/pwm.h b/cpu/cc2538/dev/pwm.h index 7420d3d30..f80402f31 100644 --- a/cpu/cc2538/dev/pwm.h +++ b/cpu/cc2538/dev/pwm.h @@ -78,15 +78,15 @@ /** \name PWM recommended values respect to peripheral clock frequency * @{ */ -/* Roughly 244 Hz with a 16 MHz IO clock, no prescaler */ -#define PWM_SYS_IO_16MHZ_NO_PRES_MIN 0xFFFF -#define PWM_SYS_IO_16MHZ_NO_PRES_MIN_FREQ 244 -/* Roughly 1 Hz with a 16 MHz IO clock, to keep frequency parameter in Hz */ -#define PWM_SYS_IO_16MHZ_PRES_MIN 0x00F42400 -#define PWM_SYS_IO_16MHZ_PRES_MIN_FREQ 1 +/* Roughly 244 Hz with a 16-MHz system clock, no prescaler */ +#define PWM_SYS_16MHZ_NO_PRES_MIN 0xFFFF +#define PWM_SYS_16MHZ_NO_PRES_MIN_FREQ 244 +/* Roughly 1 Hz with a 16-MHz system clock, to keep frequency parameter in Hz */ +#define PWM_SYS_16MHZ_PRES_MIN 0x00F42400 +#define PWM_SYS_16MHZ_PRES_MIN_FREQ 1 /* Yields 160 KHz at 16 MHz and allows down to 1% (integer) duty cycles */ -#define PWM_SYS_IO_16MHZ_NO_PRES_MAX 100 -#define PWM_SYS_IO_16MHZ_NO_PRES_MAX_FREQ 160000 +#define PWM_SYS_16MHZ_NO_PRES_MAX 100 +#define PWM_SYS_16MHZ_NO_PRES_MAX_FREQ 160000 /** @} */ /*---------------------------------------------------------------------------*/ /** \name PWM driver definitions and configuration values @@ -107,8 +107,8 @@ #define PWM_GPTIMER_CFG_SPLIT_MODE 0x04 #define PWM_DUTY_MAX 100 #define PWM_DUTY_MIN 0 -#define PWM_FREQ_MIN PWM_SYS_IO_16MHZ_PRES_MIN_FREQ -#define PWM_FREQ_MAX PWM_SYS_IO_16MHZ_NO_PRES_MAX_FREQ +#define PWM_FREQ_MIN PWM_SYS_16MHZ_PRES_MIN_FREQ +#define PWM_FREQ_MAX PWM_SYS_16MHZ_NO_PRES_MAX_FREQ /** @} */ /*---------------------------------------------------------------------------*/ /** \name PWM functions