LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Performing a regulation with two loops in parallel

Hi,
I'm using two loops running in parallel to make the regulation of a voltage through the automatic control of a motor. In the first loop I read all the time which is the value of my actual voltage. There's also a subVI inside this loop that looks if the voltage is within the specified limits and if not, calculate in which direction and which is the optimal speed of the motor to continue regulating in order to achieve the desirable value. The actual voltage, the direction of the motor and the actual speed are stored in a global variable.
On the other side I have a loop with a machine state that at the beginning initializes my motor (I control it with serial communication) and it's reading the direction and speed glob
als and sending this information always to the motor until the first loop detect that our regulation has finished, and the machine state of the second loop stops the motor, and close the serial port.
In both loops I have a Wait(ms) command, 250ms in the first one (every voltage acquisition needs about 210ms) and 100ms in the second one (I just wrote this times without no idea, just to try them).
The thing is that this program is working most of the time perfect, BUT for some reason from time to time the subVI get hanged and I have to kill LV. I don't know if my problem comes from the timing in the loops or maybe because in some cases I'm writing and reading to one of the globals at the same time and I get a collapse. Could somebody help me? If I need some kind of semaphores or syncronization issues, could you send me an example? I'm using LabVIEW 7.0.
Thanks in advance,

Angel
0 Kudos
Message 1 of 5
(3,110 Views)
I would use a que in this instance. labview comes with plenty of examples, just goto the installation directory and then "examples".

how does the subvi operates, does it have while loop inside, does it use any visa / serial vis? if it has a while loop inside, make sure the exit condition always comes to true so. if it uses visa/serial vis or any daq vis, make sure you wire the timeout in case the data comes in too slow and the subvi does not wait forever.

if possible, posting your code or pictures of it can help people diagnose the problem.

-Joe
0 Kudos
Message 2 of 5
(3,110 Views)
Hi Joe,
thank you very much. In the meantime a friend has given me a great idea. I'm using now a global VI with a while loop that is one time exectuted and inside a true/case in which I read or write values and I've been running my application since a couple of hours with this improvements and it's working perfect. If I still have some problems I'll post a comment. Thanks a lot for your cooperation.

Angel
0 Kudos
Message 3 of 5
(3,110 Views)
The technique you are using is called a functional global variable, and it's generally better programming practice than using a normal global variable. The only potential problem I see is if you are concerned about loosing data. If you just want to send the current values to the motor then you are fine, but if you need to send a command to the motor every time the values are updated then you should consider using a queue. With the functional global you still have the possibility of changing the value in the first loop twice before the second loop ever sees it, or reading it twice in the second loop before the first has had a chance to update it. If this situation wouldn't be a problem then you should be just fine.

Regards,
Ryan K.
0 Kudos
Message 4 of 5
(3,110 Views)
Thanks Ryan, I'll take your advice into consideration for next projects. With the functional global variable the programm is working as it should.
Thanks again,

Angel
0 Kudos
Message 5 of 5
(3,110 Views)