LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FPGA VI communicating directly to a Windows application on PC

Quick background...

Using Labview 8.5 with the FPGA Module, I've created a large FPGA VI, with a bunch of Host VIs to interface with the FPGA VI, and bundled them into a DLL using the Buiild Specifications.  This DLL will be used by a proprietary Windows application whcih create it's own user interface, i.e. the Host VI's Front Panels' APIs aren't used.  From our application I read and write data to the FPGA VI, start and stop various parts of the FPGA VI code, etc.  It all works well.  By the way, I'm using the PCI-7811R board.

One part of the FPGA code is detecting the rising and falling edge of a particular signal.  Ideally what I'd like to have happen is when the signal changes state, my Windows application would be flagged instantly, for example via an interrupt, by my FPGA VI.  In other words, I'd like to by pass any Host VI.

Now from my understanding, only a Host VI can comunicate with the FPGA VI, and visa versa.  If that's the case, then all I can figure out to do is have my Windows application poll the state of the signal via a call to a Host VI that I would add to the DLL.  Not as efficient as I'd like.

So, is there any way to have the FPGA VI pass the state change information directly to my Windows application?

Thanks for your help.

-Rick

0 Kudos
Message 1 of 2
(2,106 Views)
You don't have to poll.

The fact that you want a non-LabVIEW application to get notification is
another problem (I'll talk about later on). The FPGA can send notifications
to a LabVIEW VI (or app. or dll) through a FIFO or queue. Basically, the
FPGA uses a case with a queue in it, and when the case switches, it puts an
element on the queue. You'll have to program that the elements get queued
only when a state changes, but that's as easy as using an XOR over the
current and the previous value... On the host VI, you'll get a queue
nitification. In a way, you still need to poll the data. The time out of the
read queue isn' working properly, so if yuo put it to e.g. 100000, the
processor will be 100% occupied... So, in a while loop you read the queue,
if it has an element, read it (you get an array of elements, so you can use
a for loop to process each element)... Still sound a lot like polling. But a
difference is that the queues use DMA, and that should be pretty efficient.
If you put the time out on 0, and you put a 2 ms wait in the loop, it hardly
uses processor time. You only have 3 channels though, but you can merge a
channel ID, and a state in an integer to get as much channels as you
require.

On the external program, there are but a few options. You can call a
function that quits only when a signal is received. This is not very
practical, since the rest of the application hangs, and you'll have to
create seperate threads. A callback is a good mechanism for this. It's
standard in C/C++, but not that easy to do in LabVIEW. Normally, the
question is make a vi that acts as callback, in your case you want to call a
callback. So you need to be able to call a function at a given pointer. The
main application needs to tell the LV dll what this pointer is. So you make
a function "WaitForStateChange" with a pointer parameter. The application
puts it's callback functions' pointer there when the function is called. To
do this, a long time ago I've created a dll (called calldlldll.dll). Check
out
http://forums.ni.com/ni/board/message?board.id=170&thread.id=39381&view=by_date_ascending&page=2 .
The example gets a pointer from LoadLibrary, GetProcAddress. In your case,
use the given pointer. The parameters should be the same, as if you where
calling the original function with a dll.

Regards,

Wiebe.







0 Kudos
Message 2 of 2
(2,085 Views)