You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2021/05/21 11:33:21 UTC
[mynewt-core] branch master updated: drivers/da1469x_charger:
Enable custom value for NTC
This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new f9784db drivers/da1469x_charger: Enable custom value for NTC
f9784db is described below
commit f9784db5232f76f7d07350954580d7e1c27841a2
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Wed Mar 31 14:14:36 2021 +0200
drivers/da1469x_charger: Enable custom value for NTC
Battery temperature values from CHARGER_TEMPSET_PARAM_REG
could be incorrectly decoded in shell command `charger dump decode`
when NTC value was different then datasheet recommended 15k ohm.
Now real pull-up resistor value is taken into account when values
are displayed.
Value of the resistor can be set in syscfg file.
---
.../da1469x_charger/src/da1469x_charger_shell.c | 44 +++++++++++++++++++++-
hw/drivers/chg_ctrl/da1469x_charger/syscfg.yml | 4 ++
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/hw/drivers/chg_ctrl/da1469x_charger/src/da1469x_charger_shell.c b/hw/drivers/chg_ctrl/da1469x_charger/src/da1469x_charger_shell.c
index cc5454c..2d46a8b 100644
--- a/hw/drivers/chg_ctrl/da1469x_charger/src/da1469x_charger_shell.c
+++ b/hw/drivers/chg_ctrl/da1469x_charger/src/da1469x_charger_shell.c
@@ -373,11 +373,53 @@ static const char *const tdie_max[] = {
NULL,
};
+/*
+ * When pull-up resistor for NTC is different then 15k code needs to
+ * recalculate temperature settings. It uses table with voltages measured
+ * at NTC for values from -10 to 53 deg C and converts voltage to
+ * to values that would be measured IF recommended 15K resistor was used.
+ */
+#if MYNEWT_VAL(DA1469X_CHARGER_NTC_VALUE) != 15000
+static const uint16_t Vntc_tab[] = {
+ 2253, 2225, 2197, 2169, 2140, 2111, 2081, 2051, 2021, 1990,
+ 1960, 1929, 1898, 1866, 1835, 1804, 1772, 1741, 1709, 1678,
+ 1646, 1615, 1584, 1553, 1522, 1488, 1461, 1431, 1401, 1371,
+ 1336, 1313, 1284, 1256, 1228, 1200, 1173, 1146, 1120, 1094,
+ 1068, 1043, 1018, 994, 970, 947, 924, 902, 880, 858,
+ 837, 817, 796, 777, 758, 729, 711, 694, 676, 659,
+ 643, 627, 611, 596, 581, 570, 556, 542, 529, 509,
+ 505, 492, 480, 468, 456, 445
+};
+#endif
+
static const char *
tbat_temp(const struct reg_field *field, uint32_t reg_val, char *buf)
{
int val = (int)((reg_val & field->fld_mask) >> field->fld_pos);
-
+#if MYNEWT_VAL(DA1469X_CHARGER_NTC_VALUE) != 15000
+ int lo = 0;
+ int hi = ARRAY_SIZE(Vntc_tab);
+ /* Actual V at NTC */
+ uint32_t Vntc = Vntc_tab[val];
+ uint32_t Rntc = (Vntc * MYNEWT_VAL(DA1469X_CHARGER_NTC_VALUE)) / (3000 - Vntc);
+ /* Value of V at NTC that would be measured if 15K resistor was used. */
+ uint32_t Vntc2 = 3000 * Rntc / (Rntc + 15000);
+
+ /* Binary search for voltage table */
+ while (lo < hi) {
+ val = lo + (hi - lo) / 2;
+ if (Vntc_tab[val] < Vntc2) {
+ hi = val;
+ } else if (Vntc_tab[val] > Vntc2 && lo < val) {
+ lo = val;
+ } else {
+ break;
+ }
+ }
+ if (val < ARRAY_SIZE(Vntc_tab) && (Vntc_tab[val] - Vntc2) > (Vntc2 - Vntc_tab[val + 1])) {
+ ++val;
+ }
+#endif
val -= 10;
sprintf(buf, "%d C", val);
return buf;
diff --git a/hw/drivers/chg_ctrl/da1469x_charger/syscfg.yml b/hw/drivers/chg_ctrl/da1469x_charger/syscfg.yml
index 83ed95d..f54ebd8 100644
--- a/hw/drivers/chg_ctrl/da1469x_charger/syscfg.yml
+++ b/hw/drivers/chg_ctrl/da1469x_charger/syscfg.yml
@@ -74,3 +74,7 @@ syscfg.defs:
description: >
End of charge current settings, 4-35 (%).
value: 7
+ DA1469X_CHARGER_NTC_VALUE:
+ description: >
+ NTC value in ohms.
+ value: 15000