12-15-2014 03:31 PM - edited 12-15-2014 03:32 PM
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?
Thanks in advance.
Solved! Go to Solution.
12-16-2014 07:29 PM
What was your actual end with only two channels?
12-18-2014 10:52 AM
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:
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 .
What is happening? Please help me out.
12-18-2014 12:51 PM
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:
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?
12-24-2014 07:50 AM
Any one ?
Is there at least any solution for continuous reading from SPI?
12-24-2014 01:02 PM
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.
06-26-2017 09:44 AM
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.
06-26-2017 09:45 AM
If you hook up a logic analyzer to your SPI bus you would see this delay between each byte