Academic Hardware Products (myDAQ, myRIO)

cancel
Showing results for 
Search instead for 
Did you mean: 

myRIO Real-Time Read from SPI slowing down

Solved!
Go to solution

Hi community,

 

I have this realt-time thread wich samples my control system variables at precisely 1 kHz. Since there are a lot of variables, I am not using myRIO analog inputs, but instead I am using a AC8732 data converter from texas instruments, which has a lot of AIs, AOs and GPIOs. It communicates via SPI bus.

 

Everything was going smoothly while I was reading only two channels of the data converter, which results in 48 bits transfer (16 bit of address write and 16 bit of each channel read-back). Once I started to read 15 channels, the real-time loop started to miss all iterations, like if it was not able to fetch the 15 channels periodically with 1 ms. However, I am communicating with the data converter at 4 MHz, wich results in 64 us for the whole transmission, leaving the RT loop more than 900 us to do whatever it has to do. But it is doing only this one task: read from spi. I already got rid of the express VIs and moved to the advanced VIs as shown in the attached screen, but no success so far.

 

What would I have to do to get the data with no delay?

 

Fetch SPI data

 

Thanks in advance.

0 Kudos
Message 1 of 8
(6,936 Views)

What was your actual end with only two channels?

0 Kudos
Message 2 of 8
(6,916 Views)

natasftw escreveu:

What was your actual end with only two channels?


Hi, natasftw! Thanks for your answer.

 

I was using two channels only for testing purposes of the communication. Once I saw the devices were communicating properly, I went to full frame communication.

 

In fact, when I was reading only two channels I did not perform any benchmark to test if the time is satisfactory. Now that you pointed out, I did this simple VI:

 

SPI test

 

It is 2 bytes writing and 4 bytes reading at 4 MHz clock. This communication should happen in 12 us, but measuring the time with the tick count VI, the process is executed in 300 ms Smiley Frustrated.

 

What is happening? Please help me out.

0 Kudos
Message 3 of 8
(6,894 Views)

New update:

 

I realized that in the first moment the Smart open VI takes longer to open the channel, so I altered the test to become like this:

 

SPI Test

 

Reading 2 channels takes around 400 microseconds and reading 15 channels takes around 1200 microseconds, which should take 12 and 64 microseconds respectively. Any thoughts why it is so slow?

0 Kudos
Message 4 of 8
(6,889 Views)

Any one Smiley Sad

 

Is there at least any solution for continuous reading from SPI?

0 Kudos
Message 5 of 8
(6,817 Views)
Solution
Accepted by topic author FilipeTaveiros

Are you coding purely in RT or are you using the FPGA on the myRIO as well?

 

Take a look at:http://www.ni.com/white-paper/9117/en/

 

This discusses implementing SPI on the FPGA.  The API for SPI should also work on both RT and FPGA.

 

It looks like we've definitely determined the computation time is the cause.  Moving some of this code to the FPGA should help to optimize your code a bit.

0 Kudos
Message 6 of 8
(6,813 Views)

There is a inherent delay between each byte transferred. That is why you are not getting your data at the advertized 4 MHz as expected. This delay eats up the bandwidth. I am trying to figure out a way to fix this. Inquiring from NI Assistance now.

0 Kudos
Message 7 of 8
(4,229 Views)

If you hook up a logic analyzer to your SPI bus you would see this delay between each byte

0 Kudos
Message 8 of 8
(4,228 Views)