LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pass value between while loops using FIFO in LabView FPGA

Hi everyone,

 

I am passing the AI value read from one while loop to another using FIFO with 1 Requested Element (since I just need to use the newest reading). The two while loops are set at the same loop time (3 us). The structure is shown below:

JustinZZJ_0-1618000978738.png

 

 

However, when I display the Write FIFO value from the sending loop (Input Current variable in the figure above) and compare with the Read FIFO value from the receiving loop (Input Current 2 variable in the figure above), the values are the not same:

JustinZZJ_1-1618001046054.png

Is there something that I have done wrong?

 

Thanks!

0 Kudos
Message 1 of 7
(2,358 Views)

You're probably looking at different elements.  Perhaps you are reading the 1st element  in the lower loop, but the upper loop has already put in that one and a few more when you are looking at the value in the upper loop.  ??

0 Kudos
Message 2 of 7
(2,323 Views)

Hi RavensFan,

 

Thank you for your prompt reply. I have set the Number of Requested Elements to 1 in the FIFO, which I understand would be the size of FIFO, so it will only have 1 element and if I read it, only the current element will be read? Also, the two while loops are both set to 3 us cycle time, so why there will be extra elements in the FIFO, since I assume writing and reading the FIFO are synchronized in this situation?

 

Furthermore, if I want to pass the current element of analog input immediately to another while loop so that writing and reading between two while loops will be synchronized, do you recommend using either FIFO, memory block, local variable, or global variable?

 

Thank you!

0 Kudos
Message 3 of 7
(2,307 Views)

 


 

Furthermore, if I want to pass the current element of analog input immediately to another while loop so that writing and reading between two while loops will be synchronized, do you recommend using either FIFO, memory block, local variable, or global variable?

 


If you need to process every AI sample, I would use a FIFO and monitor the Timed Out? of the FIFO read function. If it is TRUE, do nothing and iterate loop. Process values only if Timed Out is FALSE. Consumer loop doesn't have to be timed - leave the loop execute as fast as possible.

It's not clear for me why do you want to use 2 loops, why not read AI and process values in the same loop?

Lucian
CLA
0 Kudos
Message 4 of 7
(2,285 Views)

Hi Lucian,

 

Thanks for your reply. I am using 2 loops - one for reading AI from NI9223, and another for processing the AI sample reading (I am doing integration for calculating energy). I read that this structure allows parallel execution resulting in faster speed. Please let me know your suggestions.

 

Thanks!

0 Kudos
Message 5 of 7
(2,272 Views)

Put everything in one loop and forget about the FIFO. If your processing operations take more than your minimum loop time, you should try to optimize the code if possible (perhaps by pipelining). Reach back for help if you get stuck.

Lucian
CLA
0 Kudos
Message 6 of 7
(2,263 Views)

Hi Lucian,

 

Thank you very much for the suggestions! I will give it a try.

0 Kudos
Message 7 of 7
(2,219 Views)