Skip to content
Snippets Groups Projects
Commit f519abd7 authored by Jake Read's avatar Jake Read
Browse files

prelim spi tests with mechanics intact

parent 54ac2a07
Branches
No related tags found
No related merge requests found
import spidev
import spidev, time
# import numpy as np
# from plot_stamps import plot_stamps
bitrate = 1000000
bitrate = 10000000
print(f'rate {bitrate/1e6}MBit/s bit period should be {1000000000/bitrate}ns')
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = bitrate
spi.mode = 0b00
spi.mode = 0b10
test_pck = bytearray(32)
pck_len = 64
stamp_count = 10000
# stamps = np.zeros(stamp_count)
test_pck = bytearray(pck_len)
for b in range(len(test_pck)):
test_pck[b] = b
test_pck[b] = b + 1
print(test_pck)
for i in range(1000):
# 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
for i in range(stamp_count):
if bonked:
break
ret = spi.xfer(test_pck)
print(ret)
# stamps[i] = time.perf_counter() * 1e6
start = -1
for j in range(len(ret)):
if start == -1:
if ret[j] == 0:
start = j
continue
else:
if ret[j] != j - start:
print(f'BONK at {i} char {j} {start} {ret[j]}')
print(ret)
bonked = True
break
spi.close()
# plot_stamps(stamps, stamp_count, pck_len)
spi.close()
\ No newline at end of file
# 1Mbit seems solid,
# 2.5Mbit and we have very occasional starvation
# 5Mbit and we have at least one bad packet every run (1/1000?)
# 5Mbit with more F_CPU (250MHz) it is obviously improved (1/5000?)
# 10Mbit at 250MHz we are back to ~ (1/2000) starvations,
\ No newline at end of file
import pandas as pd
import matplotlib.pyplot as plt
def plot_stamps(stamps, stamp_count, pck_len):
# make df from stamps
df = pd.DataFrame({'timestamps': stamps})
# calculate deltas between stamps
df['deltas'] = df['timestamps'].diff()
# clean NaN's
df = df.dropna()
# wipe obviously-wrong deltas (i.e. the 1st, which goes 0-start-us)
df = df[df['deltas'] < 10000]
# Plotting
fig, ax1 = plt.subplots(figsize=(11, 3))
ax1.set_xlim([50, 2000])
# Primary x-axis (time deltas)
df['deltas'].plot(kind='hist', bins=50, ax=ax1)
ax1.set_xlabel('Time-Stamp Deltas (us) and equivalent (MBits/s)')
ax1.set_ylabel(f'Frequency (of {stamp_count})')
# get axis ticks to calculate equivalent bandwidths
x_ticks = ax1.get_xticks()
ax1.set_xticks(x_ticks)
bandwidths = [((pck_len * 8) * (1e6 / x)) / 1e6 for x in x_ticks]
ticks = []
for i in range(len(x_ticks)):
print(i, x_ticks[i], bandwidths[i])
ticks.append(f"{x_ticks[i]:.0f} ({bandwidths[i]:.3f})")
ax1.set_xticklabels(ticks)
plt.title(f'Single-Source COBS Data Sink Deltas, pck_len={pck_len}')
plt.tight_layout()
plt.show()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment