LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Loop Timing

Let me just say that I am a beginner with programming and I've had no training with LabView so if my question is a bit "obvious" please forgive me.  Anyway, I wrote a program that essentially performs three functions:
1.  Displays the pressure reading from a transducer.
2.  Does a Boolean comparison of the transducer input and a user defined variable.
3.  Depending on the outcome of the Boolean expression the pressure data is logged every 10 seconds or every 10 milliseconds.
 
I'm having trouble getting the timing of this events to occur without effecting the other.  I need to be able to control each timing sequence independent of the others.  Any suggestions?
LabVIEW 2016 - Windows 7

CLAD
0 Kudos
Message 1 of 15
(5,014 Views)
MeCoOp,

From the description of your issue, it sounds like you may need to use two different loops to get the timing correct.  I might suggest running one loop that reads the FieldPoint data (maybe using the single polymorphic FieldPoint Read VI), displays it, and makes the necessary comparison.  The second loop could be the variable speed loop that writes your data to file.  If you create local variables for your data, comparison, and stop buttons you can link the two loops.  Hope this information helps.

Andy F.
-----------------------------------------------------------------
National Instruments
0 Kudos
Message 2 of 15
(4,989 Views)
What exactly do you mean by link the two loops together?  I tried implementing your suggestion as I understood it but I could only get one loop to execute.  Thanks.
LabVIEW 2016 - Windows 7

CLAD
0 Kudos
Message 3 of 15
(4,967 Views)
I can understand how that would be a bit confusing.  My apologies.  To do what I was suggesting, you need to break the data flow of LabVIEW.   By creating the local variables you can share the data between the loops without having them connected, allowing them to run in parallel (note: this is not truly parallel unless you are running multiple processors, but close).  I might recommend using Highlight Execution (the lightbulb on the block diagram) to see what is going on with your code.
-----------------------------------------------------------------
National Instruments
Message 4 of 15
(4,940 Views)

Ahhh yes, local variables, the things you miss when you had no real training!!  Your suggestions worked perfectly.  Thanks a bunch.

Bobby

LabVIEW 2016 - Windows 7

CLAD
0 Kudos
Message 5 of 15
(4,918 Views)
First of all, I would advise against using local variables.  While they are certainly the "easy" way, when you get into more complex code it's also "easy" to create race conditions.  Functional globals (also called LabVIEW 2 style globals) are a much better alternative to standard local and global variables.  You can find much information on functional globals on this forum.
 
I would also like to point out that LabVIEW block diagrams are much easier to follow when they are not spread out over three screens.  Your code could easily be compacted to fit on a single screen.
 
Finally, I'm not sure that you have to use two loops in your case.  As I understand it you have two times, the acquisition time and the record time.  You want to show the data on screen at the acquisition rate and store the data to file at the storage rate.  You should set the loop up to run at the acquisition timing rate.  At the start of acquisition initialize a shift register with a ms time.  On each iteration compare this with the current ms time.  If the elapsed time has been reached, depending upon your record rate, record the data and reset the time at the shift register.  Otherwise continue to the next loop.
0 Kudos
Message 6 of 15
(4,907 Views)

I don't think you need seperate loops and local variables.

  1. Run your FP acq always at 10ms. (what if 100ms later a condition exists to log every 10ms? You would not want to wait 10 seconds!)
  2. Place the file write only in the TRUE case and also add a tick count to the TRUE case that you feed into a shift register.
  3. At the next iteration, see if either: (1) The triggger condition is met OR (2) 10 seconds have elapsed Get a tick count and subtract the shift register value, see if it is >10000.
  4. If the logical OR is TRUE, switch to the case that reset the tick count and appends to the log file.
  5. If the logical OR is FALSE, execute an empty case that simply wires the old tick count across.
Let me know if this is clear! 🙂

Message Edited by altenbach on 08-09-2005 08:37 AM

0 Kudos
Message 7 of 15
(4,905 Views)
Ok, I think I already did what you suggested, although I'm sure my version is a lot more complicated than it should be.
LabVIEW 2016 - Windows 7

CLAD
0 Kudos
Message 8 of 15
(4,900 Views)
Your code will not work. There is no way that the various loops can be stopped via a wire coming from the outside. And, Yes, it is probably a bit too complicated with all these local variables. 😉
0 Kudos
Message 9 of 15
(4,895 Views)
Hmm, I tested it out with the transducer and it seemed to work fine.  I just checked to see if it printed the data at the correct rate depending on the cases.
LabVIEW 2016 - Windows 7

CLAD
0 Kudos
Message 10 of 15
(4,891 Views)