LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read signals when the loop takes different execution times?

We have developed a Labview software (not RT) which executes various events according to a loop-routine. Each cycle can take different amount of time according to the actions it should perform.

Now we have implemented a device that places 3 different signals on the parallel port of the PC according an outside state. The device is only able to place the signal by 50 milliseconds. At this point we don't have any trouble; the Labview routine can read the three different signals accordingly.

The problem arises when the routine performs rapidly or very slowly: If it has to perform many actions it won't read the data on the port, but if it performs very rapidly it will read the data more than once.


Here we ask your kind help and guidance: how can we solve the problem above? Hopefully maintaining the hardware design (parallel port), and letting the main routine perform as it goes, I mean, without considering its execution time.

I appreciate any help on this matter.

Best regards,
Mauricio Vidal
VIDAL & ASTUDILLO Ltda.
http://www.vidalastudillo.com
0 Kudos
Message 1 of 3
(2,657 Views)
It sounds as though you should put the routine that monitors the parallel port into a separate loop that isn't dependent on the execution of your other tasks. When it detects a new signal (a change since last time round the loop) it can send a message to the main loop, e.g. using a notifier.

>The device is only able to place the signal by 50 milliseconds.

Do you mean the state you want to detect at the parallel port is only there for 50 ms? On its own, a simple loop should be able to cycle much more often than that. BUT you can't rely on this, because the OS (Windows) may take control away from your program for any amount of time to handle other tasks. If you need to reliably detect a pulse 50 ms wide, you may need to use some kind of digital input DAQ board/modul
e instead of the parallel port.
0 Kudos
Message 2 of 3
(2,657 Views)
As was mentioned by tmh, using a while loop with your acquisition in parallel with you main code can help reduce transfer errors. With this second loop, you can set the rate at which you will query the parallel port with some accuracy.
The one issue with using parallel while loops is synchronization. To avoid missing data, you will want to create a buffer to store data from the parallel port until the main code can process this data. The easiest way to do this is to create a queue and write your acquired data to it. The main program will then be able to read from this queue at its leisure as long as it does not let it overfill. For examples of using queues, take a look at the following examples.

Queue to Pass Data

Running Multiple Tasks in LabVIEW
The advanced example from this library is a great example of how to do acquisition at the same time as analysis through queues.

Good luck with your application development.

Regards,

Matt Friedman
National Instruments
Message 3 of 3
(2,657 Views)