LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I detect if a global bolean variable has changed

I have a boolean global variable that change its value from time to time. At hte beginning of my program I take the actual time, but everytime this value change I have to reset this previous value and take the actual one. I've tried to do this with the event structure but it doesn't work because this is a global variable and not a control in the panel. Some idea to solve this problem? Thanks in advance,

Angel
0 Kudos
Message 1 of 8
(5,086 Views)
I would use a functional global to store the boolean, or skip the boolean all together and just have the functional global store the time. The global should have read and write funtionality, and when you use the write method it should update the time...

You mention events and events do not need to be local. You can create a user event and pass the reference to that event wherever you want. By putting it into a functional global e.g. you can have an event structure react to the event one place and have other parts of the code fire the event by using the reference from the global...not many limitations really.
0 Kudos
Message 2 of 8
(5,086 Views)
Hi, I don't udnerstand what you mean. If I want to store the new time value in a global, I need to detect my change of state of this bolean indicator. How can I mange it? Could you send me a small VI? Thanks,

Angel
0 Kudos
Message 3 of 8
(5,086 Views)
Check out the attached examples. One shows the use of a functional global to hold a time stamp of the latest value change along with the current value. The second one shows how to create a user event based on a refeence passed using a functional global and then react to value change events on it. In this case only one VI monitors such a user event, but you can have multiple...

To test the functional global example open the .llb file and run the main VI. In the example the global is read in a parallell loop to similify things, it can really be accessed globally; from any VI.

To test the event example open and run the generator.vi and then open the react.vi and run it...Now flip the boolean control in the generator
and see how the react
.vi fires value change events.
0 Kudos
Message 4 of 8
(5,086 Views)
Hi "Mads",
This is really a good help, now I hope I can solve the problem.
Thanks a lot!

Angel
0 Kudos
Message 5 of 8
(5,086 Views)
Hi again,
I've used your example to create a new one that can be useful for me but doesn't want to work properly. Can you have a look?
Thanks,

Angel
0 Kudos
Message 6 of 8
(5,086 Views)
It's mainly because you are reading value change events for the indicator, not the control. Value change events are only fired for changes given by a user. The indicator however is not updated by the GUI, but by programmatic input from the control. By replacing the reference with a reference to the control it will work. Or you can write the value to the indicator by using a Value (Signaling) property, that will trigger a change event for the indicator.

Note: You should not register the event inside the loop, do that only once - outside the loop.

If the boolean you are to monitor is not changed from the GUI you can as I mentioned above make it fire an event by setting the value using the value signalling property inst
ead of wiring the new value directly, but the property node has it's downsides so another option is to create a user event, put that reference in the global, and then run the generate user event function whenever the boolean changes.

I see you read the ms timer when the value changes. Why? If you want the time get the time, if you want the time since the last update you could use the ms timer, keep the previous value in a shift register and then calculate the difference, but the ms timer rolls over now and then so that can give false results...What is the purpose of the time and how often does the value change?

Attached is an exmaple that use a user event and the generate event function.
0 Kudos
Message 7 of 8
(5,086 Views)
Hi,
I explain you a little....This is the purpose of my application: I have a to adjust the tilt of a DVD. Therefore I use a servomotor and as feedback I acquire a voltage signal. As the motor-torque so high is, I cannot read the torquecurrent. This implies that I can never now if my regulated screw is so much regulated that can broken the system.I thougt that I could enter as parameters the maximum number of motor turns per direction and the speed (constant).Right now I only need to read the time that is going to know when the motor has achieved the maximum number of turns. Parallel I calculate if i've regulated so much and have to turn. This turn is stored in a global variable and this one makes to reset my ti
mer to start counting again. The idea is that if for example I give a maximum of 3 turns and in the second turn I have to turn in the other direction my counter resets, so that I can turn again a maximum of 3 turns. I hope this clarifies you everything a little.
I really appreciate your help. Thanks a lot!

Angel
0 Kudos
Message 8 of 8
(5,086 Views)