diff --git a/rpi_spi/code/spi_controller/pi_spi.py b/rpi_spi/code/spi_controller/pi_spi.py index 6c2c166bc38d00b2f250c543207e9a9e019a35f7..f2b67398a58fc0e983adb8ea9a6a9c4d4b39530c 100644 --- a/rpi_spi/code/spi_controller/pi_spi.py +++ b/rpi_spi/code/spi_controller/pi_spi.py @@ -1,8 +1,8 @@ import spidev, time -# import numpy as np -# from plot_stamps import plot_stamps +import numpy as np +from plot_stamps import plot_stamps -bitrate = 10000000 +bitrate = 11000000 print(f'rate {bitrate/1e6}MBit/s bit period should be {1000000000/bitrate}ns') @@ -13,7 +13,7 @@ spi.mode = 0b10 pck_len = 64 stamp_count = 10000 -# stamps = np.zeros(stamp_count) +stamps = np.zeros(stamp_count) test_pck = bytearray(pck_len) for b in range(len(test_pck)): @@ -21,15 +21,14 @@ for b in range(len(test_pck)): print(test_pck) -# TODO will be to finish making these plots, -# need to install pandas and numpy here w a venv -# for now I'm just going to turn the rate up until things go wrong bonked = False +bonk_count = 0 + for i in range(stamp_count): - if bonked: - break + # if bonked: + # break ret = spi.xfer(test_pck) - # stamps[i] = time.perf_counter() * 1e6 + stamps[i] = time.perf_counter() * 1e6 start = -1 for j in range(len(ret)): if start == -1: @@ -38,14 +37,17 @@ for i in range(stamp_count): continue else: if ret[j] != j - start: - print(f'BONK at {i} char {j} {start} {ret[j]}') - print(ret) + # print(f'BONK at {i} char {j} {start} {ret[j]}') + # print(ret) + bonk_count += 1 bonked = True break spi.close() -# plot_stamps(stamps, stamp_count, pck_len) +print(f"bonk {bonk_count} / {stamp_count}") + +plot_stamps(stamps, stamp_count, pck_len, bonk_count / stamp_count) # 1Mbit seems solid, # 2.5Mbit and we have very occasional starvation diff --git a/rpi_spi/code/spi_controller/plot_stamps.py b/rpi_spi/code/spi_controller/plot_stamps.py index 805d3d03592b2bb2e34fdd10a64864a8528d8581..eba07c262a5574afebfe697a10f2a3db9d98d09e 100644 --- a/rpi_spi/code/spi_controller/plot_stamps.py +++ b/rpi_spi/code/spi_controller/plot_stamps.py @@ -1,7 +1,7 @@ import pandas as pd import matplotlib.pyplot as plt -def plot_stamps(stamps, stamp_count, pck_len): +def plot_stamps(stamps, stamp_count, pck_len, misses): # make df from stamps df = pd.DataFrame({'timestamps': stamps}) @@ -17,7 +17,7 @@ def plot_stamps(stamps, stamp_count, pck_len): # Plotting fig, ax1 = plt.subplots(figsize=(11, 3)) - ax1.set_xlim([50, 2000]) + ax1.set_xlim([0, 1000]) # Primary x-axis (time deltas) df['deltas'].plot(kind='hist', bins=50, ax=ax1) @@ -26,6 +26,7 @@ def plot_stamps(stamps, stamp_count, pck_len): # get axis ticks to calculate equivalent bandwidths x_ticks = ax1.get_xticks() + x_ticks = [100, 200, 300, 400, 500, 600, 700, 800, 900] ax1.set_xticks(x_ticks) bandwidths = [((pck_len * 8) * (1e6 / x)) / 1e6 for x in x_ticks] ticks = [] @@ -36,7 +37,7 @@ def plot_stamps(stamps, stamp_count, pck_len): ax1.set_xticklabels(ticks) - plt.title(f'Single-Source COBS Data Sink Deltas, pck_len={pck_len}') + plt.title(f'Single-Source COBS Data Sink Deltas, pck_len={pck_len}, miss={misses}') plt.tight_layout() diff --git a/rpi_spi/images/2024-01-04_spi-histo-10Mb.png b/rpi_spi/images/2024-01-04_spi-histo-10Mb.png new file mode 100644 index 0000000000000000000000000000000000000000..a13302240ab25b2c6c33bce6472bff62f9810514 Binary files /dev/null and b/rpi_spi/images/2024-01-04_spi-histo-10Mb.png differ diff --git a/rpi_spi/images/2024-01-04_spi-histo-11Mb.png b/rpi_spi/images/2024-01-04_spi-histo-11Mb.png new file mode 100644 index 0000000000000000000000000000000000000000..43919f22a87ceb7544e73c831ed30664e79f7b98 Binary files /dev/null and b/rpi_spi/images/2024-01-04_spi-histo-11Mb.png differ diff --git a/rpi_spi/images/2024-01-04_spi-histo-15Mb.png b/rpi_spi/images/2024-01-04_spi-histo-15Mb.png new file mode 100644 index 0000000000000000000000000000000000000000..5fa3b972dac7a0cda6df2351d43728f7c61746c3 Binary files /dev/null and b/rpi_spi/images/2024-01-04_spi-histo-15Mb.png differ diff --git a/rpi_spi/images/2024-01-04_spi-histo-1Mb.png b/rpi_spi/images/2024-01-04_spi-histo-1Mb.png new file mode 100644 index 0000000000000000000000000000000000000000..cf4455a99ef8ce1fa1a20d9d1db68df8fe6e8473 Binary files /dev/null and b/rpi_spi/images/2024-01-04_spi-histo-1Mb.png differ