Multiple SPI Devices - Slow Down | LabJack
 

Multiple SPI Devices - Slow Down

5 posts / 0 new
Last post
patrick
patrickmcgarey's picture
Multiple SPI Devices - Slow Down

Hi I've managed to succesfully intergrate 5 SPI absolute encoders with a Labjack T7. I'm now trying to address a speed problem, which is that with each device that I add to read (in a python script), the rate of read reduces. For example I want to read all sensors at 10Hz or greater. If I listen to 1 sensor I get 10 Hz, If I listen to 2 I get ~7Hz, if I listen to all 5 I get ~2Hz. My setup is as follows: Each sensor's MISO, MOSI, CS, and CLK  are connected to a different DIO pin. The clocks (CLK) use the DIO's that have a PWM output. MOSI and CS are more or less dummy channels but are all different for each sensor. I'm using a python script interfaced to ROS to publish messages and have made a function to query readSPI. I'm currently using the USB port, however will soon try the Ethernet, although the size of each sensor's message is only ~22bit (~14Byte). This may be the problem since USB is limited to 50Byte (as I read in another thread). Therefore I'm curious if you see any problem with my setup, specifically as it relates to the max number of SPI connections that can be made, the use of discrete MOSI, CS, and CLK channels for each sensor. Any tips for speeds up would be greatly appreciated as 2Hz. Above all, I want to determine if this is a hardware implementation issue or software issue (on my end). Thanks as always for your A++ support.

LabJack Support
labjack support's picture
What is your SPI clock speed

What is your SPI clock speed running at?

How many bytes need to be transferred for each transaction?

 

There are a few things we can do to improving serial communication speeds. 

Clock Speed. Maximize the SPI clock speed to minimize transfer time.

Packet Packing. Use eNames to squeeze config, TX data and RX data (possibly for more than one sensor) into a single packet. Switching to Ethernet can help here because Ethernet packets are 1040 bytes compared to USB's 64.

Lua Scripting. The final, and usually fastest, option is to write a lua script that will run the SPI operations to collect data from the sensors. Lua scripts run right on the device so they are not subject to communication overhead. In this case the host application just needs to read the results produced by the lua script. 
 

patrick
patrickmcgarey's picture
These are good suggestions,

These are good suggestions, currently clocks are running at the Max rate (i.e., set to 0 or 65536), per transaction its 2 byte per 5 sensors.

I will try your suggestions thank you. Any comment on my settings listed here would be appreciated.

patrick
patrickmcgarey's picture
Can you give me a ballpark

Can you give me a ballpark estimate for the max read speed of the SPI (Lua vs Python). Currently with the python implemenation with just 1 sensor, we are only getting about 15Hz, I would except orders of mag greater than this. Still trying to descern if this is a hardware or software issue. Thanks for any info you can provide.

LabJack Support
labjack support's picture
15 Hz is pretty darn slow.

15 Hz is pretty darn slow. Normally we are looking at ~1 ms of communication overhead. If you are only transferring a couple bytes then that should be less than 1 ms of SPI time. So I would expect 500 Hz using the normal C-R operations that you are. There must be something slowing things down.

The speed of a lua script will depend on the operations is it performing. To transfer 3 bytes at 500 kHz takes 48 us. If we need to do a little math and such then I would expect to be able to hit 2-5 kHz.