pyb.delay accuracy
Posted: Sat Feb 13, 2016 5:58 pm
Hi, has anyone noticed that pyb.delay is wildly inaccurate the first time it is invoked? I am trying to send SPI messages separated by a fixed delay of 1ms, but I am measuring that the first and second SPI messages can be anywhere from 60us to 900us apart. From the second message on, the separation is 1ms consistently. See code below.
My workaround is to send a sacrificial delay before the start of my actual timing-critical block, but I am wondering why this would be.
Thanks,
Steve
My workaround is to send a sacrificial delay before the start of my actual timing-critical block, but I am wondering why this would be.
Thanks,
Steve
Code: Select all
from pyb import SPI
spi = SPI(1, SPI.MASTER, baudrate=10000000, polarity=0, phase=1) # ~ 10.50 MHz
data = bytearray(4)
data[1] = 0xa1
data2 = bytearray(4)
data2[1] = 0xa2
data3 = bytearray(4)
data3[1] = 0xa3
data4 = bytearray(4)
data4[1] = 0xa4
DELAY = 1
#pyb.delay(DELAY) # sacrificial delay here
spi.send(data)
pyb.delay(DELAY)
spi.send(data2)
pyb.delay(DELAY)
spi.send(data3)
pyb.delay(DELAY)
spi.send(data4)
pyb.delay(DELAY)