FIRST Robotics Competition Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

SubVI exibits odd behavior when using multiple instances

First of all, I am quite a newbie in Labview programming.

I have written a subVI that emulates an asynchronous S/R (set/reset) flip-flop.  This is just 2 cross-wired NOR gates.  The SET input of the flip-flop is connected to a momentary boolean control. The Q output of the FF is connected to the input a timer.  The elapsed time output of the timer is connected to the RESET input of the FF.  In essence, my VI takes a short pulse in, and stretches it out to a predictable value.  I use it to extend a simulated  "blip" from a photoelectric eye. Works just fine.

So I decided "hey, i'm so proud of my useful new flip-flop, i'll use it in several other places in the VI"".  That's when the weird stuff happened.  Each FF instance behaved just like the original FF!  When the timer reset my photoeye FF, it also reset other FF's that had no connection to the timer or photoeye.  It's like they reference the same memory location.

So do I have to something extra to these subVI's so that each one will be a unique instance?  This sorta reminds me of C pointers (eeeek!).

Please help,

wezelball

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

Great idea to make your code into a SubVI.  That's Code Reuse at it's best.

Your problem is that all your insances of the VI (all the places you use it) are sharing the same data, so since it has a "memory" of past events, it's getting them all mixed up.

What you need to do is make the VI "re-entrant", which means it can be called many times simultaniously and still keep all the instances straight.

Open up your SubVI

Right Click on the VI Icon (top corner of Front Panel).

Select "VI Properties"

Expand the "Category" list and select "Execution"

Check the "Reentrant Excution" box and then ckeck "Pre-allocate clone for each instance".

You should be set.

BTW, have you saved the VI out as a logical file name like:  FlipFlop.vi?

Have you also edited the Icon to make it your own (choose a color scheme and use it on all your SubVI's).

Phil.

Get a life? This IS my life!
0 Kudos
Message 2 of 2
(2,627 Views)