# Timed loop with array dimension control

Hello,
I have imported an excel to an array and im trying to use a timed loop to run the values of the array on a timed interval. One of my problems is that the array is 2D and i cant use its length to stop the loop. I want to use witch value of the array in the loop in each iteration of the loop and i want the loop o stop when the counter equals the length of the array. Can someone help me plz here is the labview.

It is really unclear what your question is.  Could you clarify?
If you are struggling with why you have a broken wire it is because you are sending an array to the stop of the loop.  When you use the array size function on a 2D array it returns a 1D array with the size of each dimension.  When you then use the greater than function it returns a 1D array of Booleans.  It compares each element of the array size to the current count of the iteration terminal.
To use this to stop your loop you need to reduce it to a single element some way before you send it to the stop control of the loop.  You could apply an "and" or "or" function to the out put of the greater than or pull out a single index out of the single greater than array.
In the image logical AND, logical OR, or element could be used to stop the loop.  You just need to choose one that gives you the behavior you need.
Lukin
Certified LabVIEW Developer

### Similar Messages

• Array dimensions when converting from a cluster

Hello,
I am a beginner Labview programmer. Right now I am working on a VI
that converts a portion of cluster data to an array of tables. The
cluster is loop tunneled into a for loop then unbundled. I then build
it into a 2D array. When I hand the data back out of the for loop the
array dimensions are the same size. i.e. If the 2D arrays were 2x7 and
2x6 going in then going out I have both as 2x7's. This happens right
at the exiting loop tunnel (I suppose when it initializes the 3D
array). This places zeros in the last row of my 2x6 array. Can anyone
suggest a fix. Thanks a bunch.
Peter.

Hi, Peter:
I think you want to have an array of different row sizes. I think it's impossible in LabView. At least using only arrays and without clusters.
And as all rows have the same number of elements, undefined elements get default value. In case of numerics, zeros.
You could create an array of cluster elements, and each element be an array 2D. Then each element can be an array of different sizes.
But that's just what you had at start.
Aitortxo.
Aitortxo.

• While loop inside a timed loop

Hi everybody!
I'm using:
- LV 7.1 + RealTime;
- compactFieldpoint;
I've noticed a strange behaviour, when I put a while loop inside a timed loop.  Let's fix timed loop with these settings:
- 1 KHz clock
- 1 ms period (yes, I know it's short....)
- offset 0 ms
- Phase 0
- Discard missed period (ON) and MAintain original Phase (ON);
- Timeout: -1.
If inside this loo, I put a traditional while loop, waiting (say) for an event to occur, and if this event does not arrive, my cFP-2020 hangs! I mean, it becomes unreachable for the debugger, and, more, if I run a ping to it's address, after some cycles it becomes unreachable also from ping!
Clearly, this code statement lock the fieldPoint, because if I remove the inner while loop all works.
I know that with 1 ms period, timed loop always finishes late, but I set to discard missed period and timeout to -1.
It seems to me that sometimes Timed Loop add heavi overhead to programs, I'm turning to all while loop based tasks, even if my application has to be real-time!
Advices welcomed! Have a nice day!
graziano
Solved!
Go to Solution.

I think the issue here is that putting your while loop inside a Timed Loop increases the priority for that task. Timed Loops can have dynamic priorities set over eachother, but they all run between Above Normal and Time Critical priority. My guess is that the debugger and built-in TCP functions run at Above Normal priority or less. This means your cFP isn't hanging, it's doing what it thinks is best. It's trying to finish this task before handling any lower-priority tasks.
The suggestion to put a Wait function in your loop is an OK one. Keep in mind that you can actually set your wait time to zero instead of one and get the same positive benefit of handling other tasks. I would also suggest that you might look into waiting for this event in a lower priority (non-Timed) loop, and then transmit the appropriate data to your Timed Loop using an RT-FIFO or something. That might give you better handling. Just a thought....
Jarrod S.
National Instruments

• Timed loop in a subvi, one or the other runs but not both.

I have a vi with two sub vis. Each sub vi contains a timed loop that updates a global variable. In the top level vi I read from each global and display its content. When I run the top level vi I see only one global counting but not both. If I start and stop the top level vi the sub vis take turns counting but they never both count. If I replace the timed loop with a while loop in each subvi then both count. If I move the two timed loops from their respective sub vis and place them in the top level vi then both globals show counting. Can any body explain what is going on.
I'm using Labview 2010 SP1.
Attachments:
Test Of Timed Loop.zip ‏72 KB

Never Mind!
When I cloned the subvi I forgot to change the structure name of the timed loop. Placing an error indicator inside the subvi disclosed the error -808 (Error -808 occurred at an unidentified location. Possible reason(s):LabVIEW:  The given name is already being used by the following timed structure.).

• Unrecoverable Error w/ Timed Loop

When I use a timed loop I get an "Unrecoverable Error" (status light on FP-20xx blinks four times) after compile and run - although not immediately. When I replace the timed loops with regular while loops everything is o.k.
TommyH

Hi TommyH,
Thanks for the information. I understand that all this stuff can be a little overwhelming. That's OK. We'll get through it.
Sounds like this is a case of the code not being able to execute within the allowed amount of time. So, in this case I would suggest not using the timed loop because the code will not be able to execute within 1ms. I would suggest using the regular while loop and using a wait until next millisecond multiple timer. You will need to experiment with the code to determine how long to wait. Give this a try and let me know how it goes.
Best Regards,
Brooks W.
National Instruments

• LabVIEW crashes in timed loops

Hi,
I'm running LabVIEW 8 on a
Pentium D, 2 GB RAM, Windows XP sp2 with an ETS target Pentium 4, 256
MB RAM. I have two timed loops in a sequence, so they do not execute at
the same time. A similar sequence is on the target allowing me to make
a state machine between both computers.
The loops on the host
simply update the GUI for the user have a large period of 45-ms. This
makes the CPU usage virtually zero. Also, task manager tells me that
LabVIEW on the host only uses 200 MB of memory, so I know that the
computer is not running out of memory.
When I run the multiple
VIs, the host will randomly crash. It works about 9 times out of 10
with no crashes. Windows will tell me that it (is sorry and) has to
close LabVIEW on the host. The target side continues to run like
nothing happened. When I click on the link requesting details, I get
this information from Dr. Watson:
AppName: labview.exe
AppVer: 8.0.0.4005
ModName: lvalarms.dll
ModVer:8.0.0.6
Offset: 00001df4
I
have narrowed it down and I know that it will only crash in the two GUI
loops. Does anyone have any ideas about how to approach this problem?
-J

Recently, I have had similar problems with timed loops (LV8.0.1/W XP). According to NI's answer, this is linked to hyperthreading. Unfortunately, until now, my question if this incompatibility is a bug or not remains unanswered. Because my application is critical, I have replaced all the timed loops with while loops even if the crash didn't appear during a short test with disabled hyperthreading.
Here is an extract of the exchange with JR Andrews from NI :
04/04/06
The preliminary investigation of the issue indicated that it may be due to hyperthreading (or having dual processors) and that disabling hyperthreading resolved the issue as a potential workaround. If you have the time and ability, I would be interested to know if you were seeing the issue on a hyperthreaded machine and if disabling hyperthreading does in fact resolve the issue for you. I can then pass that information on to the developer to assist them in fixing the issue.
Regards,
JR
JR Andrews | LabVIEW Real-Time & PDA Product Support Engineer | 512-683-2820
05/04/06
Even though your computers only have 1 processor, that processor may be using "Hyperthreading" to make it appear to the OS that there are 2 processors. You can check this by looking that Performance tab in the Windows Task manager or at the number of processors shown in the Device Manager. I've attached a screen shot of my system which is a single P4 processor which is hyperthreaded. Disabling the LV option for "Run with Multiple Thread" would probably not have any effect because to Timed Loops are always their own thread and that setting only applies to non-timed loop LabVIEW code. So I wanted to clarify that double check that your machine indeed does not have hyperthreading. To disable hyperthreading, you can go into the BIOS and you should be able to disable it. You can always go back and enable it again too.

• Write to XML File crashes when multiple Timed Loops present

Hello All,
It took me forever to track this bug down.
In this project we can edit operating parameters on the Host and send them down to an RT program in a cRIO-9025. The data is converted to XML and stored on the cRIO's disk.
Occasionally, the RT program would lock up and had to be rebooted.
It turns out that if you use Timed Loops , then a Write to XML File (or presumably any file write) will not return.
Attached is an example. This has 5 loops to make it crash faster, but it will eventually crash with only 2.
Paul J
Attachments:
XML Write test.vi ‏93 KB

Hello Chris,
I know that Write to XML File fails because I put in debug code in my actual program, a flat sequence which updated an indicator, and after the crash, the indicator had not updated.
Yes, I know that it replaces the file. It's a configuration file, not data gathering. This is just an example of the bug.
FYI,
I increased the period for the loop with the file save to 500msecs and it still crashed.
I then decreased it to 50 msecs, and replaced all of the other Timed loops with While loops and it does not crash, even though the file save takes much longer than 50 msecs, average ~150msecs.
I replaced the loop with the file save with a While loop while leaving ﻿the others as Timed loops and it does not crash.
So the bug is systemic and related to a file save in a Timed Loop when there are other Timed Loops.
I'm not looking for a solution, I'm only reporting a bug in Labview. The solution is not to use Timed Loops, especially, as you point out, when there is file saving. It cost me several days of dicking around to figure it out. Maybe someone can save some time if they find this.
Paul J

• Who know the difference between the two Timed Loop structures in NI's examples named PAC Simulation.vi?

My LabVIEW version is LabVIEW 8.0.
When I look up the help document about Timed Loop, I find two examples about Timed Loop with the same file name and different file path.
One is "labview\examples\general\plat-timedloopframes.llb\PAC Simulation.vi",
and the other is "labview\examples\general\timedloop.llb\PAC Simulation.vi".
The function of these two examples is almost the same. But they display different results when running. I debug them and find that the value of Actual Start [f] of these two timed loop is different. Its value is constand in one vi and increasing in another vi. But the configuration of these two timed loops is the same.
Can anyone tell me the diffrence between these two timed loops?
Thanks!

After I posted this, I realized there was one more "Time" clock, namely the Time node on the Event structure.  How is this clock (which I will call ET, for Event Time) related to the Global Start Time (or GST) and the TimeStamp (TS)?
ET represents time in milliseconds, using a U32.  The largest value that can be represented is roughly 4 billion, but there are more than 30 billion milliseconds per year.  Hence this "clock" cannot directly keep the same time as the GST or TS.
However, on the PC, if you multiply the ET value by a million (thereby converting the time to nanoseconds) and compare this value to GST, you'll see they are basically the same.  Thus, on the PC, ET and GST are "in sync", but not in sync with TS.
On a real-time PXI system, we already established that TS and GST are "in sync" -- what about ET?  Curiously, this does not seem to be synchronized with anything.
A Word to the Wise -- when I originally added the Event structure, I synchronized it with the Timed Loop using a Value(Signalling) property node, which worked fine on the PC, but failed to fire on the PXI.  I'd forgotten that you can't use this trick on real-time systems, as they have no Front Panel objects, hence the implementation using Dynamic Events.
Attachments:
TS GST ET VI.png ‏16 KB

• Timing Loop won't Execute

I think this is a labVIEW bug, but I'm looking for a work around or a 'gotcha'.
I was attempting to create a timing loop for the purposes of sychronizing two sections of code within a VI.  The timing loops would not execute and so as part of the debugging process I created a simple empty timing loop with a 'stop button' in it.  Put a probe on the wire between the stop button and the stop terminal of the timing loop and executed my VI.  The Timing loop never executed.
I then created a new VI to continue debugging the timing loop: I created a new VI and a new timing loop with only a stop button, placed the probe in the same place, (between the button and the stop terminal) and ran the 'untitled vi'.  In the new vi the timing loop ran as intended.
All I can think is that there is some VI property in my rather complicated VI that prohibits timing loops but is not producing an error or warning.  I did check the VI properties and though they are not default there isn't anything that should be interfering with running a timing loop (e.g. critical execution).
I'm looking for solutions and work arounds.
Using LabVIEW 2014 SP1 32 bit.
-Regards
eximo
UofL Bioengineering M.S.
Neuronetrix
"I had rather be right than be president" -Henry Clay
Attachments:
timing loop.PNG ‏9 KB

The attached image of the first post is the disfunctional version, Attached to this is a segment of the VI with the example disfuctional timing loop at the bottom right.
-Regards
eximo
UofL Bioengineering M.S.
Neuronetrix
"I had rather be right than be president" -Henry Clay
Attachments:
Timing loop not working.PNG ‏68 KB

• Timed loop works not well

Hi,
how can I get a digital signal shorter than 25 microseconds? I am using
a RT-system, and I am using a timed loop with the internal clock, but I
can't get it faster than 25 microsecs.
Thanks
Tim

Tim,
Sorry I don't know much about RT but you may find a better response to your questions if you post in the real time forum.
http://forums.ni.com/ni/board?board.id=280
Brian

• Unable to click on buttons during timed loop .

Hi !
I have a timed loop with a cadence set by user . And when the loop is running, I can not push any button of my GUI to stop this....
I have to wait until error or I stop the run.
I can't put the diagram it's too big and I think I haven't the right but do you have some ideas ?
Ask me for more details .
Thanks
Solved!
Go to Solution.

bejard wrote:  The Timed loop is just in an event structure and I set 10 ms or 100 ms .
The program is running correctly (with this Timed loop of 10ms/100 ms) as the beginning but I still can't push any button or change tabs during the loop .
You should not have long processes inside of an event case.  What is supposed to stop your timed loop?
I think you have the "Lock front panel until event case completes" option turned on.  This will not allow you to press anything until everything in  that event case (including the timed loop) completes.
In my experience, using a timed loop in a Windows system is a complete waste and often adds more overhead and issues.  Instead, I really think you need to change over to use a State Machine.  When the button is pressed, you just tell your state machine to go into the state the runs some of the code inside of your timed loop.  You can use the state with the event structure to time your loop.  So you can go back and forth from your event structure state to your processing loop.  Just set the timeout on the event structure to whatever loop rate you actually want.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines

• Using timer/counter with PCI-6221/USB-6210 to control timed-loop VI

Dear all,
I need to ask about two devices and one of their functionalities, PCI-6221 and USB-6210. For our NI-based system, we need to control some timings in a Timed-Loop vi, for that currently we are using PCI-6221 and we give external TTL signal (at 1 kHz) to it,
recenntly we need to make some changes and for that we found USB 6210 DAQ to be more suitable, but we need to clear ourselves on some specific things.
Can the counter/timers functions available in the either PCI 6221 or USB 6210 can be used to control the Timed-loop VI by giving external clock or by using their own internal clock source?
Although we are using external clock with the PCI 6221 but we want to know about the usage of their internal clock, also are controlling timed-loop also possible for USB-6210
Also... What if we use the RTOS, are they still able to control the timed-loop VI  without giving any 'EXTERNAL CLOCK' and using the internal clock sources of the DAQs
Bests,
RaJaf
Solved!
Go to Solution.

Ben,
I having read previous email which I send earlier with general overview, we discussed in more detail within our team and I am giviing the specific answers.
1.    Using Internal hardware clock of PCI-6221 would enable us get rid of external clock, but how to divert the internal hardware clock to the current settings. Any idea  (can you provide us with some reference manul for otherwise). I mean is there some flag-bit etc. or VI
2.       Is it also meant that with the installation of RTOS the timed-loop can directly get the timing source from the internal hardware clock PCI-6221? --- How???
3.       In order to make desktop to work as RT system, what is the hardware (motherboard, processor, etc..) requirement? What are the LabVIEW modules (specific name) that needed to be installed? Our platform is LabVIEW 8.6. (Currently we have windows-7 with i7 core processor)
What kind of application are you intending for this system? ---- high-speed laser scanning system.
Are you most concerned about accuracy, speed, or responsiveness? To control the laser mirror scanner to move at 1 kHz or 2 kHz speed. On the other hands, using PCI-5105 (128 MB memory) as a DAQ for real-time/on-the-fly data processing.
Bests,
RAJAF

• Integrator control with timed loop

Hi all, when dealing with discrete time control like the poleplacement method, the sampletime shouldn't necessarily be
as short as possible like in "analog" PID-control.
I want to be able to set the time of how often I am sensing the input and therefore I am using a timed loop.
Something is missing in my file because it won't work.
The propertynode DigNum is not inserted by me, but by the png-software. I have a local variable there refering to the period dt.
Kindest regards,
Lasse
Attachments:
Integrator control with Timed Loop.vi ‏118 KB

Hi Lasse,
"Something is missing in my file because it won't work."
Yes, the error description is missing. What is wrong? What exactly doesn't work?
- Instead of using locals you could use a wire or the block in the upper left of the TimedWhileLoop to get dt from it...
- Does the loop spin as fast as you want it to spin or do the ExpressVIs slow down the execution?
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome

• Timed Loop timing source - Control Loop From Task is too slow

I'm trying to make a Timed Loop run at a period of 2 ms, with an analog input task running at 50 kHz as timing source. The input analog signal is scaled and fed into a synchronised analog output task on the same multifunction DAQ board. Using the built-in 1 kHz or 1 MHz clock as timing source for the Timed Loop works great, except for a slight time lag between the loop and my AI/AO tasks which over time becomes unacceptable because my task will be running for up to an hour. However, when I use the DAQmx Create Timing Source: Control Loop From Task vi to create a timing source, everything slows down and the fastest loop time I can get is around 20 ms. Any suggestions to get around this would be highly appreciated!
System: LabVIEW RT 8.0 with DAQmx 8.0 running on an NI PXI-8186; NI PXI-6251 used for analog input.

You're welcome!
You can build an array, and if your data is not hugh (100's of MB) this may be the easiest solution. However, we aways suggest implementing the Producer/Consumer Architecture. Keep the PID in the Producer loop, but move the File IO to the Consumer. Also, it  appears that your instrument uses some form of serial communication, so that could cause lags in your system....
What is your application about in general, what performance are you hoping for, etc?
Joshua B.
National Instruments
NI Services
NI Support Resources
NI Training Resources

• Why i get different value when subtractin​g two elements of different arrays then the actual value in a timed loop

Hi Everyone
I have a probem in substracting the two elements of two different  1-D arrays. The problem is, I am taking out data from a CCD camera which gives me data in form of 2-D array. So i select 1-D array out of it. Now this CCD output is in a timed loop, hence i am getting data in each loop. I select a perticular array output of the CCD and this is then passed to shift register and in all the loops later on, one of the element of the output array of the CCD is substracted from the same indexed element of the selected array. For reference i have pasted the snap shot of the block diagram. In this snap shot you see three probes. The value at the prob 1 is 232, at probe 2 is 255 and at 3 is 4294967273, where as actually i sould have a value of -23 since i am substacting prob 1 and probe 2 values. Since the value of probe 2 will always remain at 255 as i have fixed it by choosing an array form CCD and i checked the value of probe 1 which never goes above 255 so why do i get this false value here.