diff --git a/example.py b/example.py index 5753754..3e58860 100644 --- a/example.py +++ b/example.py @@ -19,7 +19,7 @@ ppk2_test = PPK2_API(ppk2_port, timeout=1, write_timeout=1, exclusive=True) ppk2_test.get_modifiers() -ppk2_test.set_source_voltage(3300) +ppk2_test.set_source_voltage(2850) ppk2_test.use_source_meter() # set source meter mode ppk2_test.toggle_DUT_power("ON") # enable DUT power diff --git a/src/example.py b/src/example.py new file mode 100644 index 0000000..9f8bd21 --- /dev/null +++ b/src/example.py @@ -0,0 +1,69 @@ + +""" +Basic usage of PPK2 Python API. +The basic ampere mode sequence is: +1. read modifiers +2. set ampere mode +3. read stream of data +""" +import time +from ppk2_api.ppk2_api import PPK2_API + +ppk2s_connected = PPK2_API.list_devices() +if(len(ppk2s_connected) == 1): + ppk2_port = ppk2s_connected[0] + print(f'Found PPK2 at {ppk2_port}') +else: + print(f'Too many connected PPK2\'s: {ppk2s_connected}') + exit() + +ppk2_test = PPK2_API(ppk2_port, timeout=1, write_timeout=1, exclusive=True) +ppk2_test.get_modifiers() +ppk2_test.set_source_voltage(2850) + +ppk2_test.use_source_meter() # set source meter mode +ppk2_test.toggle_DUT_power("ON") # enable DUT power + +ppk2_test.start_measuring() # start measuring +# measurements are a constant stream of bytes +# the number of measurements in one sampling period depends on the wait between serial reads +# it appears the maximum number of bytes received is 1024b +# the sampling rate of the PPK2 is 100 samples per millisecond +for i in range(0, 1000): + read_data = ppk2_test.get_data() + if read_data != b'': + samples, raw_digital = ppk2_test.get_samples(read_data) + print(f"Average of {len(samples)} samples is: {sum(samples)/len(samples)}uA") + + # Raw digital contains the raw digital data from the PPK2 + # The number of raw samples is equal to the number of samples in the samples list + # We have to process the raw digital data to get the actual digital data + digital_channels = ppk2_test.digital_channels(raw_digital) + for ch in digital_channels: + # Print last 10 values of each channel + print(ch[-10:]) + print() + time.sleep(0.01) + +ppk2_test.toggle_DUT_power("OFF") # disable DUT power + +ppk2_test.use_ampere_meter() # set ampere meter mode + +ppk2_test.start_measuring() +for i in range(0, 1000): + read_data = ppk2_test.get_data() + if read_data != b'': + samples, raw_digital = ppk2_test.get_samples(read_data) + print(f"Average of {len(samples)} samples is: {sum(samples)/len(samples)}uA") + + # Raw digital contains the raw digital data from the PPK2 + # The number of raw samples is equal to the number of samples in the samples list + # We have to process the raw digital data to get the actual digital data + digital_channels = ppk2_test.digital_channels(raw_digital) + for ch in digital_channels: + # Print last 10 values of each channel + print(ch[-10:]) + print() + time.sleep(0.01) # lower time between sampling -> less samples read in one sampling period + +ppk2_test.stop_measuring() diff --git a/src/examplePowerProfiler.py b/src/examplePowerProfiler.py new file mode 100644 index 0000000..2c313d0 --- /dev/null +++ b/src/examplePowerProfiler.py @@ -0,0 +1,15 @@ +""" +Basic usage of PowerProfiler +""" +import time +from power_profiler import PowerProfiler + +powerProfilerInstance = PowerProfiler() +powerProfilerInstance.start_measuring() + +time.sleep(5) + +powerProfilerInstance.stop_measuring() + +averageCurrentMa = powerProfilerInstance.get_average_current_mA() +print(f'averageCurrentMa={averageCurrentMa}') \ No newline at end of file diff --git a/src/example_mp.py b/src/example_mp.py new file mode 100644 index 0000000..d556546 --- /dev/null +++ b/src/example_mp.py @@ -0,0 +1,85 @@ + +""" +Basic usage of PPK2 Python API - multiprocessing version. +The basic ampere mode sequence is: +1. read modifiers +2. set ampere mode +3. read stream of data +""" +import time +from ppk2_api.ppk2_api import PPK2_MP as PPK2_API + +ppk2s_connected = PPK2_API.list_devices() +if(len(ppk2s_connected) == 1): + ppk2_port = ppk2s_connected[0] + print(f'Found PPK2 at {ppk2_port}') +else: + print(f'Too many connected PPK2\'s: {ppk2s_connected}') + exit() + +ppk2_test = PPK2_API(ppk2_port, buffer_max_size_seconds=1, buffer_chunk_seconds=0.01, timeout=1, write_timeout=1, exclusive=True) +ppk2_test.get_modifiers() +ppk2_test.set_source_voltage(2850) + +""" +Source mode example +""" +ppk2_test.use_source_meter() # set source meter mode +ppk2_test.toggle_DUT_power("ON") # enable DUT power + +ppk2_test.start_measuring() # start measuring +# measurements are a constant stream of bytes +# the number of measurements in one sampling period depends on the wait between serial reads +# it appears the maximum number of bytes received is 1024 +# the sampling rate of the PPK2 is 100 samples per millisecond + +t = time.process_time() +timeLimit = 10 +while True: + read_data = ppk2_test.get_data() + if read_data != b'': + samples, raw_digital = ppk2_test.get_samples(read_data) + print(f"Average of {len(samples)} samples is: {sum(samples)/len(samples)}uA") + + # Raw digital contains the raw digital data from the PPK2 + # The number of raw samples is equal to the number of samples in the samples list + # We have to process the raw digital data to get the actual digital data + digital_channels = ppk2_test.digital_channels(raw_digital) + for ch in digital_channels: + # Print last 10 values of each channel + print(ch[-10:]) + print() + + time.sleep(0.001) + + elapsedTime = time.process_time() - t + print(f'elapsedTime={elapsedTime} of timeLimit={timeLimit}') + if (elapsedTime > timeLimit): + break + +ppk2_test.toggle_DUT_power("OFF") # disable DUT power +ppk2_test.stop_measuring() + +""" +Ampere mode example +ppk2_test.use_ampere_meter() # set ampere meter mode + +ppk2_test.start_measuring() +while True: + read_data = ppk2_test.get_data() + if read_data != b'': + samples, raw_digital = ppk2_test.get_samples(read_data) + print(f"Average of {len(samples)} samples is: {sum(samples)/len(samples)}uA") + + # Raw digital contains the raw digital data from the PPK2 + # The number of raw samples is equal to the number of samples in the samples list + # We have to process the raw digital data to get the actual digital data + digital_channels = ppk2_test.digital_channels(raw_digital) + for ch in digital_channels: + # Print last 10 values of each channel + print(ch[-10:]) + print() + time.sleep(0.001) # lower time between sampling -> less samples read in one sampling period + +ppk2_test.stop_measuring() +""" \ No newline at end of file diff --git a/src/power_profiler.py b/src/power_profiler.py index 7af0f6f..4f7ba92 100644 --- a/src/power_profiler.py +++ b/src/power_profiler.py @@ -8,7 +8,7 @@ from ppk2_api.ppk2_api import PPK2_MP as PPK2_API class PowerProfiler(): - def __init__(self, serial_port=None, source_voltage_mV=3300, filename=None): + def __init__(self, serial_port=None, source_voltage_mV=2850, filename=None): """Initialize PPK2 power profiler with serial""" self.measuring = None self.measurement_thread = None @@ -171,6 +171,7 @@ def get_average_current_mA(self): """Returns average current of last measurement in mA""" if len(self.current_measurements) == 0: return 0 + average_current_mA = (sum(self.current_measurements) / len(self.current_measurements)) / 1000 # measurements are in microamperes, divide by 1000 return average_current_mA