Principle¶
How a current at the device under test (DUT) becomes a number in a file. This page follows one sample from the PPK2 to the CSV.
flowchart TB
subgraph ppk2["In the PPK2"]
direction LR
current["current of the DUT"] --> range["one of five ranges"]
range --> word["sample word: reading, range,<br/>counter, digital inputs"]
end
subgraph host["On the computer"]
direction LR
cal["calibration"] --> filter["spike filter"]
filter --> floor["0.2 µA floor"]
floor --> file["CSV or .ppk2"]
end
ppk2 -- "USB, 100,000 samples per second" --> host
The PPK2 sends raw readings. Everything after the USB cable is done by this package, the same way as Nordic's Power Profiler app does it.
Measured quantities and modes¶
The PPK2 measures the current that flows through it, 100,000 times per second. With each sample it also reads the state of eight digital inputs. It does not measure voltage.
| Mode | Where the PPK2 sits | Supply voltage |
|---|---|---|
| Ampere meter | In series between a supply and the DUT | Whatever the supply gives. The PPK2 must be told |
| Source meter | It is the supply | Set by the PPK2, 0.8 to 5.0 V |
Measurement ranges¶
The PPK2 covers 200 nA to 1 A with five ranges and switches between them by itself as the current moves. From the PPK2 user guide:
| Range in the app | Range in the stream | Span | Resolution |
|---|---|---|---|
| 1 | 0 | 200 nA to 50 µA | 0.2 µA |
| 2 | 1 | 50 µA to 500 µA | 0.5 µA |
| 3 | 2 | 500 µA to 5 mA | 5 µA |
| 4 | 3 | 5 mA to 50 mA | 50 µA |
| 5 | 4 | 50 mA to 1 A | 1 mA |
The app and the user guide number the ranges 1 to 5. The PPK2's stream numbers them 0 to 4, and so does this package:
- in
--user-gain; - in
Session.set_user_gain; - in the calibration arrays.
There is no setting for where the PPK2 switches. Nordic's command list
includes SWITCH_POINT_DOWN and SWITCH_POINT_UP, but neither the app
nor this package sends them.
Each sample says which range it was taken in. The range is in the stream, not in the CSV. To see it, decode the words:
from pathlib import Path
from ppk2 import decode_sample_bytes
stream = Path("tests/fixtures/stream_poweron.bin").read_bytes()
ranges = [decode_sample_bytes(stream[i : i + 4]).range for i in range(0, len(stream), 4)]
changes = sum(a != b for a, b in zip(ranges, ranges[1:]))
print(f"{len(ranges)} samples, {changes} range changes, ranges {sorted(set(ranges))}")
That file is 6 ms of a dev kit being powered on: the current climbs through all five ranges.
Calibration¶
Every PPK2 carries its own calibration and sends it as text when asked.
ppk2 metadata prints it. In Python, Session.coefficients() returns
it.
Calibration data¶
Seven arrays of five values, one value per range:
| Name | Role in the formula |
|---|---|
R |
Resistance of the range, in ohms |
O |
Offset of the reading |
GS |
Gain, quadratic term |
GI |
Gain, linear term |
S |
Dependence on the supply voltage, slope |
I |
Dependence on the supply voltage, constant |
UG |
User gain, 1.0 unless changed |
And five single values:
| Name | Meaning |
|---|---|
Calibrated |
0 or 1. See below |
VDD |
The supply voltage the PPK2 was left at, in millivolts |
mode |
The mode it was left in: 1 Ampere meter, 2 Source meter |
HW, IA |
Whole numbers, reported as they come. This package does not interpret them |
The parser requires every one of these except VDD and mode. When
those two are missing, it assumes 3,300 mV and Ampere meter mode.
A PPK2 can leave a slot of an array blank, which it prints as -nan.
The parser then takes the value the app assumes for it. See the
protocol page for those values.
Calibrated flag¶
This line makes people think their PPK2 is faulty. It is not a fault. The PPK2 used for every measurement in this documentation reports it, and its captures agree with the app's on the same bench. Nothing in the app's source reads this value, and this package only stores it.
To check a PPK2, compare it with the app on the same DUT, as the validation does.
Formula¶
For a reading adc taken in range r, at a supply voltage vdd in
volts:
x = (adc * 4 - O[r]) * ((1.8 / 163840) / R[r])
uA = UG[r] * (x * (GS[r] * x + GI[r]) + S[r] * vdd + I[r]) * 1e6
x is the current in amperes before correction. 1.8 V is the reference
of the converter and 163,840 is 2^14 × 10. The second line:
- corrects the gain;
- adds the part that depends on the supply voltage;
- applies the user gain.
This is the app's formula. In Python it is
current_micro_amps.
The sample word 0x015c0097 decodes to a reading of 151 in range 0,
with counter 23 and D0 high. With the range 0 values of the PPK2
measured here, at 3,300 mV:
R[0] = 1002.1185913085938
O[0] = 122.94572448730469
GS[0] = 1e-19
GI[0] = 1.0
S[0] = -7.04615787939e-09
I[0] = 5.155071036711e-08
UG[0] = 1.0
x = (604 - 122.94572448730469) * ((1.8 / 163840) / 1002.1185913085938)
= 5.2738469903200775e-06
uA = 5.302145379685201
Supply voltage term¶
The formula has a term in vdd. In Source meter mode the PPK2 knows
the voltage, since it supplies it. In Ampere meter mode it does not:
--vdd, or set_source_voltage in Python, tells it. That is why the
option exists in both modes.
How much a wrong value costs depends on the range. On the PPK2 measured here, an error of 0.3 V shifts the result by:
| Range in the stream | Shift |
|---|---|
| 0 | 2 nA |
| 1 | 16 nA |
| 2 | 0.15 µA |
| 3 | 2.8 µA |
| 4 | 0.72 mA |
At sleep currents it does not matter. Above a few milliamperes it does: give the voltage the DUT really runs at.
User gain¶
UG multiplies the result of one range. It is 1.0 on the PPK2 measured
here. Session.set_user_gain and
--user-gain change it for one session, on the computer only.
Spike filter¶
The first readings after a range change can be far too high. The spike filter replaces them. It is the app's filter, with the app's defaults.
It is not a general smoother. It acts only around a range change:
- Two running averages follow all readings, a quick one and a heavier one.
- From each range change on, three readings are replaced by an average. The reading at the change is the first of the three.
- In the top range the heavier average is used, and the first two readings after the change are also kept out of both averages.
- Every other reading passes through unchanged.
On the 600 samples above, with their nine range changes:
| Mean | Highest reading | |
|---|---|---|
| With the filter | 5,205.55 µA | 127 mA |
| Without it | 5,907.45 µA | 288 mA |
The filter changed 23 of the 600 samples. Without it, the mean of these samples reads 13.5 % higher than the app shows.
| Setting in the app | Here | Default | Allowed |
|---|---|---|---|
| Samples to smooth | samples |
3 | 0 or more |
| Coefficient for range 1-4 | alpha |
0.18 | 0 to 1 |
| Coefficient for range 5 | alpha5 |
0.06 | 0 to 1 |
A smaller coefficient is a heavier average: with 0.18, each new
reading counts for 18 % of the average. To change the three numbers,
use
Session.set_spike_filter.
The command line has no option for it, on purpose: a file written by
ppk2 capture always uses the app's defaults.
samples=0 does not switch the filter off. The reading at each range
change is still replaced: 9 of the 600 samples above. To see what the
PPK2 really sent, decode the words yourself and skip the stream parser:
from pathlib import Path
from ppk2 import current_micro_amps, decode_sample_bytes, parse_metadata
coeffs = parse_metadata(Path("tests/fixtures/metadata.raw").read_bytes())
stream = Path("tests/fixtures/stream_poweron.bin").read_bytes()
currents = []
for i in range(0, len(stream), 4):
word = decode_sample_bytes(stream[i : i + 4])
currents.append(current_micro_amps(word.adc_14, word.range, 3300, coeffs))
print(f"{len(currents)} readings, mean {sum(currents) / len(currents):.2f} µA")
Nordic's command list also includes SPIKE_FILTERING_ON and
SPIKE_FILTERING_OFF, for a filter inside the PPK2. Neither the app
nor this package sends them.
Limit: waking from sleep¶
The filter does not remove everything, and it shows when a DUT wakes from sleep.

The figure shows two wake-ups of the same DUT, 0.2 s apart in one capture of the validation. The two traces overlap except for 40 µs, where one reads 50 to 120 mA.
To follow a current that jumps from microamperes to milliamperes, the PPK2 changes its measuring range. For 2 or 3 samples during that change it sits in its highest range and reports several hundred mA.
The spike filter exists for this. It replaces the readings after a range change by a running average, and keeps the first two readings in the top range out of that average.
A third one enters it, and the four samples that follow carry what is left of it: tens of mA that fade over 40 µs, as in the orange trace.
Those four samples add about 3.5 µC. A short event, such as a radio transmission of a few µC, can read nearly twice as much because of them.
In the captures of the validation, an
nRF54LM20 DK wakes five times a second. just plots prints these
counts:
| Capture | Wake-ups | With a sample above 20 mA |
|---|---|---|
Source meter, ppk2 capture |
140 | 50 |
| Source meter, the app | 137 | 45 |
Ampere meter, ppk2 capture |
140 | 58 |
| Ampere meter, the app | 137 | 56 |
It is the same in both modes and in the app's own captures.
Nordic covers the effect in three places:
- Its course on low-power Bluetooth LE products describes the cause. When an instrument switches its measuring resistor, the supply voltage at the DUT steps, and the decoupling capacitors take an inrush current, seen as an overshoot. How much of it shows depends on the instrument.
- Its webinar on the nRF54L series gives the wake-up before a radio event as an example: such spikes last about 10 µs and are not to be taken as the peak current of the device.
- The app's documentation of the spike filter says that the first samples after a switch may be higher than the actual value.
So part of the burst is a real current into the capacitors and part may be overshoot. The capture does not say how much of each.
What it costs depends on what is measured:
- A stretch that contains no wake-up is not affected. A region marked by the firmware often starts just after one, since the pin rises once the CPU runs. It is affected if the DUT sleeps and wakes inside it.
- The mean of a DUT that wakes often for short events reads too high.
For events that repeat, trust the median of their charge and not the mean: the leaked samples move the mean and not the median.
Noise floor¶
A value below 0.2 µA, negative noise included, becomes 0. The app does
the same when it receives a sample: its source gives 200 nA as the
lowest current a PPK2 reads. ppk2 capture applies the floor before
it writes the file and before it computes the mean it prints, so the two
agree.
Timing¶
The sample count is the clock. One sample lasts 10 µs, and the timestamp of a row is its number times 0.01 ms. No computer clock is involved, so rows are exactly 10 µs apart.
- A lost sample keeps its place. Each sample carries a counter. When the counter jumps, the parser puts a placeholder where each missing sample was. The trace keeps its true length, with one limit. The counter has 6 bits, so a loss of exactly 64 samples, or a multiple of 64, goes unseen, and a longer loss is counted short by a multiple of 64. See the protocol page for how.
- The rate is fixed. The PPK2 has no command that makes it send fewer
samples: its firmware ignores
AVG_NUM_SET. When the app shows fewer samples per second, it has averaged blocks of samples on the computer.ppk2 capturealways writes the full rate. - A capture starts about 10 ms before the DUT is powered. See the known caveats for why.
Digital inputs¶
The eight inputs of the logic port are read at the same instants as the current, and travel in the same sample word. That is why a marked region of code can be measured to the sample.
- In the library,
Sample.logicis a number in which D0 is bit 0. In the CSV'sD0-D7field, D0 is the leftmost character. - The PPK2 tells high from low against the voltage on the logic port's
VCCpin, which Nordic specifies from 1.65 to 5.5 V. - Nordic gives the inputs a typical bandwidth of 50 kHz. A pulse shorter than 10 µs can be missed.
- While the DUT is unpowered, the inputs can read high.
Accuracy¶
The accuracy is the PPK2's. Nordic's user guide gives ±10 % on the average value in ranges 1 to 4 and ±15 % in range 5, as typical figures, and "better than ±20 %" overall.
This package neither improves nor measures that. What it aims at is narrower: from the same samples, the same numbers as the app. See the validation for how that is checked.