cc2538: pwm: Fix clock

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 <benoit.thebaudeau.dev@gmail.com>
This commit is contained in:
Benoît Thébaudeau 2015-12-13 00:23:40 +01:00
parent 4302e23ddc
commit 9c6d9a7fe0
2 changed files with 12 additions and 12 deletions

View file

@ -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 */ /* 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; 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); interval_load, duty_count);
/* Set the start value (period), count down */ /* Set the start value (period), count down */

View file

@ -78,15 +78,15 @@
/** \name PWM recommended values respect to peripheral clock frequency /** \name PWM recommended values respect to peripheral clock frequency
* @{ * @{
*/ */
/* Roughly 244 Hz with a 16 MHz IO clock, no prescaler */ /* Roughly 244 Hz with a 16-MHz system clock, no prescaler */
#define PWM_SYS_IO_16MHZ_NO_PRES_MIN 0xFFFF #define PWM_SYS_16MHZ_NO_PRES_MIN 0xFFFF
#define PWM_SYS_IO_16MHZ_NO_PRES_MIN_FREQ 244 #define PWM_SYS_16MHZ_NO_PRES_MIN_FREQ 244
/* Roughly 1 Hz with a 16 MHz IO clock, to keep frequency parameter in Hz */ /* Roughly 1 Hz with a 16-MHz system clock, to keep frequency parameter in Hz */
#define PWM_SYS_IO_16MHZ_PRES_MIN 0x00F42400 #define PWM_SYS_16MHZ_PRES_MIN 0x00F42400
#define PWM_SYS_IO_16MHZ_PRES_MIN_FREQ 1 #define PWM_SYS_16MHZ_PRES_MIN_FREQ 1
/* Yields 160 KHz at 16 MHz and allows down to 1% (integer) duty cycles */ /* 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_16MHZ_NO_PRES_MAX 100
#define PWM_SYS_IO_16MHZ_NO_PRES_MAX_FREQ 160000 #define PWM_SYS_16MHZ_NO_PRES_MAX_FREQ 160000
/** @} */ /** @} */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** \name PWM driver definitions and configuration values /** \name PWM driver definitions and configuration values
@ -107,8 +107,8 @@
#define PWM_GPTIMER_CFG_SPLIT_MODE 0x04 #define PWM_GPTIMER_CFG_SPLIT_MODE 0x04
#define PWM_DUTY_MAX 100 #define PWM_DUTY_MAX 100
#define PWM_DUTY_MIN 0 #define PWM_DUTY_MIN 0
#define PWM_FREQ_MIN PWM_SYS_IO_16MHZ_PRES_MIN_FREQ #define PWM_FREQ_MIN PWM_SYS_16MHZ_PRES_MIN_FREQ
#define PWM_FREQ_MAX PWM_SYS_IO_16MHZ_NO_PRES_MAX_FREQ #define PWM_FREQ_MAX PWM_SYS_16MHZ_NO_PRES_MAX_FREQ
/** @} */ /** @} */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/** \name PWM functions /** \name PWM functions