RajeshAnand10
Posts: 22
Joined: Sun Oct 13, 2019 6:33 pm

Regarding the current measurement

Sun Oct 13, 2019 6:39 pm

Hello everyone. I'm new to Raspberry pi platform. I want to measure the current which is drawn by the CPU of my RPi 3 Model B V1.2.

Is there any option to measure the current which is drawn by the CPU when it runs any code, within the RPi hardware like a scope or oscilloscope that I can use directly?

Any suggestions would be helpful.

Regards,
Rajesh.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12355
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Regarding the current measurement

Sun Oct 13, 2019 7:18 pm

Not really, as it would imply putting a small resistor in series with the wire transferring the current to the SoC, (and other parts comprising what you want to monitor) and measuring the voltage drop over it.

Meaning you would need to cut the connection somewhere between the power and the SoC, which is in practicality impossible to do.

Also, the SoC doesn't use power from one source either, so you have to do this multiple times, and add the energy consumptions together.

You could measure the energy flowing "into" the PI, but that energy is also distributed to other things not having to do with the SoC's current consumption, things like USB device, and current going to the HDMI 5V line.

Also, when the SoC uses external RAM, you must measure its consumption too, as its part of the PI's own current use. If you also count other chips on the board as part of the PI, then the puzzle gets even more complex.

RajeshAnand10
Posts: 22
Joined: Sun Oct 13, 2019 6:33 pm

Re: Regarding the current measurement

Sun Oct 13, 2019 7:29 pm

Yeah, and that's why I would like to know if there are any options to do it in software without risking the hardware (especially the CPU) with some code probably?

I need to measure the power being consumed by the SOC.

User avatar
joan
Posts: 14378
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Regarding the current measurement

Sun Oct 13, 2019 7:39 pm

There is no way to measure the SoC current consumption in software.

You will have to design and build your own solution using the methods outlined by mahjongg.

User avatar
Imperf3kt
Posts: 2904
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia

Re: Regarding the current measurement

Sun Oct 13, 2019 8:24 pm

If your goal is to measure the difference between running different code then just measure the board as a whole as long as you don't use extra stuff (like wifi, or additional usb devices etc) you'll get an accurate enough reading to approximate how much more current one code takes to execute compared to another.

If that's what your end goal was.
If not, then what are you doing that requires the current consumption of the SOC?
55:55:44:44:4C
52:4C:52:42:41

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12355
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Regarding the current measurement

Mon Oct 14, 2019 12:34 pm

RajeshAnand10 wrote:
Sun Oct 13, 2019 7:29 pm
Yeah, and that's why I would like to know if there are any options to do it in software without risking the hardware (especially the CPU) with some code probably?

I need to measure the power being consumed by the SOC.
No!
there is no hardware inside the SoC, to measure its own current consumption.

and as far as I know no such feature exist in the PMIC either (it has a digital interface to the SoC, so it would be theoretically possible for the voltage converter (PMIC) to signal current consumption to the SoC, if it had that feature) ignoring that AFAIK the SoC also uses 5V directly (bypassing the PMIC).

alphanumeric
Posts: 2116
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Regarding the current measurement

Mon Oct 14, 2019 7:16 pm

Wouldn't a round about way to do it be monitoring the CPU load?

alphanumeric
Posts: 2116
Joined: Tue Jan 19, 2016 2:17 pm
Location: Sydney, Nova Scotia, Canada

Re: Regarding the current measurement

Mon Oct 14, 2019 7:20 pm

There are devices like this, https://www.adafruit.com/product/2690 To measure total current drawn by the Pi. Might be a bit of a PITA getting the adapters for it though.

User avatar
Imperf3kt
Posts: 2904
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia

Re: Regarding the current measurement

Tue Oct 15, 2019 12:10 am

alphanumeric wrote:
Mon Oct 14, 2019 7:20 pm
There are devices like this, https://www.adafruit.com/product/2690 To measure total current drawn by the Pi. Might be a bit of a PITA getting the adapters for it though.
Those things are no more accurate than a multimeter. You should use an oscilloscope, not a usb current meter.
55:55:44:44:4C
52:4C:52:42:41

User avatar
davidcoton
Posts: 4202
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Regarding the current measurement

Tue Oct 15, 2019 8:34 am

Imperf3kt wrote:
Tue Oct 15, 2019 12:10 am
Those things are no more accurate than a multimeter. You should use an oscilloscope, not a usb current meter.
What makes you think that oscilloscopes are any more accurate than multimeters? Any instrument that produces repeatable results can be calibrated accurately.

There is also the minor problem that an oscilloscope by itself will not measure current, only voltage. Measuring current requires a voltage measurement across a known resistor -- which with most oscilloscopes requires a differential measurement using two channels, since one side of the 'scope probe is likely to be grounded.
Signature retired

User avatar
Imperf3kt
Posts: 2904
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia

Re: Regarding the current measurement

Tue Oct 15, 2019 9:33 pm

I'm only regurgitating what was told to me from this very forum, that a multimeter will average its readings, including transients.
If that information is incorrect then I will stop spreading it, but I would like to ask what I should believe.
55:55:44:44:4C
52:4C:52:42:41

User avatar
davidcoton
Posts: 4202
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Regarding the current measurement

Tue Oct 15, 2019 10:10 pm

Accuracy and resolution of short duration events are two different things. The multimeter will not respond to short duration peaks or dips (except in modifying the average reading), but a 'scope will show them (if you are skilful enough to capture transient events). If you are interested in average current draw, use a meter. If spikes or dips are an issue, you need a 'scope and the skill to use it properly.
Signature retired

RajeshAnand10
Posts: 22
Joined: Sun Oct 13, 2019 6:33 pm

Re: Regarding the current measurement

Thu Oct 17, 2019 3:42 pm

Yeah, i need to know the changes in current for very short duration (micro seconds). I'm having a 12 bit ADC which i will use for fine resolution.

But is it fine if I use a small resistor (shunt resistor of 1 ohm) in series to the RPi and take the voltage signal across the shunt and measure current indirectly?

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

Re: Regarding the current measurement

Thu Oct 17, 2019 4:21 pm

RajeshAnand10 wrote:
Thu Oct 17, 2019 3:42 pm
Yeah, i need to know the changes in current for very short duration (micro seconds). I'm having a 12 bit ADC which i will use for fine resolution.

But is it fine if I use a small resistor (shunt resistor of 1 ohm) in series to the RPi and take the voltage signal across the shunt and measure current indirectly?
1 Ohm is not small when it comes to measuring currents of 2-3 Amps. You could lose up to 3V across that resistor on a fully loaded Pi 4B with a USB disk.

0.01 Ohm might be better. The voltage across the shunt must be as low as possible otherwise the Pi won'r get enough.

RajeshAnand10
Posts: 22
Joined: Sun Oct 13, 2019 6:33 pm

Re: Regarding the current measurement

Thu Oct 17, 2019 5:32 pm

rpdom wrote:
RajeshAnand10 wrote:
Thu Oct 17, 2019 3:42 pm
Yeah, i need to know the changes in current for very short duration (micro seconds). I'm having a 12 bit ADC which i will use for fine resolution.

But is it fine if I use a small resistor (shunt resistor of 1 ohm) in series to the RPi and take the voltage signal across the shunt and measure current indirectly?
1 Ohm is not small when it comes to measuring currents of 2-3 Amps. You could lose up to 3V across that resistor on a fully loaded Pi 4B with a USB disk.

0.01 Ohm might be better. The voltage across the shunt must be as low as possible otherwise the Pi won'r get enough.
Maximum current which the RPi 3B will be drawing is 2.5A ( After which the fuse blows off), So the Maximum voltage drop I can expect is 0.5V. in the shunt resistor.
How could I give supply to the RPi from the resistor network as I will be using micro USB to power RPi and physical wires for power supply to the Shunt resistor? Any provisions are available to connect RPi through the physical wires? (as i have read somewhere powering the RPi using GPIO but it seems to be complex and risky)

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

Re: Regarding the current measurement

Thu Oct 17, 2019 8:09 pm

RajeshAnand10 wrote:
Thu Oct 17, 2019 5:32 pm
Maximum current which the RPi 3B will be drawing is 2.5A ( After which the fuse blows off), So the Maximum voltage drop I can expect is 0.5V. in the shunt resistor.
Even 2.5A through a 1 Ohm resistor will drop 2.5V!

Although even if the voltage drop was 0.5V that would drop the 5V to 4.5V which is well under the level required for a Pi to run stable.

You can feed the Pi through the GPIO connector (Pins 2 or 4 and pin 6, for example). It is not that risky of you make sure you connect it right.

User avatar
jbeale
Posts: 3500
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: Regarding the current measurement

Thu Oct 17, 2019 9:01 pm

RajeshAnand10 wrote:
Thu Oct 17, 2019 3:42 pm
Yeah, i need to know the changes in current for very short duration (micro seconds).
AFAIK the Pi SoC runs from an onboard switch-mode converter that drops the +5V power input down to what the processor needs (maybe it is 1.8V and 3.3V? I don't know). If you want current consumption on a microsecond timescale, I'm not sure what you can see from measuring the +5V input current due to the DC-DC converter and all the filter capacitance between you and the actual internal SoC load. The capacitors tend to smooth out the fast voltage changes on a microsecond, and perhaps even millisecond timescale.

RajeshAnand10
Posts: 22
Joined: Sun Oct 13, 2019 6:33 pm

Re: Regarding the current measurement

Thu Oct 17, 2019 11:22 pm

jbeale wrote:
Thu Oct 17, 2019 9:01 pm
RajeshAnand10 wrote:
Thu Oct 17, 2019 3:42 pm
Yeah, i need to know the changes in current for very short duration (micro seconds).
AFAIK the Pi SoC runs from an onboard switch-mode converter that drops the +5V power input down to what the processor needs (maybe it is 1.8V and 3.3V? I don't know). If you want current consumption on a microsecond timescale, I'm not sure what you can see from measuring the +5V input current due to the DC-DC converter and all the filter capacitance between you and the actual internal SoC load. The capacitors tend to smooth out the fast voltage changes on a microsecond, and perhaps even millisecond timescale.
In that case, where the SOC requires higher current to process the load, there will be an increase in current from the main +5v supply right?

RajeshAnand10
Posts: 22
Joined: Sun Oct 13, 2019 6:33 pm

Re: Regarding the current measurement

Thu Oct 17, 2019 11:30 pm

rpdom wrote:
Thu Oct 17, 2019 8:09 pm
RajeshAnand10 wrote:
Thu Oct 17, 2019 5:32 pm
Maximum current which the RPi 3B will be drawing is 2.5A ( After which the fuse blows off), So the Maximum voltage drop I can expect is 0.5V. in the shunt resistor.
Even 2.5A through a 1 Ohm resistor will drop 2.5V!

Although even if the voltage drop was 0.5V that would drop the 5V to 4.5V which is well under the level required for a Pi to run stable.

You can feed the Pi through the GPIO connector (Pins 2 or 4 and pin 6, for example). It is not that risky if you to make sure you connect it right.
Yes Yes. I forgot to mention the resistor which I'm planning to use ( 0.2 ohms with 5 Nos 1-ohm resistors in parallel configuration).

Actually, in my case I have Unipi connected to RPi and Unipi is currently providing power for the operation of RPi (GPIO pins are currently locked to provide power to RPi). If I want to power RPi independently through MicroUSB (assuming I give power separately to Unipi and RPi), Is there any way to modify the MicroUSB where I can provide a shunt resistor for power calculations?

User avatar
Burngate
Posts: 6063
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Regarding the current measurement

Fri Oct 18, 2019 9:57 am

RajeshAnand10 wrote:
Thu Oct 17, 2019 11:22 pm
In that case, where the SOC requires higher current to process the load, there will be an increase in current from the main +5v supply right?
Yes, eventually.

At the 5v input, just after the ideal diode, there's a 47μF capacitor.
A resistor of 0.2Ω in series with the 5v input together with the 47μF capacitor forms a low-pass filter with a turnover at about 10μS. So you're unlikely to see much change at the μS scale.

The 5v then feeds the PAM2306A converter, which runs at 1.5Mhz, so any increase in current drawn by the 3v3 & 1v8 rails can take a further 0.66μS to propagate back to its input.

boyoh
Posts: 1343
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Regarding the current measurement

Sat Oct 19, 2019 10:41 pm

It might be possible to fit a 10ohm resistor
In series with the main 5v in/put lead to the
Pi, then using a multimeter to read the voltage
Drop. Then using the difference between the readings to calculate the current when the code
Is active. Might be worth a try use a high wattage
Resistor
Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

trejan
Posts: 758
Joined: Tue Jul 02, 2019 2:28 pm

Re: Regarding the current measurement

Sat Oct 19, 2019 10:54 pm

boyoh wrote:
Sat Oct 19, 2019 10:41 pm
It might be possible to fit a 10ohm resistor
In series with the main 5v in/put lead to the
Pi, then using a multimeter to read the voltage
Drop. Then using the difference between the readings to calculate the current when the code
Is active. Might be worth a try use a high wattage
Resistor
Regards BoyOh
Measuring the voltage drop across a current shunt is the plan already. However, a 10 ohm resistor is going to cause such a large voltage drop that the Pi won't boot. Even a 1 ohm resistor is too high.

RajeshAnand10
Posts: 22
Joined: Sun Oct 13, 2019 6:33 pm

Re: Regarding the current measurement

Sun Oct 20, 2019 2:23 pm

trejan wrote:
Sat Oct 19, 2019 10:54 pm
boyoh wrote:
Sat Oct 19, 2019 10:41 pm
It might be possible to fit a 10ohm resistor
In series with the main 5v in/put lead to the
Pi, then using a multimeter to read the voltage
Drop. Then using the difference between the readings to calculate the current when the code
Is active. Might be worth a try using a high wattage
Resistor
Regards BoyOh
Measuring the voltage drop across a current shunt is the plan already. However, a 10-ohm resistor is going to cause such a large voltage drop that the Pi won't boot. Even a 1 ohm resistor is too high.
I guess. How about I add resistors in parallel and reduce the effective resistance close to 0.2 ohms? will that be good enough to have a low voltage drop and will it be safe enough for the DAQ card which im using? since max current, I can expect from load is 1.5A (at the worst case) and 0.2ohms corresponds to 0.3V approximately.

trejan
Posts: 758
Joined: Tue Jul 02, 2019 2:28 pm

Re: Regarding the current measurement

Sun Oct 20, 2019 3:45 pm

RajeshAnand10 wrote:
Sun Oct 20, 2019 2:23 pm
How about I add resistors in parallel and reduce the effective resistance close to 0.2 ohms? will that be good enough to have a low voltage drop and will it be safe enough for the DAQ card which im using? since max current, I can expect from load is 1.5A (at the worst case) and 0.2ohms corresponds to 0.3V approximately.
0.2 ohms is still high for this situation. The under voltage lightning bolt warning comes on at ~4.6V so a 0.3V drop is going to cause problems. If you're passing 1.5A then those resistors will be dissipating 450mW.

Return to “Beginners”