LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way how to write FPGA data in rt cRIO system in tdms file

Solved!
Go to solution

Hardware i am using is cRio 9024 controller, 9118 chassis and the 9215 analogue module...

0 Kudos
Message 11 of 19
(4,546 Views)

Hej Mark,

 

thank you very much for your detailed answer. This gives me a lot of new ideas and understanding.

 

I tried now a lot of different ways to find a good solution using first the DMA fifo to send the data from the FPGA to the rt system and then reading the data in the rt system into a rt fifo in the high priority loop. FInally I wanted to write the data from the rt fifo to a tdms file in a low priority loop. But since the low priority loop runs around 20-50 times slower than the high priority loop,I was thinking if it would be possible to read the data from the rt fifo in a for-loop. If I understand correctly, I can just read one element from the rt fifo each time i call it . That means if i write a scalar or a 1D array to the rt fifo 20 times faster then reading from the rt fifo, I have to call the rt fifo read vi 20 times in e.g. a for loop if i do not want to loose data?

 

I tried the following part in my vi, but I do not get the correct result in my tdms file.

 

First I write an array from the DMA fifo to the rt fifo (I make sure that there are at least some (150) elements in the fifo before I start reading them in the other loop)

 

NI_Forum_saveData_HP_part.png

 

 

And then I try to read the data 20 times slower in the following loop:

 

NI_Forum_saveData_lP_part.png

 

But there are zeros or very strange low numbers (x*10^-312) in my tdms file if I do it this way.

 

Thus I am doing may be a very bad mistake? Or does anybody knows a better way how to read more than one element from the rt fifo in a loop which runs 20 times slower than the loop writing to the rt fifo?

 

A lot of thanks in advance.

 

Have a great weekend.

 

Andy

0 Kudos
Message 12 of 19
(4,524 Views)

you can take many elements from the dma fifo buffer. If you use a 0 in the elements to read and use the number of element remaining and wire that to the number of element you want to read from .. i.e. use the read fifo buffer twice. there are some examples when i find then i will send a link.

 

i read from multiple chnnels using the single buffer. to keep data aligned i add extra elements like a separator and timestamp to the analogue data.

 

when i get to work on monday i will see if i can create an example..

 

Mark

0 Kudos
Message 13 of 19
(4,521 Views)

Hi Mark,

 

thank you very much for your very fast answer. Unfortunately I do not really understand what you mean with


@MrBliss wrote:

you can take many elements from the dma fifo buffer. If you use a 0 in the elements to read and use the number of element remaining and wire that to the number of element you want to read from .. i.e. use the read fifo buffer twice. there are some examples when i find then i will send a link. 




Do you mean I take either a 0 or the number of elements which are in the dma buffer if they are enough to read (simple "greater as" comparison)? Or do you mean I should use the dma fifo buffer twice, once with reading 0 elements and asking for the elements and then in the second step read this number of elements?

 

I would be really thankful if you could send me a link since i couldn't found an example in the LabVIEW examples.

 


@MrBliss wrote:
....

i read from multiple channels using the single buffer. to keep data aligned i add extra elements like a separator and timestamp to the analogue data.

 

when i get to work on monday i will see if i can create an example..

 

Mark


Furthermore, I thought the elements are always aligned in the correct order since you always read first the oldest element in the fifo, or not? But adding a timestamp might be a very good idea, also for checking when data is lost. What kind of separator do you use?

 

Or do you mean, you read in parallel from the rt fifo and write then to the tdms file also in parallel loops?

 

Thank you very much in advance for your help. I really would appreciate if you could send me a short example of your producer/consumer structure and how do you read and write the dma fifo and the rt fifo.

 

Best regards

 

Andy

0 Kudos
Message 14 of 19
(4,501 Views)

fpga.png

Message 15 of 19
(4,492 Views)

rthost.png

In the RT code the top loop controls the fpga vi

Middle loop extracts data from the FIFO and adds it to a queue in block of 1000 sample

bottom loop adds the blocks of data to an array

the for loop save the data to a file.

 

Hope this helps

 

Mark

Message 16 of 19
(4,487 Views)

Hi Mark,

 

thank you very much for your example, showing how you are saving your data. It looks logical and reasonable for me and I will try to adapt this to my vi. But I have two short questions you can perhaps answer quickly:

 

I do not understand why you change your array data in the third loop first into a cluster and afterwards then back into an array for saving?

 

Do I see it correctly, that you use the "split array" function as a kind of fifo which takes out the first values if it become greater than "Max Elements in result array"?

 

Thanks again for your help. Finally I can make some progress here.

 

Best regards

 

Andy

 

0 Kudos
Message 17 of 19
(4,477 Views)

Hi Andy

 

I take 1000 samples and clusterise to be able to handle the amount of data. If i left it as whole array then everything slows down.

 

I hold at most 1000 x 1000 samples running at 50k gives me about 20 seconds worth of data cycling around all the time. i am only interested in the data post trigger event. if i try and hold any more than 1000x1000 i get memory problems on the RT side.

 

i tried to use the array subset..... was too slow. its the delete from array i use. deleting the first element before adding a new element at the end.

 

Hope that helps

 

Mark

0 Kudos
Message 18 of 19
(4,440 Views)
Solution
Accepted by topic author AndyKr

Hi Marc,

 

thank you for your explanation and all your help. I now managed to save the data at variable rates up to 10kS/s for 5 channels. I use the following two sub VIs, the first one in the high priority loop (2 ms) and the second one in a low priority loop (20 ms). Of course I also use the "NI_MinimumBufferSize" option for writing the tdms file. If Save Data in the high priority loop is false, I just read the full DMA fifo and through away all the data.

 

NI_Forum_saveHiPrio.png

 

NI_Forum_saveLowPrio.png

 

 

Observe Maybe this code can also somebody else who has the same problems with saving his data with the cRIO system.

 

Thanks again everybody for the great help here!

 

Best regards

 

Andy

Message 19 of 19
(4,430 Views)