LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FPGA - Synchronization between two loops with different loop rates.

Hi all,

I am trying to implement an Analog and Quadrature Decoder. Simply put, I have two loops:  LOOP 1 with an Analog Input (AI) which is a slower loop rate. Another loop: LOOP 2 has a digital input (input) and counts the Quadrature counts. I understand that Analog conversion is slower, and as a result,  LOOP 1 will have a slower higher tick rate. I want to pass the "counts" from LOOP 2 into LOOP1, so that I can synchronize the Analog Input with the number of quadrature counts. My issue at hand is: since LOOP 2 updates at a higher rate. Will the "counts" value that I pass/tunnel from LOOP 2 to LOOP 1 refresh at the LOOP 2's rate or at LOOP 1's rate.

Thanks,

Herrick Chang
0 Kudos
Message 1 of 3
(4,925 Views)


@hlchang wrote:
Hi all,

I am trying to implement an Analog and Quadrature Decoder. Simply put, I have two loops:  LOOP 1 with an Analog Input (AI) which is a slower loop rate. Another loop: LOOP 2 has a digital input (input) and counts the Quadrature counts. I understand that Analog conversion is slower, and as a result,  LOOP 1 will have a slower higher tick rate. I want to pass the "counts" from LOOP 2 into LOOP1, so that I can synchronize the Analog Input with the number of quadrature counts. My issue at hand is: since LOOP 2 updates at a higher rate. Will the "counts" value that I pass/tunnel from LOOP 2 to LOOP 1 refresh at the LOOP 2's rate or at LOOP 1's rate.

Thanks,

Herrick Chang


The only way to pass values between two parallel loops is by some sort of global variable (global or locals are fine, as are shared variables although I wouldn't recommend that for FPGA if you don't want to go outside of the FPGA target at all). Don't tunnel anything between two independant loops as they won't be independant anymore.

The local variable will be updated at the rate the writing loop updates it, though your slower read loop will obviously not see every value. Note that the FPGA compiler will protect the local variable access in both loops in order to avoid race conditions. This protection is necessary but expensive in terms of runtime performance of each loop as well as FPGA gate usage.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 3
(4,908 Views)
You can also pass data between loops on the FPGA using FIFOs or memory blocks, which are more efficient on the FPGA than local variables.  If your loops don't reference different clocks (this is only an issue if you use timed while loops and derived clocks) you can use memory blocks to transfer data between your loops; otherwise you'll have to use FIFOs which risk having stale data if you don't read frequently enough.

Another option might be to put your faster loop inside your slower loop, and run the faster loop a fixed number of times for each iteration of the slower outside loop.  Then the two loops will synchronize every iteration of the slower loop (which is the same as every n iterations of the faster loop).  However it would be difficult to maintain precise timing for the faster loop.
0 Kudos
Message 3 of 3
(4,899 Views)