LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronise loop with semaphores

Solved!
Go to solution

I am using semaphores to synchronize these 3 loops and I want to stop one of the loop, reset "data ready" and go to the next state of my state machine. While doing the step by step execution, I noticed the program just blocks. Do you have any idea why please? I attached my VI.

 

 

0 Kudos
Message 1 of 5
(417 Views)

Did you read the help on using semaphores? Do you understand the purpose of a semaphore (hint, it is not to synchronize loops)? If you're using a semaphore at 3 different places in your code what do you expect to happen? I realize that this is likely just example code designed to illustrate the issue. Perhaps if you could better explain what you're trying to do (not how you're trying to do it) you could get some advice on how to accomplish what you want to do. There should be no reason for you to need 3 parallel loops inside your main loop. Perhaps you need to either restructure your program or make changes to the way that your state machine works.

 

If you really need to synchronize loops then a rendezvous is a more appropriate mechanism.

0 Kudos
Message 2 of 5
(402 Views)

Hi John, 

 

Thank you a lot for your detailed reply. I took inspiration from a LabView Example code where they synchronize two loops using semaphores (Please see atached VI). 

 

My principal goal is to implement the following

FabFet_0-1638195380026.png

I want to synchronise communication between a Vi on my PC and a VI located in the FPGA of myRio 1900. In fact I want to read data from a file on the PC, write the data from the file to  DMA FIFO 1. On the FPGA, I want to read the DMA FIFO 1 and save the data in Memory. This is required because the processing algorythm need all the data. After saving the all the data to memory, I want to Read them back, process them and write them back to the memory. Once the processing is done, I want to read the processed data from the memory and write them to DMA FIFO 2. At the end of last operation on the FPGA, I want to inform the VI on the PC so that it can start reading the processed data and storing them and the cycle re-begins.

 

I am a new programmer and I would be glad to take advice about how to design a better communication protocol and if my design is acceptable, what will be the best way to implement it. Thank you in advance

0 Kudos
Message 3 of 5
(384 Views)
Solution
Accepted by topic author FabFet

OK, so you're not synchronizing the loops, you are sequencing them. I think that the example that you show has taken you down a wrong path. There is no way to control whether loop 1 or loop 2 runs first in that code. All the semaphore does is keep them from running at the same time. 

 

I would recommend that you look at a state machine architecture. In the state machine you would have states like "Initialize", "Read Data from File", "Write Data to DMA FIFO", for example. 

Message 4 of 5
(366 Views)

Thank you a lot. I will have a look at state machine. I also think, it will be the better way to implement this. I will mark the case as solved for now.

0 Kudos
Message 5 of 5
(359 Views)