I start in this forum with a problem, but I would have preferred to come up with a solution...
I spent a whole week looking for a solution before posting the following :
I have a project to read the bytes of a binary file and present them on a port (port A) of Pyboard_D_SF6W.
I have to do this every 100µs and read a datafile in binary mode.
At first, i want to measure the reading time of one byte of the file on an oscilloscope, so i wrote this code :
Code: Select all
from pyb import Pin, Timer
#----------
# INIT
#----------
strobe = Pin(Pin.cpu.A0, Pin.OUT_PP)
strobe.low()
# Timer 10KHz, period=100µs
flag=0
def tim1_isr(timer):
global flag
flag=1
tim1=Timer(1, freq=10000)
tim1.callback(tim1_isr)
i=300000 # File of 30 sec (300 Kb)
#----------------
# MAIN
#----------------
fi = open("/flash/data.bin", "rb")
print("Start")
while i>0:
if flag==1:
strobe.high()
octet = fi.read(1) # read next byte
strobe.low()
i-=1
flag=0
tim1.callback(None)
fi.close()
print("Complete")
#---- END OF SRC ----------------------------
About every second, the strobe signal stays at a high level for 230µs and it was no good for me...
I tried this code without reading a file, and the problem doesn't appear. So it looks like it comes from reading the file.
It looks like a pause created by reading a block of data or resetting a buffer. Do you think this problem is solvable?
Thank you for your help.