Skip to content

Commit 9ca87d4

Browse files
committed
Created update 1.2.0
Added prompt to retry the compatibility test if Vbus voltage is not present, instead of outright failing (2022-11-06). Added CC deadband threshold tweaks to fix an issue where setting charge current overwrites the user's defaults (2022-11-06). Fixed issue where double-tapping Select key in "Advanced... > Chg Reg Deadband" menu does not go up a level (2022-11-06).
1 parent c6d3bcf commit 9ca87d4

7 files changed

+137
-80
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Lithium-ion batteries can be dangerous if mishandled or abused! The author accep
88
Follow the prompts in the program when they appear, and try to do them promptly (but don't rush yourself). Some steps require user intervention to connect/disconnect the battery and/or adapter, as the tester has no innate switching capabilities; in other words, you are manually performing the work of a relay/switch. :)
99

1010
## How does DingoCharge work?
11-
DingoCharge leverages the [USB PD PPS](https://www.belkin.com/us/support-article?articleNum=318878) protocol to control the amount of current that flows into a rechargeable battery (as of version 1.1.2, only lithium-ion chemistries are supported). By adjusting the difference between the battery's present voltage and the voltage being supplied from the adapter, the amount of current flowing into the battery can be controlled via closed-loop regulation; this provides software controlled constant-current and constant-voltage operation. The program also provides an easy-to-use interface to set up the required charging parameters (voltage, current, charge termination/cutoff, etc.), and also ensures that the requested settings are compatible with the adapter in use, as not all PD PPS adapters are equal.
11+
DingoCharge leverages the [USB PD PPS](https://www.belkin.com/us/support-article?articleNum=318878) protocol to control the amount of current that flows into a rechargeable battery (as of version 1.2.0, only lithium-ion chemistries are supported). By adjusting the difference between the battery's present voltage and the voltage being supplied from the adapter, the amount of current flowing into the battery can be controlled via closed-loop regulation; this provides software controlled constant-current and constant-voltage operation. The program also provides an easy-to-use interface to set up the required charging parameters (voltage, current, charge termination/cutoff, etc.), and also ensures that the requested settings are compatible with the adapter in use, as not all PD PPS adapters are equal.
1212

1313
The program is built around the [Lua API](https://yk-lab.org:666/index.php/2020/01/09/lua-programming-overview/) feature that is present on the Shizuku platform. The API provides the necessary functions to interact with a USB PD PPS adapter, as well as providing basic routines for the user interface.
1414

@@ -19,7 +19,7 @@ DingoCharge is meant for people with existing electronics/battery knowledge (hob
1919
DingoCharge takes advantage of existing features in hardware that you already purchased (the USB tester, USB-C to USB-C cable(s), and your USB-C PD adapter(s)). With a little bit of extra hardware (USB-C or USB-A plug to the various connections you may need to hook up the battery), you have a highly flexible battery charger for your projects.
2020

2121
## Extra hardware required
22-
The only extra hardware required is a USB power cable that connects the VBUS and ground pins to your battery, and a microUSB cable to an external 5 volt USB power source (as of version 1.1.2), and the battery you want to charge (as of version 1.1.2, lithium-ion/lithium iron phosphate batteries with a 1S to 5S (2S to 4S recommended) configuration are supported, with experimental support for 2S-8S lithium-titanate chemistries added but untested). Examples include USB-A to 5.5x2.1mm barrel jacks, XT30/XT60, Deans, SAE, Anderson Powerpole connectors, or alligator clips. If your PD adapter supports PPS with more than 3 amps of current, you will need a suitably rated 5 amp/100 watt USB-C to USB-C cable to connect the tester to the adapter.
22+
The only extra hardware required is a USB power cable that connects the VBUS and ground pins to your battery, and a microUSB cable to an external 5 volt USB power source (as of version 1.2.0), and the battery you want to charge (as of version 1.2.0, lithium-ion/lithium iron phosphate batteries with a 1S to 5S (2S to 4S recommended) configuration are supported, with experimental support for 2S-8S lithium-titanate chemistries added but untested). Examples include USB-A to 5.5x2.1mm barrel jacks, XT30/XT60, Deans, SAE, Anderson Powerpole connectors, or alligator clips. If your PD adapter supports PPS with more than 3 amps of current, you will need a suitably rated 5 amp/100 watt USB-C to USB-C cable to connect the tester to the adapter.
2323

2424
DingoCharge will only work with the USB PD adapter connected to the tester's input, and the battery on the tester's output. It will not work if the connections are reversed.
2525

main/lua/user/DC4S/LibMenu-DC4S.lc

480 Bytes
Binary file not shown.

main/lua/user/DC4S/UserDefaults-DC4S.lua

+38-23
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ Version history:
99
Added an option to display system temperature in Fahrenheit (2022-10-12).
1010
Added 2.5V/cell and 8S cell configurations (2022-10-13).
1111
1.1.1: Fixed issue where some chargers' current-limiting conflicted with CV control loop (2022-10-15).
12-
1.1.2: Fixed issue where setting 8S configuration would result in a Config Error message (2022-10-20).]]
12+
1.1.2: Fixed issue where setting 8S configuration would result in a Config Error message (2022-10-20).
13+
1.2.0: Added prompt to retry the compatibility test if Vbus voltage is not present, instead of outright failing (2022-11-06).
14+
Added CC deadband threshold tweaks to fix an issue where setting charge current overwrites the user's defaults (2022-11-06).
15+
Fixed issue where double-tapping Select key in "Advanced... > Chg Reg Deadband" menu does not go up a level (2022-11-06).]]
1316

1417
-- I guess this is easier than trying to build a configuration file parser...
1518
-- Note: as versions are updated, this file should be replaced with one from
@@ -66,67 +69,79 @@ function setDeadbandDefaults()
6669
-- For example, if cvDeadband is 50 mV, the algorithm will switch when the
6770
-- voltage is [voltsPerCell * numCells] - 50 mV. This causes a temporary
6871
-- overshoot in current but is limited in amount and duration (often less
69-
-- than 10% for a couple minutes).
72+
-- than 10% for a couple minutes), but if it is too high then charging will
73+
-- fall back to constant-current mode; see setCcFallbackDefaults() below.
7074
-- This can be helpful when the adapter is unable to fully reach its
7175
-- maximum reported voltage (in testing, 3 of 3 "21V" capable adapters only
7276
-- produced 19.95V~20.5V, preventing use with 5S Li-ion packs unless
7377
-- 4V/cell is selected).
7478
pcDeadband = 0.01 -- Amps, precharge mode
75-
ccDeadband = 0.025 -- Amps, constant-current mode
79+
ccDeadbandNormal = 0.025 -- Amps, constant-current mode
80+
ccDeadbandLow = 0.01 -- Amps, constant-current mode for lower currents
81+
ccDeadbandThreshold = 0.5 -- Amps, use low deadband if current <= threshold
7682
cvDeadband = 0.01 -- Volts, constant-voltage mode
7783
tcDeadband = 0.01 -- Amps, end-of-charge mode
84+
85+
-- CAUTION: Do not change the rest of the code in this section.
86+
if (chargeCurrent <= ccDeadbandThreshold) then
87+
ccDeadband = ccDeadbandLow
88+
else
89+
ccDeadband = ccDeadbandNormal
90+
end
7891
end
7992

8093
function setAggressiveGcDefaults()
8194
-- If enabled, Lua's collectgarbage() will be forced if free RAM is below
82-
-- this threshold. This check occurs during every charge regulation loop
83-
-- iteration. (Yes, this is a pretty blunt approach, but it works and it
84-
-- keeps the system stable...)
95+
-- this threshold. This check occurs during every charge regulation loop
96+
-- iteration. (Yes, this is a pretty blunt approach, but it works and it
97+
-- keeps the system stable...)
8598
-- Note: Although the option is provided to disable this behaviour, doing
86-
-- so will severely impact stability (the system will likely hang, or crash
87-
-- with an out-of-memory dialog within minutes or hours when running the main
88-
-- charging/UI loop).
99+
-- so will severely impact stability (the system will likely hang, or crash
100+
-- with an out-of-memory dialog within minutes or hours when running the
101+
-- main charging/UI loop).
89102
aggressiveGcThreshold = 16384 -- bytes
90103
isAggressiveGcEnabled = true -- should be true for proper program operation
91104
end
92105

93106
function setSystemSoundDefaults()
94107
-- The Shizuku sound API is used to sound a beep on the splash screen, if a
95-
-- PD request fails, and when charging is finished (transition from CV to
96-
-- TC charge stage).
108+
-- PD request fails, and when charging is finished (transition from CV to
109+
-- TC charge stage).
97110
isSystemSoundsEnabled = true
98111
end
99112

100113
function setCableResistanceDefaults()
101114
-- The algorithm can compensate for additional cable resistance between the
102-
-- tester and the battery, which will raise the CC-to-CV threshold voltage
103-
-- and CV voltage by (current * cableResistance). The algorithm inherently
104-
-- compensates for resistance and offset from the adapter to the tester
105-
-- without the need to define it manually.
115+
-- tester and the battery, which will raise the CC-to-CV threshold voltage
116+
-- and CV voltage by (current * cableResistance). The algorithm inherently
117+
-- compensates for resistance and offset from the adapter to the tester
118+
-- without the need to define it manually.
106119
-- Note: it is not recommended to overcompensate for downstream resistance
107-
-- as it poses a risk of damaging the battery through overvoltage/overcharge.
120+
-- as it poses a risk of damaging the battery through overvoltage. A safe
121+
-- value is about half of the calculated downstream resistance:
122+
-- cableResistance = (Vbus_meter - Vbat) / Icharge
108123
cableResistance = 0
109124
end
110125

111126
function setCcFallbackDefaults()
112127
-- The algorithm can protect against excessive current draw when the charge
113-
-- stage moves from constant-current (CC) to constant-voltage (CV) mode. If
114-
-- the current flow exceeds (ccFallbackRate * chargeCurrent) then the stage
115-
-- is sent back to CC mode from CV mode.
128+
-- stage moves from constant-current (CC) to constant-voltage (CV) mode. If
129+
-- the current flow exceeds (ccFallbackRate * chargeCurrent) then the stage
130+
-- is sent back to CC mode from CV mode.
116131
ccFallbackRate = 1.1
117132
end
118133

119134
function setTemperatureDisplayDefaults()
120135
-- During charging, DingoCharge displays the system temperature in the
121-
-- MiscInfo section. The Lua API provides temperature in Celsius, but this
122-
-- can be converted to Fahrenheit for locales that use it (e.g. USA).
136+
-- MiscInfo section. The Lua API provides temperature in Celsius, but this
137+
-- can be converted to Fahrenheit for locales that use it (e.g. USA).
123138
isTempDisplayF = false
124139
end
125140

126141
function resetAllDefaults()
127142
-- This function is called upon program initialization. All of the referenced
128-
-- functions above must be called here to ensure all settings are applied at
129-
-- startup.
143+
-- functions above must be called here to ensure all settings are applied
144+
-- during startup.
130145
setDefaults()
131146
setPChgDefaults()
132147
setRefreshDefaults()

main/lua/user/DingoCharge-Shizuku.lc

140 Bytes
Binary file not shown.

source/lua/user/DC4S/LibMenu-DC4S.lua

+39-19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ Version history:
99
Added an option to display system temperature in Fahrenheit (2022-10-12).
1010
Added 2.5V/cell and 8S cell configurations (2022-10-13).
1111
1.1.1: Fixed issue where some chargers' current-limiting conflicted with CV control loop (2022-10-15).
12-
1.1.2: Fixed issue where setting 8S configuration would result in a Config Error message (2022-10-20).]]
12+
1.1.2: Fixed issue where setting 8S configuration would result in a Config Error message (2022-10-20).
13+
1.2.0: Added prompt to retry the compatibility test if Vbus voltage is not present, instead of outright failing (2022-11-06).
14+
Added CC deadband threshold tweaks to fix an issue where setting charge current overwrites the user's defaults (2022-11-06).
15+
Fixed issue where double-tapping Select key in "Advanced... > Chg Reg Deadband" menu does not go up a level (2022-11-06).]]
1316

1417
function checkConfigs()
1518
local returnStatus = false
@@ -116,10 +119,10 @@ function cfgCurr()
116119
tmpCurr = tmpCurr + (0.001 * screen.popMenu({string.format("%0.3fA",tmpCurr),string.format("%0.3fA",tmpCurr + 0.001),string.format("%0.3fA",tmpCurr + 0.002),string.format("%0.3fA",tmpCurr + 0.003),string.format("%0.3fA",tmpCurr + 0.004),string.format("%0.3fA",tmpCurr + 0.005),string.format("%0.3fA",tmpCurr + 0.006),string.format("%0.3fA",tmpCurr + 0.007),string.format("%0.3fA",tmpCurr + 0.008),string.format("%0.3fA",tmpCurr + 0.009)}))
117120
end
118121
chargeCurrent = tmpCurr
119-
if (chargeCurrent <= 0.5) then -- smaller deadband for low charge currents
120-
ccDeadband = 0.01
122+
if (chargeCurrent <= ccDeadbandThreshold) then -- smaller deadband for lower charge currents
123+
ccDeadband = ccDeadbandLow
121124
else
122-
ccDeadband = 0.025
125+
ccDeadband = ccDeadbandNormal
123126
end
124127
screen.popHint(string.format("%0.3fA", chargeCurrent), 1000)
125128
end
@@ -233,24 +236,32 @@ function cfgDeadbandEntry(varSel)
233236
if (varSel == 1) then -- precharge
234237
varValue = pcDeadband
235238
varUnit = "A"
236-
varType = "Precharge"
237-
elseif (varSel == 2) then -- constant current
239+
varType = "Precharge Dband"
240+
elseif (varSel == 2) then -- constant current normal
241+
varValue = ccDeadbandNormal
242+
varUnit = "A"
243+
varType = "CC Norm Dband"
244+
elseif (varSel == 3) then -- constant current low
238245
varValue = ccDeadband
239246
varUnit = "A"
240-
varType = "CC Mode"
241-
elseif (varSel == 3) then -- constant voltage
247+
varType = "CC Low Dband"
248+
elseif (varSel == 4) then -- constant current normal/low decision threshold
249+
varValue = ccDeadbandThreshold
250+
varUnit = "A"
251+
varType = "CC Low Thresh"
252+
elseif (varSel == 5) then -- constant voltage
242253
varValue = cvDeadband
243254
varUnit = "V"
244-
varType = "CV Mode"
245-
elseif (varSel == 4) then -- terminate charge/current
255+
varType = "CV Dband"
256+
elseif (varSel == 6) then -- terminate charge/current
246257
varValue = tcDeadband
247258
varUnit = "A"
248-
varType = "Chg Term"
259+
varType = "Chg Term Dband"
249260
else
250261
return
251262
end
252263

253-
local dbndSel = screen.popMenu({string.format("Keep Current (%.3f%s)",varValue,varUnit),string.format("Set %s Dband...",varType)})
264+
local dbndSel = screen.popMenu({string.format("Keep Current (%.3f%s)",varValue,varUnit),string.format("Set %s...",varType)})
254265
if dbndSel == 1 then
255266
-- Integer, always <1
256267
varValue = 0
@@ -266,29 +277,38 @@ function cfgDeadbandEntry(varSel)
266277
if (varSel == 1) then
267278
pcDeadband = varValue
268279
elseif (varSel == 2) then
269-
ccDeadband = varValue
280+
ccDeadbandNormal = varValue
270281
elseif (varSel == 3) then
271-
cvDeadband = varValue
282+
ccDeadbandLow = varValue
272283
elseif (varSel == 4) then
284+
ccDeadbandThreshold = varValue
285+
elseif (varSel == 5) then
286+
cvDeadband = varValue
287+
elseif (varSel == 6) then
273288
tcDeadband = varValue
274289
else
275290
return
276291
end
292+
if (chargeCurrent <= ccDeadbandThreshold) then
293+
ccDeadband = ccDeadbandLow
294+
else
295+
ccDeadband = ccDeadbandNormal
296+
end
277297
end
278298

279299
function cfgDeadband()
280-
local hystCfgSel = 0
300+
local dbandCfgSel = 0
281301
while true do
282302
screen.clear()
283-
hystCfgSel = screen.popMenu({"< Advanced... ", string.format("Precharge Dband: %0.3fA",pcDeadband), string.format("CC Mode Dband: %0.3fA",ccDeadband), string.format("CV Mode Dband: %0.3fV",cvDeadband), string.format("Chg Term Dband: %0.3fA",tcDeadband), "Restore Defaults"})
303+
dbandCfgSel = screen.popMenu({"< Advanced... ", string.format("Precharge Dband: %0.3fA",pcDeadband), string.format("CC Norm Dband: %0.3fA",ccDeadbandNormal), string.format("CC Low Dband: %0.3fA",ccDeadbandLow), string.format("CC Low Thresh: %.3fA",ccDeadbandThreshold), string.format("CV Dband: %0.3fV",cvDeadband), string.format("Chg Term Dband: %0.3fA",tcDeadband), "Restore Defaults"})
284304
screen.clear()
285-
if (hystCfgSel == 5) then
305+
if (dbandCfgSel == 7) then
286306
if (screen.popYesOrNo("Restore defaults?",color.yellow)) then
287307
setDeadbandDefaults()
288308
screen.popHint("Defaults Restored", 1000)
289309
end
290-
elseif (hystCfgSel > 0) then
291-
cfgDeadbandEntry(hystCfgSel)
310+
elseif (dbandCfgSel > 0 and dbandCfgSel < 255) then
311+
cfgDeadbandEntry(dbandCfgSel)
292312
else
293313
break
294314
end

0 commit comments

Comments
 (0)