From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FPGA execution mode

Solved!
Go to solution

Hello all.

 

Before writing about my problem I will try to describe my application and what I want to achieve. I have an sbRio in which I want to implement a control algorithm in order to control an inverter. At the moment, I have two main loops.

 

First loops read grid voltage from 3 analog inputs and it allocates them in a memory (with look-up table implementation). Execution time of this loop is 400 tick (I use tick timer VI for that).

 

In second loop I read from memory grid 3 voltages and I calculate wave phase and frequency with a PLL. Execution time of this loop is 400 tick as well.

 

In order to test this set up, I select simulation execution mode first. Instead of saving analog inputs in first loop, I simulate a grid with a VI. When simulating everything works fine and frequency and phase is correctly calculated. When testing with the real hardware it does not work. I think the problem is in how I pass voltage information from one loop to another, but I am not sure.

 

Hoping anyone can help. Thank you and best regards!

0 Kudos
Message 1 of 8
(1,568 Views)

I think it's because the quantum oscillator in your phase-declined-subwoofer are not compatible.

 

Jokes aside, please post an image of your code or even better, the code itself so that we have any kind of idea what you're talking about.

 

I think the problem is in how I pass voltage information from one loop to another, but I am not sure.

Don't you think then that a few words about HOW you are doing that might help identifying the problem?

0 Kudos
Message 2 of 8
(1,561 Views)

Sure. I upload the code. I also upload the vi I use to simulate the grid.

 

Regards.

0 Kudos
Message 3 of 8
(1,548 Views)

@igbaquedano wrote:
I think the problem is in how I pass voltage information from one loop to another, but I am not sure.

Yes, that IS your problem. You programmed a classic race condition by using a memory method for the data exchange. It would have been the same if you used three global variables.

Your two loops are not synchronized so you never know when results will be written to your memory and when data will be taken from that memory.

 

I suggest that you switch over to a FIFO method and add a "delimiter" channel so that you can distinguish between different data sets on the read loop.

 

Regards, Jens

Kudos are welcome...
Message 4 of 8
(1,511 Views)

Thank you for the advice Jens.

 

When it comes to synchronization, what method would you use? Would you deal with occurrences or is there anything more efficient?

 

What do you mean by a "delimiter" channel in FIFO. Do you mean to use interleaving?

 

Best regards.

0 Kudos
Message 5 of 8
(1,484 Views)
Solution
Accepted by topic author igbaquedano

JensG69_0-1598600548090.png

Here is a (draft) screenshot of my idea.

Top loops: Upper loop represents your aqusition loop, data is transferred by FIFO to the calculation loop. In order to syncronize the loops I have added an additional element that gets transmitted. The value of this additional element should be chosen in such a was that it is an invalid value for the normal aquisition. The calculation loop can then look for that sync value.

 

Another idea, shown in the bottom loop: Why do you split your problem in two loops. Both loops take the same time, so do the aquisition and the calculation in parallel inside one loop.

 

Regards, Jens

Kudos are welcome...
Message 6 of 8
(1,474 Views)

Thank you very much Jens.

 

Your explanation was very clear and helpful I will apply what you suggest with FIFOs. Anyway, with the synchronization you showed me in the first example, could it be possible to use a memory instead of a FIFO? There will not be any more race conditions right? What would be the advantage/disadvantage of FIFO vs Memory?

 

Could it be correct to use occurrences (to synchronize both loops) and memories (image attached)? Would this avoid race condition?

 

The reason why I split acquisition and calculation in different loops is because in the future I will need to run them at different speeds.

0 Kudos
Message 7 of 8
(1,453 Views)

Hello,

 

your idea might work, but I strongly recommend to set the occurence either after the FOR-Loop or on the second or third write cycle (depending on how fast memory read and memory write are definded) and not in parallel to the FOR-Loop.

 

Regards, Jens

Kudos are welcome...
Message 8 of 8
(1,428 Views)