This is what I'm running.
It's a long story but this system has been growing in both hardware and software for some time and we haven't wanted to rock the boat by upgrading. Maybe now's the time.
Even if the SPI and code is SUPER fast it won't solve the problem if something else takes over for more than 1/3 of a millisecond.
I'm not using the FIFO on the ADXL312 because it creates extra noise on the signals. (it's a design problem in the chip).
The code is written in Python and it uses the PyBBIO library to handle the SPI communication and GPIO.
Here's the snippet of code that is doing the tight loop grabbing the accelerometer data:
*********************** begin snippet **************************************
try:
while sample_count < sensor_channel.samples_per_burst + extra_samps_for_smoothing:
# wait for interrupt bit to go hi before grabbing the sample
while bbio.digitalRead(sensor_channel.accel_interrupt_gpio) == 0:
loop_count += 1
if loop_count > max_loop_count:
break
# read the SPI data
spi_read_data = bbio.SPI0.transfer(0, [((ADXL312_REG_INT_SOURCE_R | 0xC0)
<< 8), 0, 0, 0, 0])
enc_unpack = struct.unpack("<L", mem[EQEP2_POSITION:EQEP2_POSITION + 4])[0]
# INT_SOURCE spi_read_data[0] hi byte store in int_source
# nothing spi_read_data[0] lo byte
# DATA_FORMAT spi_read_data[1] hi byte
# DATAX0 spi_read_data[1] lo byte store in xlo
# DATAX1 spi_read_data[2] hi byte store in xhi
# DATAY0 spi_read_data[2] lo byte store in ylo
# DATAY1 spi_read_data[3] hi byte store in yhi
# DATAZ0 spi_read_data[3] lo byte store in zlo
# DATAZ1 spi_read_data[4] hi byte store in zhi
# FIFO_CTL spi_read_data[4] lo byte ignore
# it timed out, break out of the outer loop
if loop_count > max_loop_count:
break
# grab the bytes and put them in the right place
x_accel = (spi_read_data[2] & 0xFF00) | (spi_read_data[1] & 0x00FF)
y_accel = (spi_read_data[3] & 0xFF00) | (spi_read_data[2] & 0x00FF)
z_accel = (spi_read_data[4] & 0xFF00) | (spi_read_data[3] & 0x00FF)
# convert to +- 32767
if x_accel >= 32768:
x_accel -= 65536
if y_accel >= 32768:
y_accel -= 65536
if z_accel >= 32768:
z_accel -= 65536
BUFFA.append(x_accel)
BUFFA.append(y_accel)
BUFFA.append(z_accel)
BUFFP.append(enc_unpack)
# count the number of times data is missed
if spi_read_data[0] & 0x0001:
overrun_count += 1
sample_count += 1
except KeyboardInterrupt:
pass
*********************** end snippet **************************************