LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing data between two parallel while loops

Solved!
Go to solution

Hello,

 

I am struggling to implement a control system. The physical system consists of the following:

 

  • A networked temperature datalogger (60 channels) sampling every 5 seconds (Agilent 34970)
  • An networked datalogger with Analog output driving triac heater controllers (ICPDAS I-8KE8)

 

The objective is to maintain the temperature setpoint of a test cell using a PID control loop.

 

My attempted solution (screenshot). I can run the loops (bottom is temperature acquisition and top is analog output) and they behave as expected. Note that I have heavily scrubbed the vi to simplify what's going on - I know the PID is not connected...etc. Both structure are very closely based on the reference Vi's from the manufacturers. 

Untitled.png

 

It is not possible to consolidate both loops as the Agilent datalogger cannot scan faster than every 5 seconds. Speeding it up will cause it to begin re scanning and won't complete the scan of the rest of the card. The analog output must be outputting at 1 Hz (it's controlling other devices from the same card). Therefore I want to be able to move the "SAMPLE DATA" temperature to the PID input.   

 

Questions:

 

1. How can I pass the temperature value between the two structures

2. Alternatively, how can I pass the PID output value from one loop to the other (assuming I put it in the 5 second loop).

3. Is this the best approach to achieve this? Would it be possible to eliminate the delay for the temperature datalogger, consolidate the loops and have the temperature scan driven by some sort of elapsed time conditional structure? Basically the loop is running much faster (1 Hz or 10 Hz) but only triggering the temperature scan once every 5 seconds. 

4. As the PID feedback is only 0.2 Hz, is there any advantage to running the output at 1 Hz?

 

I would appreciate any help.

 

Regards,

 

Barry

 

0 Kudos
Message 1 of 9
(8,475 Views)
Solution
Accepted by topic author Barry675

@Barry675 wrote:

1. How can I pass the temperature value between the two structures

2. Alternatively, how can I pass the PID output value from one loop to the other (assuming I put it in the 5 second loop).


Use a Local Variable or a Global Variable.  You only care about the latest data, so either of those will work just fine.

 


@Barry675 wrote:
3. Is this the best approach to achieve this? Would it be possible to eliminate the delay for the temperature datalogger, consolidate the loops and have the temperature scan driven by some sort of elapsed time conditional structure? Basically the loop is running much faster (1 Hz or 10 Hz) but only triggering the temperature scan once every 5 seconds.

Keep them in separate loops.  It will make reading code a lot easier and you allow for more parallelism.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 9
(8,467 Views)

crossrulz,

 

This has done the trick - I knew it would be something straightforward. Thanks for the tip, I didn't know about using local variables. This will help clean up a lot of other VIs too.

 

Regards,

 

Barry

0 Kudos
Message 3 of 9
(8,452 Views)

My responses, in order.

 

1.  A simple local variable would be sufficient here.  Write updated values to it in your Temp query loop every 5 seconds, let your control loop read from it as it iterates at its own pace.  I'd add sequencing to make sure I didn't read the local variable value *before* the 1000 msec wait and then use it for PID and output *after*.  Be sure you read the local at the last moment before using it.

 

2. Same answer.  Local variable.  Both raw value and PID output only change once every 5 sec, you probably only need to send one of them from loop to loop.

 

3. I prefer the basic outline you already did.  The two processes are governed by different timing needs, it's cleaner to keep them in parallel loops.

 

4. You've already said the control needs to run every 1 second for the sake of other devices.   It won't hurt to output the same PID output (based on the same temperature sample value) 5 times during those 5 seconds.  Neither will it help.   You're free to choose whichever fits your software architecture better.    No need to change from what you're doing.

 

 

-Kevin P

 

 

P.S.  Oops, started a reply and didn't recheck to see if anyone had already replied before I came back and finished.  On the plus side, we agree so that should be good confirmation for the OP.

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 4 of 9
(8,448 Views)

Just some friendly advice that was not asked for...

 

Please remove that stacked sequence structure! It's almost certainly completely redundant. We can't see what's in frame 0, but the frame 1 VI is synchronized by those inputs, no need to obfuscate things in a stacked frame. It's preventing overview, and forces redundant clicking to see what's happening.

 

The flat sequence structure is also redundant, or at least easy to avoid. That function global probably has errors in and out. Use those to synchronize VI execution. Better jet... You already are programming OO, only you're using a cluster as an object, not a class. Put each function in a method of a class, and see your code get clean. You can even convert that cluster to class, so it's data ends up in a class's private data. Bonuses: You get automatic execution synchronization through the class wire, you can have two serial devices (or an array of them), you can add a simulation child, you'll learn a bit about proper OO.

0 Kudos
Message 5 of 9
(8,442 Views)

 

 

 

 

Download All
0 Kudos
Message 6 of 9
(8,435 Views)

The dll is missing, making it really annoying to do. Also, the init and close are missing.

0 Kudos
Message 7 of 9
(8,406 Views)

Please see the full folder attached

0 Kudos
Message 8 of 9
(8,402 Views)

The DCON driver is finished, but that zip adds another API handling the UART. It'll have to wait to next week, off for the weekend.

 

Note that everything I'll make will be 100% untested. There will be mistakes.

0 Kudos
Message 9 of 9
(8,390 Views)