From f2df09d60259eb6abe00899925a64f5131dc2b10 Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Fri, 15 Mar 2013 09:53:07 -0700 Subject: [PATCH] spring: set boost PWM frequency to 32Khz Push the PWM frequency outside the audio band to avoid audible whining. Also fix the off-by-one in the PWM frequency computation. Signed-off-by: Vincent Palatin BRANCH=spring BUG=chrome-os-partner:17583 TEST=manual : probe the PWM output with a scope. Change-Id: Ie1c8c5aed72bef46c8bac16c1bf3007e8e9573bb Reviewed-on: https://gerrit.chromium.org/gerrit/45584 Reviewed-by: Vic Yang Commit-Queue: Vincent Palatin Tested-by: Vincent Palatin --- board/spring/usb_charging.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/board/spring/usb_charging.c b/board/spring/usb_charging.c index d7ba332047..5c29af3e69 100644 --- a/board/spring/usb_charging.c +++ b/board/spring/usb_charging.c @@ -21,7 +21,7 @@ #include "tsu6721.h" #include "util.h" -#define PWM_FREQUENCY 10000 /* Hz */ +#define PWM_FREQUENCY 32000 /* Hz */ /* Console output macros */ #define CPUTS(outstr) cputs(CC_USBCHARGE, outstr) @@ -116,14 +116,14 @@ static void board_ilim_use_pwm(void) STM32_TIM_CR1(3) = 0x0000; /* - * CPU_CLOCK / PSC determines how fast the counter operates. + * CPU_CLOCK / (PSC + 1) determines how fast the counter operates. * ARR determines the wave period, CCRn determines duty cycle. - * Thus, frequency = CPU_CLOCK / PSC / ARR. + * Thus, frequency = CPU_CLOCK / (PSC + 1) / ARR. * * Assuming 16MHz clock and ARR=100, PSC needed to achieve PWM_FREQUENCY - * is: PSC = CPU_CLOCK / PWM_FREQUENCY / ARR + * is: PSC = CPU_CLOCK / PWM_FREQUENCY / ARR - 1 */ - STM32_TIM_PSC(3) = CPU_CLOCK / PWM_FREQUENCY / 100; /* pre-scaler */ + STM32_TIM_PSC(3) = CPU_CLOCK / PWM_FREQUENCY / 100 - 1; /* pre-scaler */ STM32_TIM_ARR(3) = 100; /* auto-reload value */ STM32_TIM_CCR1(3) = 100; /* duty cycle */