Skip to content

Proper way to get voltage and log VALUES into dmesg #5584

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

Closed
evrial opened this issue Aug 28, 2023 · 8 comments
Closed

Proper way to get voltage and log VALUES into dmesg #5584

evrial opened this issue Aug 28, 2023 · 8 comments

Comments

@evrial
Copy link

evrial commented Aug 28, 2023

Describe the bug

https://github.com/raspberrypi/linux/blob/rpi-6.1.y/drivers/hwmon/raspberrypi-hwmon.c#L52

When diagnosing the problem with voltage this message doesn't make much sense when reading dmesg. We need to read the voltage value, not meaningless junk!!! Also what about overvoltage?
Also we need to read voltage from lm-sensors, not this:

$ sensors
cpu_thermal-virtual-0
Adapter: Virtual device
temp1:        +54.5°C  (crit = +110.0°C)

rpi_volt-isa-0000
Adapter: ISA adapter
in0:              N/A

Steps to reproduce the behaviour

Attach the USB SSD drive and write large files, undervoltage happens

Device (s)

Raspberry Pi 4 Mod. B

System

DietPi actual
vcgencmd version
Mar 17 2023 10:50:56
Copyright (c) 2012 Broadcom
version 82f3750a65fadae9a38077e3c2e217ad158c8d54 (clean) (release) (start_cd)

Linux DietPi 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux

Logs

[Aug28 17:07] hwmon hwmon1: Undervoltage detected!
[  +8.063930] hwmon hwmon1: Voltage normalised
[ +14.112012] hwmon hwmon1: Undervoltage detected!
[  +4.032014] hwmon hwmon1: Voltage normalised
[Aug28 17:29] hwmon hwmon1: Undervoltage detected!
[  +4.026423] hwmon hwmon1: Voltage normalised
[ +12.095992] hwmon hwmon1: Undervoltage detected!
[  +4.032175] hwmon hwmon1: Voltage normalised
[ +18.143830] hwmon hwmon1: Undervoltage detected!
[  +2.016073] hwmon hwmon1: Voltage normalised
[Aug28 17:30] hwmon hwmon1: Undervoltage detected!
[  +4.017547] hwmon hwmon1: Voltage normalised
[Aug28 17:43] hwmon hwmon1: Undervoltage detected!
[  +2.015996] hwmon hwmon1: Voltage normalised
[Aug28 17:44] hwmon hwmon1: Undervoltage detected!
[  +4.031950] hwmon hwmon1: Voltage normalised
[  +4.031982] hwmon hwmon1: Undervoltage detected!
[  +4.032196] hwmon hwmon1: Voltage normalised
[Aug28 17:45] hwmon hwmon1: Undervoltage detected!
[  +2.015987] hwmon hwmon1: Voltage normalised
[  +6.048030] hwmon hwmon1: Undervoltage detected!
[  +4.032009] hwmon hwmon1: Voltage normalised
[Aug28 18:00] hwmon hwmon1: Undervoltage detected!
[  +4.032007] hwmon hwmon1: Voltage normalised
[Aug28 18:11] hwmon hwmon1: Undervoltage detected!
[  +4.032082] hwmon hwmon1: Voltage normalised
[Aug28 18:12] hwmon hwmon1: Undervoltage detected!
[  +2.015998] hwmon hwmon1: Voltage normalised
[Aug28 18:53] hwmon hwmon1: Undervoltage detected!
[  +2.015991] hwmon hwmon1: Voltage normalised

Additional context

No response

@6by9
Copy link
Contributor

6by9 commented Aug 28, 2023

The log message was originally triggered from the output of an APX803-46SAG microprocessor supervisor chip, not a direct voltage sampling, therefore it was not possible to report an exact voltage. It detects even very brief brown-out conditions though. IIRC that was introduced on the Pi3B.
Subsequent revisions have report the same thing, but on some variants they have done so directly from the PMIC rather than an external circuit.

The 5V rail is browning out below 4.6V as measured at the Pi. The voltage supplied to USB peripherals is therefore going to be dropping below that, which is outside of the USB spec of 5V +/-5% (ie 4.75 - 5.25V), hence warning as USB devices are likely to malfunction.
Feel free to ignore the message, but don't complain if devices do malfunction. If you're connecting high power USB devices, use a powered USB hub.

@evrial
Copy link
Author

evrial commented Aug 28, 2023

From the code we clearly can see it's a matter of changing the message and value is there. But the main point was I'm running Pi4 connected to DC UPS with cheap USB multimeter in the middle to always read current and voltage. And voltage is never falls below 5.35V. So either multimeter is lying or hwmon lying. Undervoltage also happens with USB stick (1W)

@qrp73
Copy link

qrp73 commented Aug 28, 2023

From the code we clearly can see it's a matter of changing the message and value is there.

There is no voltage value in the code, it just reads bit state from controller and if bit is triggered it write message to the log. That's it. So, it works as expected.

I think CPU doesn't have access to +5V power line and cannot measure it.
You can check actual voltage with DMM connected on +5V GPIO pin.

I'm running Pi4 connected to DC UPS with cheap USB multimeter in the middle to always read current and voltage. And voltage is never falls below 5.35V. So either multimeter is lying or hwmon lying.

That's incorrect way to measure voltage, because you're don't take into account voltage drop on your USB cable. In many case the reason for undervoltage is a cheap USB cable which cannot handle high current. I recommend to use USB cable rated for at least 2.4 Amps.

The proper way to measure voltage is to connect your DMM to pins +5V and GND on RPI GPIO header. But be careful, because there is 3V pin near 5V, if you accidentally short +5V and +3V it can lead to RPI damage. It's better to connect DMM with reliable wires when RPI is powered off to avoid accidental shortening during connection.

@6by9
Copy link
Contributor

6by9 commented Aug 28, 2023

From the code we clearly can see it's a matter of changing the message and value is there.

Please enlighten us as to where?
I see the return value from the firmware RPI_FIRMWARE_GET_THROTTLED call, which is documented as to the meaning of the bitmask at https://www.raspberrypi.com/documentation/computers/os.html#get_throttled. No voltage value in there.

A multimeter won't pick up momentary dropouts due to bad regulation in the supply.

@qrp73
Copy link

qrp73 commented Aug 28, 2023

According to my measurements, under-voltage bit is set when voltage drops below 4.4372 V.
The bit is cleared when voltage rise above 4.566 V.

Just don't allow voltage to drop below 4.5 V

@evrial
Copy link
Author

evrial commented Aug 28, 2023

Thanks, this makes complete sense now, i think everything said should be documented because the issue is super common.

@6by9
Copy link
Contributor

6by9 commented Aug 28, 2023

https://www.raspberrypi.com/documentation/computers/compute-module.html#under-voltage-detection
https://www.raspberrypi.com/documentation/computers/os.html#get_throttled already linked.

The spec sheet for APX803 lists the trigger threshold voltage to be +/-1.5% (4.6V +/-0.69V), hysteresis to be 0.01Vth (4.64V), and will trigger on a drop within 20usecs. I would therefore treat 4.6V to be an absolute minimum, and get a decent power supply and supply cables.

@qrp73
Copy link

qrp73 commented Aug 28, 2023

yes, 4.6 V is the minimum, because with 4.5V under-voltage bit may never be cleared, because it is cleared at 4.566 V.

@evrial evrial closed this as completed Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants