Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Reported current usage is very high #665

Closed
jononi opened this issue Jun 11, 2022 · 4 comments
Closed

[Bug] Reported current usage is very high #665

jononi opened this issue Jun 11, 2022 · 4 comments
Assignees
Labels
bug Something isn't working hub: technichub Issues related to the LEGO Technic hub (Hub No. 2) software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: battery Issues involving batteries

Comments

@jononi
Copy link

jononi commented Jun 11, 2022

Describe the bug

On Technic Hub running pybricks 3.2.0b1(Build #1765):

The battery current as reported by hub.battery.current() is too high and it looks like it's a reporting error because at that value the unit should be getting warm. I'm not noticing a faster discharge of the batteries. When connecting motors they run a bit slower like when batteries are not fully charged but nothing like when on almost empty batteries.

To reproduce
Connect Technic Hub with nothing attached. Run:

from pybricks.hubs import TechnicHub
hub = TechnicHub()
print('V(bat): {} mV'.format(hub.battery.voltage()))
print('I(bat): {} mA'.format(hub.battery.current()))

Output:

V(bat): 8667 mV
I(bat): 1381 mA

Expected behavior
current load in the ~80mA (when comparing to a unit with Lego firmware installed)

@jononi jononi added the triage Issues that have not been triaged yet label Jun 11, 2022
@dlech dlech added bug Something isn't working hub: technichub Issues related to the LEGO Technic hub (Hub No. 2) software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: battery Issues involving batteries and removed triage Issues that have not been triaged yet labels Jun 11, 2022
@dlech
Copy link
Member

dlech commented Jun 11, 2022

Thanks for reporting. I am able to reproduce the issue. The battery voltage is reading too high as well (this could be a side-effect of the incorrect current reading since the current is used in the voltage calculatoin).

@dlech
Copy link
Member

dlech commented Jun 11, 2022

Reviewing the git history shows there was a major update in the STM32L4 HAL that was included when we updated to a newer version of MicroPython. No Pybricks code changed. So HAL library changes are likely the cause.

I hacked in a function to read the ADC registers to see what is different.

adc, common = hub.battery.reg()
print('ADC')
print(*("{:02x}: {:02x}".format(i, x) for i, x in enumerate(adc)), sep='\n')
print('ADC_COMMON')
print(*("{:02x}: {:02x}".format(i, x) for i, x in enumerate(common)), sep='\n')

Which produces the following diff:

--- <v3.1.0>
+++ <v3.2.0b1>
@@ -63,7 +63,7 @@
 3d: 00
 3e: 00
 3f: 00
-40: b1
+40: b3
 41: 03
 42: 00
 43: 00
@@ -98,7 +98,7 @@
 60: 00
 61: 00
 62: 00
-63: 00
+63: c4
 64: 00
 65: 00
 66: 00
@@ -175,7 +175,7 @@
 ad: 00
 ae: 00
 af: 00
-b0: 00
+b0: 0c
 b1: 00
 b2: 00
 b3: 00
@@ -196,7 +196,7 @@
 09: 00
 0a: 83
 0b: 00
-0c: b1
+0c: b3
 0d: 03
 0e: 00
 0f: 00
  • ADC 0x40 is data register (ADC_DR) so expected to be different most of the time as it is always changing as data is read.
  • ADC 0x63 is part of ADC_OFR1 - OFFSET1_EN << 7 + OFFSET1_CH << 2 - before not enabled - after enabled, offset of 1 - channel 1 is not used on the technic hub
  • ADC 0xb0 is part of ADC_DIFSEL - lsb of DIFSEL - before no channels configured in diff mode - after ch 3 configured in diff mode - channel 3 is the battery current 🤨
  • ADC_COMMON 0x0c is part of ADC_CDR - lsb of RDATA_MST - this is a data register for dual mode

dlech added a commit to pybricks/pybricks-micropython that referenced this issue Jun 11, 2022
The STM32L4Cube HAL was updated via upstream MicroPython and contains
significant changes to the ADC code. Apparently, this code is less
forgiving of zero-values for certain parameters. This fixes the issue
by ensuring that we initialize all parameters to a valid value.

Fixes: pybricks/support#665
dlech added a commit to pybricks/pybricks-micropython that referenced this issue Jun 11, 2022
The STM32L4Cube HAL was updated via upstream MicroPython and contains
significant changes to the ADC code. Apparently, this code is less
forgiving of zero-values for certain parameters. This fixes the issue
by ensuring that we initialize all parameters to a valid value.

Fixes: pybricks/support#665
@dlech
Copy link
Member

dlech commented Jun 11, 2022

The fix turned out to be trivial. After the fix:

('technichub', '3.2.0b1', 'v3.2.0b1-10-g4fc6f9d2-dirty on 2022-06-11')
V(bat): 7546 mV
I(bat): 135 mA

@jononi
Copy link
Author

jononi commented Jun 13, 2022

I confirm that the issue was fixed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hub: technichub Issues related to the LEGO Technic hub (Hub No. 2) software: pybricks-micropython Issues with Pybricks MicroPython firmware (or EV3 runtime) topic: battery Issues involving batteries
Projects
None yet
Development

No branches or pull requests

2 participants