04-09-2021 03:44 PM
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:
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:
Is there something that I have done wrong?
Thanks!
04-09-2021 06:02 PM
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. ??
04-09-2021 08:12 PM
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!
04-10-2021 04:49 AM
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?
04-10-2021 10:36 AM
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!
04-10-2021 03:21 PM
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.
04-11-2021 09:06 PM
Hi Lucian,
Thank you very much for the suggestions! I will give it a try.