LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

parallel loops and counter problems

Having a problem with a program which uses 7 parallel loops as follows

 

Loop 1 monitors a flow sensor which operates between 1.2 and 6Hz

Loop 2 Monitors all of the analogue inputs, pressures, temperatures etc

Loop 3 Controls the supply of air pressure via a motorised valve and feedback from pressure sensor in loop 2. Uses a PID routine

Loop 4 allows setting of a valve position in degrees. Uses counter output to operate a stepper motor and postion angle back via quadrature channels. Uses a PID routine

Loop 5 allows setting of a valve position in degrees. Uses counter output to operate a stepper motor and postion angle back via quadrature channels. Uses a PID routine.

Loop 6 Provides a low frequency pulse, 20Hz, that is monitored in hardware and acts as a 'heartbeat' if the computer crashes then hardware fails safe.

Loop 7 Event loop to monitor front panel controls

 

The problem is just with loop 4 and 5. When the two loops are operated on their own they function fine. However when they are in the main program Loop 4 allways works ok but loop 5 is random and using an oscilloscope the counter output signal is not present. The control lines- Digital for Direction and enable function ok its just that the counter does not provide an output. I have tried swapping channels on the counters but it has made no differance.

 

The original software that I wrote in Labview was about 3 years ago and it worked fine but the hardware was not National Instruments. This recent job has similar function but now using National instruments DAQ PCI 6601 and PCI 6053.

 

I was wondering if there is something odd happening because of the use of the various counter channels in different loops. 

 

Thanks

 

Jack

Labview Version 8.5
Labview Version 8.6
Labview Version 2014
0 Kudos
Message 1 of 15
(4,199 Views)

How are you getting the counter info to the two loops (4&5)? Is loop 4 running a lot faster than 5? If so, and depending on how you are getting the info out of the counter part there may be blocking going on, with 4 dominating the reads, causing 5 to have to wait for its turn, essentially a race condition. If so possibly having two seperate globals (functional, regular global, shared variable) would help.

 

 

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 2 of 15
(4,181 Views)

Hi Putnam

 

Each of the loops 4 and 5 have case statements that are identical to the ones detailed below.

 

Case 1

 

Sets up a counter channel on the 6601 to read quadrature A & B values back from a rotary encoder.

Sets up a further counter channel to output a 1800Hz waveform with 50% duty

Sets up a single line digital read channel to monitor a logic 0 stop signal (this signal is generated elsewhere in external electronics)

Sets up 2 digital output lines to control Direction and the Enable of a stepper motor driver (the motor that rotates the encoder shaft)

 

 

 Case 2

 

This is an idle case. To enter CASE 3 the operator has to request a new position angle, a change of value for the front panel control is detected and Case 3 is then entered. When the new angle is satisfied in Case 3 the program drops back into Case 2 in idle.

 

Case 3

 

Monitors and controls the DAQ lines as detailed in Case 1. There are no local or global variables used to read info into and out of these loop except for the Loop STOP function which is a property node generated from the STOP button in the event structure. This case also displays the angles on the user screen.

 

Case 4

 

This stops all DAQ items and ends the Loop. Activated when the Stop button is pressed.

 

 

I have tried the two loops on their own along with the 'heartbeat loop' and they seemed to work fine. When they were put back into the main program loop 5 worked a couple of times and then gave up. Everything else including loop 4 worked fine. I then tried enclosing all other blocks of code in case statements and turning those loops off until in the end I only had loop 5 running and it still worked intermittantly. The only other thing I have in the main program is a database read that is in a sequence structure and gets all of the calibration values for flow meter, pressure sensors and operator details at the begining.

 

After setting up loop 4 and 5 in the main program and monitoring the waveform output of the frequency generator counters only loop 4 generates an 1800Hz signal. Loop 5 is just low. The digital lines in Loop 5 work fine however as does its quadrature encoder counter.

 

I allways thought that once you had started a counter to generate a frequency then it would just 'free run' until task was stopped and all the counters on a DAQ board could be set up/used independantly, am I wrong?

 

Have gone around in circles with this and think there must be something really obvious that I am missing!

 

Thanks

 

Jack

Labview Version 8.5
Labview Version 8.6
Labview Version 2014
0 Kudos
Message 3 of 15
(4,165 Views)

Hi Jack,

 

I am thinking along the same lines as Putnam that you have a race condition. You may not have seen this issue with the non-NI hardware because the dll for third party hardware are often marked to run in the UI thread (which is single threaded).

 

The bulk of NI's stuff capable of running in multiple threads so this may be why you have trouble now using NI stuff.

 

A race condition is such a common problem in LabVIEW (due to multi-threading, if you are not used to working in this environment) that I wrote a Nugget on Action Engines to help people understand and use them.

 

In that Nugget I provided two examples to demonstrate Race conditions and show how AE can be used to avoid them.

 

This is bad.

 

 

 

While this is good.

 

 

I also talk about what is that makes AE's the way to go.

 

Please review that Nugget to see if that can help you.

 

Just trying to help,

 

Ben

 

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 15
(4,152 Views)

Hi Ben

 

Thanks for link and info, plenty of detail and I think it will take me a while to digest it all, but holiday next week so you have now given me something to do! Unsure if it relates to my problem as the loops do not use global or local variables for passing data.

 

In the meantime I have had a rehash of the channel allocations and using channel 0 and channel 1 for the freq output on loop 4 and 5, channels 2 and 3 now being used for the quadrature detection. All worked fine in the full program with this set up.

 

So swapped the channels back to channel 0 for freq output and channel 1 for quadrature detection on loop 4 and channel 2 for freq out and channel 3 for quadrature detection loop 5. Problem has come back and only loop 4 passes out a 1800Hz freq.

 

Tried all 4 channel outputs in max thinking the card was faulty but they all work fine.

 

Went back to just trying to activate channel 2 as frequency output on its own and it was found to generate a freq output most of the time but every now and then it would not start.

 

This is getting stranger by the minute.

 

Cheers

 

Jack

Labview Version 8.5
Labview Version 8.6
Labview Version 2014
0 Kudos
Message 5 of 15
(4,131 Views)

Can you just do the counter set up in one vi, for all needed counter operations, reading the data in Loops 4 and 5?

 

 

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 6 of 15
(4,127 Views)

jack1 wrote:

Hi Ben

 

...

 

This is getting stranger by the minute.

 

Cheers

 

Jack


 

That is one of the symptoms of a race condition. 

 

Race conditions are not limited to Globals locals or memory. They can also occur in hardware if the same widget is being told two different things. The light switch at the top and the bottom of the stairs could be an example of a race condition.

 

I really hope this helps more than it hurts.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 15
(4,126 Views)

It does seem like your are both right regarding race condition because further testing resulted in loop 4 counter output not working occasionally. A couple of times niether loop 4 or 5 counter outputs operated when the main program was started.

 

I have attached below a jpg image of the first case used to set up the counters and hardware.

 

 

Thanks

 

Jack

 

Labview Version 8.5
Labview Version 8.6
Labview Version 2014
0 Kudos
Message 8 of 15
(4,103 Views)

Hi Jack

 

After reviewing this problem I concur with the other members in this group that race conditions are occuring with loops 4 and 5.

 

Give an appropiate sequence to your VI's. Remember that LabVIEW works based on dataflow. Is there a chance you can post your code so I can identify where this problem is originating from? Many thanks.

 

 


Many thanks for using the NI forums and I look forward to your reply.

Kind regards

David

Applications Engineer
National Instruments UK
0 Kudos
Message 9 of 15
(4,065 Views)

Hi David

 

Sorry for delay in reply but been on holiday.

 

Have attached part of the code that is used in both loop 4 and 5. The code attached has been tried as it stands i.e just that vi and I get the same result where the counter output starts randomly on counter 3 or 4 depending upon which one I have selected. At the moment a temporary fix has been done where counter 1 and 2 provides the frequency output at 1800Hz to run the stepper motors and counter channels 3 and 4 are for the quadrature feedbacks respectivly.

 

Thanks Jack

Labview Version 8.5
Labview Version 8.6
Labview Version 2014
0 Kudos
Message 10 of 15
(4,006 Views)