diff options
author | Philip Chen <philipchen@google.com> | 2018-05-23 12:56:03 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2018-05-30 18:15:57 +0000 |
commit | 642affe9dbbf8f9c641e4aaf0a5d718640b17d30 (patch) | |
tree | 842fa8fb4dd534aa42fb428df4bef3cc2c35376b | |
parent | 8bfbd79990bef2b0ee2770d0c143ec530ecc6a66 (diff) | |
download | chrome-ec-642affe9dbbf8f9c641e4aaf0a5d718640b17d30.tar.gz |
charge_state_v2: Add a hysteresis for under-voltage throttling
There is a potential loop:
(1) We throttle AP when we see under-voltage.
(2) VBAT bumps because throttling starts. From our experiment,
AP throttling saves ~1A, and thus VBAT increases by ~80mV.
(3) VBAT hasn't hit BAT_LOW_VOLTAGE_THRESH for BAT_UVP_TIMEOUT_US,
so we stop throttling.
(4) VBAT again drops below BAT_LOW_VOLTAGE_THRESH.
(5) Go back to (1).
So let's introduce a hysteresis to under-voltage throttling.
We stop throttling only when we are confident that even if we stop
throttling, the battery voltage will stay above BAT_LOW_VOLTAGE_THRESH.
BUG=b:73050145, chromium:838754
BRANCH=scarlet
TEST=manually test on scarlet
Change-Id: Ic0c17a7d37d5d6ee38c7b19f9b65d17421e55cbc
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1077687
Reviewed-by: Philip Chen <philipchen@chromium.org>
Commit-Queue: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
-rw-r--r-- | common/charge_state_v2.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 3d1b6be1fd..a02b35189b 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -52,7 +52,7 @@ #define BAT_OCP_TIMEOUT_US (60 * SECOND) /* BAT_OCP_HYSTERESIS_PCT can be optionally overridden in board.h. */ #ifndef BAT_OCP_HYSTERESIS_PCT -#define BAT_OCP_HYSTERESIS_PCT 10 +#define BAT_OCP_HYSTERESIS_PCT 10 #endif /* BAT_OCP_HYSTERESIS_PCT */ #define BAT_OCP_HYSTERESIS \ (BAT_MAX_DISCHG_CURRENT * BAT_OCP_HYSTERESIS_PCT / 100) /* mA */ @@ -64,6 +64,12 @@ static timestamp_t ocp_throttle_start_time; #error "CONFIG_THROTTLE_AP_ON_BAT_VOLTAGE needs CONFIG_HOSTCMD_EVENTS" #endif /* CONFIG_HOSTCMD_EVENTS */ #define BAT_UVP_TIMEOUT_US (60 * SECOND) +/* BAT_UVP_HYSTERESIS_PCT can be optionally overridden in board.h. */ +#ifndef BAT_UVP_HYSTERESIS_PCT +#define BAT_UVP_HYSTERESIS_PCT 3 +#endif /* BAT_UVP_HYSTERESIS_PCT */ +#define BAT_UVP_HYSTERESIS \ + (BAT_LOW_VOLTAGE_THRESH * BAT_UVP_HYSTERESIS_PCT / 100) /* mV */ static timestamp_t uvp_throttle_start_time; #endif /* CONFIG_THROTTLE_AP_ON_BAT_OLTAGE */ @@ -1233,11 +1239,18 @@ static void notify_host_of_low_battery_voltage(void) chipset_in_state(CHIPSET_STATE_ANY_OFF)) return; - if (curr.batt.voltage < BAT_LOW_VOLTAGE_THRESH) { - if (!uvp_throttle_start_time.val) { - throttle_ap(THROTTLE_ON, THROTTLE_SOFT, - THROTTLE_SRC_BAT_VOLTAGE); - } + if (!uvp_throttle_start_time.val && + (curr.batt.voltage < BAT_LOW_VOLTAGE_THRESH)) { + throttle_ap(THROTTLE_ON, THROTTLE_SOFT, + THROTTLE_SRC_BAT_VOLTAGE); + uvp_throttle_start_time = get_time(); + } else if (uvp_throttle_start_time.val && + (curr.batt.voltage < BAT_LOW_VOLTAGE_THRESH + + BAT_UVP_HYSTERESIS)) { + /* + * Reset the timer when we are not sure if VBAT can stay + * above BAT_LOW_VOLTAGE_THRESH after we stop throttling. + */ uvp_throttle_start_time = get_time(); } else if (uvp_throttle_start_time.val && (get_time().val > uvp_throttle_start_time.val + |