Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't loop FPGA code

I've created an sbRIO FPGA VI that counts the number of 25nS ticks between the pressing of two separate buttons. It's a simple flat sequence structure containing a timed loop in one frame to wait for either of the two buttons to be pressed, then sequences to a second frame also containing a timed loop that waits for the second button to be pressed. The loop counter of the second loop becomes the output, indicating how many ticks elapsed between button presses. It works fine when executed, but (of course) only makes one measurement per run. A .png of the VI is attached.

 

I want to make the measurement repeatedly, so I wrapped the sequence structure in a while loop, but that causes the VI to give unpredictable results (usually zeros, but every once and a while it will give a non-zero tick count once, but appears to not respond to subsequent button presses.)

 

Ultimately I want to have a PC-based VI that communicates with the FPGA-based VI to read the timing results and display to the user. BTW, instead of putting the while loop in the FPGA VI, I tried putting it in the PC-based VI and used an FPGA I/O node to read the tick count, but again it just gives zero as the result.

 

I suspect I'm making some fundamental mistake but can't seem to put my finger on it. Any ideas? TIA

0 Kudos
Message 1 of 4
(2,927 Views)

looks like you need to wait for both buttons to be "not pressed"  before you start looking for a button press.  you are catching the same button press when you don't wait for the button press to clear.

Stu
Message 2 of 4
(2,916 Views)

Stu, that did the trick! Thanks for taking the time to investigate and reply.

0 Kudos
Message 3 of 4
(2,909 Views)

Do your buttons have "bounce"?  you may want to write a test case to be sure unless you know that the circuit is bounceless.  if your buttons have bounce, you will have to add some more code to overcome it.

Stu
0 Kudos
Message 4 of 4
(2,891 Views)