Created
February 5, 2018 20:13
-
-
Save mattvenn/17b6b66f5a233a5f271b007a4e746d13 to your computer and use it in GitHub Desktop.
plot i2c read variance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial | |
import re | |
""" | |
i2c data captured with sigrok-cli: | |
sigrok-cli -C 0,1 -c "samplerate=500k:voltage_threshold=1.8-1.8:continuous=on" --driver=dreamsourcelab-dslogic --samples 10M -P i2c:sda=1:scl=0 -A i2c=address-write --protocol-decoder-samplenum > data.raw | |
""" | |
samplerate = 1.0/500e3 | |
def load_raw(): | |
y = [] | |
x = [] | |
last_time = None | |
max = 0 | |
with open("data.raw") as fh: | |
for val in fh.readlines(): | |
if 'i2c-1: Write' in val: | |
timestamp = int(int(val.split('-')[0]) * samplerate * 1000000) # multiply by 1000000 to get in microseconds | |
# print timestamp, last_time | |
if last_time is not None: | |
interval = timestamp - last_time | |
y.append(interval) | |
if interval> max: | |
max = interval | |
last_time = timestamp | |
print(max) | |
return y | |
def plot(y): | |
n = len(y) | |
import matplotlib.pyplot as plt | |
fig = plt.figure() | |
ax = fig.add_subplot(1,1,1) | |
# bin plot | |
plt.title('i2c write frequency on bbb') | |
ax.set_xlabel('interval (us)') | |
ax.set_ylabel('count') | |
# the histogram of the data | |
bins = range(10000,60000,100) | |
n, bins, patches = plt.hist(y, bins) | |
l = plt.plot(bins) | |
plt.show() | |
y = load_raw() | |
plot(y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment