IRNAS / ppk2-api-python

Power Profiling Kit 2 unofficial python api.
http://irnas.eu
GNU General Public License v2.0
145 stars 37 forks source link

Ampere Meter Mode without fixed Voltage #39

Closed savejeff closed 10 months ago

savejeff commented 10 months ago

Hi,

first, thank you for creating this library. saved me a lot of work. unfortunately i have changing voltage in ampere mode as i measure current out of a battery.

I've found another issue where it was stated, this feature is currently not focused for development. I would like to add this functionality. can you give me information about the protocol the PPK2 uses? any resourced are apprechiated

wlgrd commented 10 months ago

Unfortunately, the PPK2 doesn't report the voltage of the device under test. The packet structure of the PPK2:

                                                  |--  Extra USB present, bit 17
        |-- Logic state, 8 bits (24-31)           |   |-- Range, 3 bits (14-16)
        |                     | count (18-23)     |   |     |
        |      Logic  (8bits) |                   B   | R   |    Analog samples, 14 bits (0-13)       |
Bit     31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
savejeff commented 10 months ago

Thanks for the quick response. how does the tool from Nordic calculate the current accurately in ampere meter mode? is the voltage even needed for calculating current? Also what happens when the target voltage in the source meter can not be achieved when drawing higher current and limited supply power over USB?

wlgrd commented 10 months ago

The PPK2 calculates it by measuring the voltage drop over a set of resistors. Ohms law: Voltage = Current * Resistance, and in turn Current = Voltage/Resistance. The magic is somewhat behind switching in the correct resistor to avoid having too much of a voltage drop, making the nRF's ADC reach its limit. So you need voltage, but you don't need to know the voltage to the device you are measuring.

If you are working beyond the specification of the kit, then you are risking breaking things or best case getting a warning from your OS that your USB device draws too much power. The target voltage should always be able to be achieved as long as you are operating below ~600mA current draw (with one USB cable connected)

savejeff commented 10 months ago

yes im familiar with a shunt based current measurement. so, to calculate the correct current two things are needed:

where does the target voltage come into play here that i have to set in ampere meter mode (otherwise you get an exception)

so is there a need right now with this library to know the current voltage that is applied to the device under test?

wlgrd commented 10 months ago

There is a very slight non-linear curve to the ADC result coming from measuring the shunt resistor, which is slightly based on the vdd of the DUT. The exception comes from the fact that the PPK2_API.current_vdd is not set during the calculation of the ADC conversion. The API could have set the default value to e.g. 3.0V to avoid this, but since this is a port of the nordic javascript software which always sets a default vdd, I am guessing that this is inherited from that.

savejeff commented 10 months ago

so the desktop software does not do anything different from this lib to calculate the current and it would be sufficient to just set the voltage in ampere meter mode to roughly the correct value?

wlgrd commented 10 months ago

Correct