IRNAS / ppk2-api-python

Power Profiling Kit 2 unofficial python api.

Home Page:http://irnas.eu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Skips at maximum frequency

VitaliChar opened this issue · comments

Hi, there is a problem. If remove the sleep to obtain the maximum polling frequency, then zero values ("-1.2596387693469735") ​​appear, which distort the final result.

    ppk2_test = PPK2_API("/dev/ttyACM0")  # serial port will be different for you
    ppk2_test.get_modifiers()
    ppk2_test.use_source_meter()  # set source meter mode
    ppk2_test.set_source_voltage(3300)  # set source voltage in mV
    ppk2_test.toggle_DUT_power('ON')
    ppk2_test.start_measuring()  # start measuring

    # read measured values in a for loop like this:
    start_time = time.time()
    while time.time() - start_time <= 1:
        read_data = ppk2_test.get_data()
        samples = ppk2_test.get_samples(read_data)
        ave = sum(samples) / len(samples)
        print(len(samples), ave)

    ppk2_test.stop_measuring()

result fragment:
1 -1.2596387693469735
1 -1.2596387693469735
1 41.078069146083955
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735
7 41.15273882494715
1 -1.2596387693469735
1 -1.2596387693469735
1 -1.2596387693469735

Looking at get_samples:

Returns list of samples read in one sampling period.
        The number of sampled values depends on the delay between serial reads. (...)

Are you sure you even have samples in the buffer when not waiting at all? The example also checks that get_data has valid values before passing it into get_samples. Please print the get_data values to see what you are parsing.

Yes, that's right. But if I need to get the maximum number of samples per second, I set the minimum delay between reads: in the PC version, the maximum number of samples = 100,000 is a delay of 0.00001 seconds. If I set delay in my script = 0.00001 the result is as described above.

Result printing get_data:

def get_data(self):
    """Return readings of one sampling period"""
    sampling_data = self.ser.read(self.ser.in_waiting)
    print(f"{sampling_data=}")
    return sampling_data

sampling_data=b''
1 -1.0382233070880205
sampling_data=b'\r\x03\x00\xff\x11\x03\x04\xff\x0c\x03\x08\xff\x11\x03\x0c\xff\x0c\x03\x10\xff\x0e\x03\x14\xff\r\x03\x18\xff\t\x03\x1c\xff\n\x03 \xff\x08\x03$\xff\x08\x03(\xff\x08\x03,\xff\x0c\x030\xff\x0b\x034\xff\x08\x038\xff\x08\x03<\xff\x08\x03@\xff\x05\x03D\xff\x00\x03H\xff\xfd\x02L\xff\xff\x02P\xff\xfe\x02T\xff\xfd\x02X\xff\xfe\x02\\xff\x02\x03`\xff\x01\x03d\xff\xfb\x02h\xff\xfd\x02l\xff\xff\x02p\xff\xff\x02t\xff\xfc\x02x\xff\xfe\x02|\xff'
1 33.362310825840595

All resolved, thanks. In total, from all the samples, approximately 100,000 are obtained