Skip to content

PPK2 gives unrealistic measurments after some time #45

Open

Description

@RehabAbdAllah

Hi .. I am running PPK2 GUI and it works as expected .
trying to automate the current consumption measurement using ppk2-api but after few samples I get unrealistic measurements .
I know nothing is wrong with the connections as I get the expected measurement from PPK2 GUI .

My tests takes a long(ish) time as I want to measure consumption as different states .
I notice after ~ 20 minutes the samples looks unrealistic giving ~ 933333333 mA .

I set delay_between_samples_in_sec to 1 sec .
measurment logic runs in a thread and prints samples

 def _measurement_logic(self):
        while True and not self.stop_thread:
            if self.ongoing_capture:
                read_data = self.ppk2_device.get_data()
                if read_data != b"":
                    samples, _ = self.ppk2_device.get_samples(read_data)
                    self.stored_current_samples += samples
                    print(f"Average of {len(samples)} samples is: {sum(samples) / len(samples)}uA")
            time.sleep(self.delay_between_samples_in_sec)

Script I run to automate measurement - I save all the samples in a csv file to post process it later

if __name__ == "__main__":
    voltage = "3750"  # in mV
    nordic_ppk2 = PPK2(source_voltage_in_mV=voltage)
    nordic_ppk2.initialize_ppk2()
    nordic_ppk2.set_ppk2_power_state_on()
    time.sleep(50)
    csv_file_name = nordic_ppk2.start_capture(file_prefix="1st_run")
    time.sleep(600)
    nordic_ppk2.stop_capture()
    print(f"Generated file: {csv_file_name}")
    df = pd.read_csv(csv_file_name)
    # FINDING AVG,MAX AND MIN
    maximum = float(df.iloc[:,1].max())/1000
    minimum = float(df.iloc[:,1].min())/1000
    average = float(df.iloc[:,1].mean())/1000
    print(f'file = {csv_file_name} \n'
          f'Average = {average} mA\n'
          f'Maximum = {maximum} mA\n'
          f'Minimum = {minimum} mA\n')
    time.sleep(10)
    csv_file_name = nordic_ppk2.start_capture(file_prefix="2nd_run")
    time.sleep(600)
    nordic_ppk2.stop_capture()
    print(f"Generated file: {csv_file_name}")
    df = pd.read_csv(csv_file_name)
    # FINDING AVG,MAX AND MIN
    maximum = float(df.iloc[:,1].max())/1000
    minimum = float(df.iloc[:,1].min())/1000
    average = float(df.iloc[:,1].mean())/1000
    print(f'file = {csv_file_name} \n'
          f'Average = {average} mA\n'
          f'Maximum = {maximum} mA\n'
          f'Minimum = {minimum} mA\n')
    time.sleep(10)
    nordic_ppk2.set_ppk2_power_state_off()
    nordic_ppk2.terminate_ppk2()

Unrealistic output that I get after sometime

Average of 255 samples is: 201.08003375301806uA
Average of 255 samples is: 9180480.471826369uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9433153.33932497uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9610732.127517093uA
Average of 255 samples is: 9433715.411266329uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9530250.845644489uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430043.706021905uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9543359.397351908uA
Average of 255 samples is: 9433184.076690257uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499032.128314802uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499021.454707844uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9464867.022682201uA
Average of 255 samples is: 9528133.342755748uA
Average of 255 samples is: 9429927.242173648uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9562305.30156186uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9492217.184726877uA
Average of 255 samples is: 9498870.427615838uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9441757.668911548uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9450267.254938764uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499020.710508693uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9492365.621076312uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9431206.030643925uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430046.134434432uA
Average of 255 samples is: 9499029.582258144uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9442397.463163968uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430038.49626446uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9561069.033534253uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9519729.856048381uA
Average of 255 samples is: 9460137.32903363uA
Average of 255 samples is: 9532202.159327868uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9498821.900509326uA
Average of 255 samples is: 9430018.578808472uA
Average of 255 samples is: 9499020.710508693uA
Average of 255 samples is: 9440338.992101854uA
Average of 255 samples is: 9499021.454707842uA
Average of 255 samples is: 9438480.773886917uA
Average of 255 samples is: 9552899.290645674uA
Average of 255 samples is: 9430109.921257356uA
Average of 255 samples is: 9499014.443456272uA
Average of 255 samples is: 9430018.578808472uA

Activity

  1. NejcKle commented on Jun 18, 2024

    @NejcKle
    Collaborator

    Hello @RehabAbdAllah
    Please try the suggestion posted here: #36 (comment)

    Please report your findings.

  2. RehabAbdAllah commented on Jun 19, 2024

    @RehabAbdAllah
    Author

    Hi @NejcKle
    Thank you for your reply .
    I used the suggested fix .
    but I see a gradual increase to the total samples because the read samples are again unrealistic after a certain amount of time .
    I cannot add all the samples but this are the samples after 12 seconds and after 599 seconds.

    After 12 seconds

    Average of 10000 samples is: 1.0613972225712949mA
    [12.643112897872925]Average current: 2.5463548116633516mA
    [12.648344993591309]Average current: 2.5463548116633516mA
    [12.653423070907593]Average current: 2.5463548116633516mA
    [12.658760070800781]Average current: 2.5463548116633516mA
    [12.663992881774902]Average current: 2.5463548116633516mA
    [12.669111013412476]Average current: 2.5463548116633516mA
    [12.674423933029175]Average current: 2.5463548116633516mA
    [12.67964792251587]Average current: 2.5463548116633516mA
    [12.685637950897217]Average current: 2.5463548116633516mA
    [12.691624879837036]Average current: 2.5463548116633516mA
    [12.698649883270264]Average current: 2.5463548116633516mA
    [12.704917907714844]Average current: 2.5463548116633516mA
    [12.710555076599121]Average current: 2.5463548116633516mA
    [12.71591591835022]Average current: 2.5463548116633516mA
    [12.725473880767822]Average current: 2.5463548116633516mA
    [12.744505882263184]Average current: 2.5463548116633516mA
    [12.756057024002075]Average current: 2.5463548116633516mA
    Average of 10000 samples is: 0.8791979206356576mA
    [12.769118785858154]Average current: 2.533227592048855mA
    [12.77507996559143]Average current: 2.533227592048855mA
    [12.780687093734741]Average current: 2.533227592048855mA
    [12.786417007446289]Average current: 2.533227592048855mA
    [12.791770935058594]Average current: 2.533227592048855mA
    [12.797851085662842]Average current: 2.533227592048855mA
    [12.803261756896973]Average current: 2.533227592048855mA
    [12.810301065444946]Average current: 2.533227592048855mA
    [12.822291851043701]Average current: 2.533227592048855mA
    [12.831923961639404]Average current: 2.533227592048855mA
    [12.842575073242188]Average current: 2.533227592048855mA
    Average of 10000 samples is: 1.0778059890655785mA
    

    After 599 seconds

    [599.2935330867767]Average current: 7164.5617474398705mA
    [599.3699128627777]Average current: 7167.4175782322545mA
    [599.4410929679871]Average current: 7167.4175782322545mA
    [599.5158860683441]Average current: 7167.4175782322545mA
    [599.5906610488892]Average current: 7167.4175782322545mA
    [599.6636469364166]Average current: 7167.4175782322545mA
    Average of 10000 samples is: 6816.917575591368mA
    [599.7597930431366]Average current: 7167.266500644936mA
    [599.8310089111328]Average current: 7167.266500644936mA
    [599.903904914856]Average current: 7167.266500644936mA
    [599.9753179550171]Average current: 7167.266500644936m
    
  3. wlgrd commented on Jul 3, 2024

    @wlgrd
    Collaborator

    Have you tried with the official software and confirmed that is behaving correctly?

  4. RehabAbdAllah commented on Jul 3, 2024

    @RehabAbdAllah
    Author

    yes it works fine on GUI application on my Mac and the python scripts works well on Raspberry pi .
    I can only see this problem with python scripts on Mac M1 .
    I am asumming it is something to do with the USB ports on Mac but I am not sure .
    for now I am using RPI to measure the current consumption with PPK2 .

  5. wlgrd commented on Oct 14, 2024

    @wlgrd
    Collaborator

    Weird. Have you tried with the latest firmware?

  6. bradanlane commented on Apr 19, 2025

    @bradanlane

    I encountered this issue. Here are some data points which may help:

    • MacOS Sequoia 15.4.1 on Apple Silicon
    • using the PPK2-API class directly (not using multi-threaded)
    • a single run (aka one one start_measuring() and one stop_measuring())
    • data gathering with get_data() and get_samples()
    • the call to get_samples() always returns 255
    • using time.sleep(0.001)
    • data is gathered for 60 seconds
    • test hardware runs for aprox 42 seconds with readings from Nordic's power profiler between 2mA and 20mA
    • test hardware goes to sleep after aprox 42 seconds and readings from Nordic's power profiler around 400nA

    The problem can occur at most anytime within the 60 seconds but most often happens after the test hardware has entered sleep mode.

    When using Nordic Power Profiler, the test completes without incident.

    FYI: Scanning for the PPK2 does not work as the serial ports created on MacOS are formatted as /dev/cu.usbmodem<SerialNumber>2 and /dev/cu.usbmodem<SerialNumber>4. using the port string directly in the PPK2-API constructor works.

    UPDATE: running a test of my same python code within a linux VM on the same Mac Apple Silicon and there have been no errors after more than 100 tests.

  7. MrKevinWeiss commented on Mar 13, 2026

    @MrKevinWeiss
    Collaborator

    So can we conclude it is some interaction with the MacOS? Unfortunately, I do not have access to a mac so it would be hard to reproduce and debug this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions