User avatar
RogerW
Posts: 285
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Low voltage detection

Mon Apr 08, 2019 2:25 pm

If the processor detects a low supply voltage a lightning symbol is shown on the screen. I have a battery powered robot using a pi zero W with no screen. Is there a way my program can recieve an interrupt or other indication that the voltage is low.

klricks
Posts: 6546
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Low voltage detection

Tue Apr 09, 2019 2:42 am

RogerW wrote:
Mon Apr 08, 2019 2:25 pm
If the processor detects a low supply voltage a lightning symbol is shown on the screen. I have a battery powered robot using a pi zero W with no screen. Is there a way my program can recieve an interrupt or other indication that the voltage is low.
There probably is but the voltage regulator in the powerbank tends to hold the voltage to 5V for as long as possible then suddenly drop out. In order to be useful you would need to add circuits to monitor the actual battery voltage.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

LdB
Posts: 1209
Joined: Wed Dec 07, 2016 2:29 pm

Re: Low voltage detection

Tue Apr 09, 2019 4:40 am

That is essentially what is done here using a simple ADC

https://raspi.tv/2013/controlled-shutdo ... -cell-lipo

User avatar
RogerW
Posts: 285
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: Low voltage detection

Wed Apr 10, 2019 10:59 am

Thanks for the comments. In fact I am more concerned by transients which may in fact be unlikely. I have four cells which deliver a nominal 6 volts. The motors are driven from this via an H bridge. The pi is fed from an up/down regulator supplied from the same source so SHOULD be ok but I wanted to be sure.
Since there is provision for user programs to monitor CPU temperature you would think it should be possible to trap out of spec voltage.

User avatar
rpdom
Posts: 14994
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Low voltage detection

Wed Apr 10, 2019 11:05 am

The output of "vcgencmd get_throttled" will give information about the power state.

It reports if the Pi is currently slowed down because it is too hot, if the voltage is too low, or if any of these events have occurred at any time since power on.

User avatar
RogerW
Posts: 285
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: Low voltage detection

Wed Apr 10, 2019 1:42 pm

Thanks for that. It would be nice to get that information directly from a program but I cannot find any mention of such. Do you know how vcgencmd gets its data?

User avatar
rpdom
Posts: 14994
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Low voltage detection

Wed Apr 10, 2019 2:08 pm

RogerW wrote:
Wed Apr 10, 2019 1:42 pm
Do you know how vcgencmd gets its data?
It talks to the VideoCore part of the GPU. Secret magic, I'm afraid.

User avatar
RogerW
Posts: 285
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: Low voltage detection

Wed Apr 10, 2019 2:13 pm

Fair enough. Thanks for the information.

DarkElvenAngel
Posts: 147
Joined: Tue Mar 20, 2018 9:53 pm

Re: Low voltage detection

Fri Apr 26, 2019 5:07 am

rpdom wrote:
Wed Apr 10, 2019 2:08 pm
RogerW wrote:
Wed Apr 10, 2019 1:42 pm
Do you know how vcgencmd gets its data?
It talks to the VideoCore part of the GPU. Secret magic, I'm afraid.
You can talk to the VideoCore directly with the mailbox protocol and get values directly. Documents are not so easy to find and are far from complete.

You will have an easier time opening a pipe and running vcgencmd and then use fscanf to convert the output to a variable you can use.

If you're interested in the mailbox here's a link https://github.com/raspberrypi/firmware ... -interface

User avatar
RogerW
Posts: 285
Joined: Sat Dec 20, 2014 12:15 pm
Location: London UK

Re: Low voltage detection

Fri Apr 26, 2019 8:52 am

Thanks for that information. Because I wanted to detect transient low voltage blips I was hoping for an "interupt" type of solution rather than polling. I have now decided it is not worth pursuing unless it definitely proves to be a problem which I supect is unlikely.

DarkElvenAngel
Posts: 147
Joined: Tue Mar 20, 2018 9:53 pm

Re: Low voltage detection

Mon Apr 29, 2019 2:58 am

RogerW wrote:
Fri Apr 26, 2019 8:52 am
Thanks for that information. Because I wanted to detect transient low voltage blips I was hoping for an "interupt" type of solution rather than polling. I have now decided it is not worth pursuing unless it definitely proves to be a problem which I supect is unlikely.
I did a little more digging because I am interested in this problem and I found a few more things out. Low voltage detect is a GPIO Input known as PWR_LOW_N.
There's also an entry in /sys/devices/platform/soc/soc:firmware/get_throttled
and a kernel event that gets logged.

So far though I had no luck finding a way to generate a callback from these maybe someone else does.

Reference link.
https://github.com/raspberrypi/linux/issues/2367

Return to “C/C++”