LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array and loop

i have some questions related to this VI.
in total cycles variable/control when i write one, it runs once cycle that means all 3 banks/elements and then stop.when i write two,it will execute for two complete times and when i write 3,it will execute 3 complete times and so on so forth. but when i write 0,it must not execute not at all.why even when i write 0,it executes atleast 1 time and then stop?

in TimeTakenAry when i set 00:00:00 to all three banks.it must not execute at all.why i see some signal on the graph and why i see some execution?

in the inside while loop i am slowing down the while loop by using the delay of 1000. if i dont use the delay, it will execute very fast and if one element of TimeTakenAry i set to 1 hour.it will not run upto 1 hour and like i said, it finishes very fast.why?what is not correct there?
if i set time 1 hour and i dont use any delay.it must run upto 1hour.why it executes so fast and finishes early? moreover one while loop takes how much time to complete one loop.does it take 1000ms to complete one loop?

i would be thankful to you for your help.
0 Kudos
Message 1 of 11
(3,500 Views)

@hood1 wrote:
in total cycles variable/control when i write one, it runs once cycle that means all 3 banks/elements and then stop.when i write two,it will execute for two complete times and when i write 3,it will execute 3 complete times and so on so forth. but when i write 0,it must not execute not at all.why even when i write 0,it executes atleast 1 time and then stop?


A while loop will always execute at least once. If you want to skip it under certain conditions, place it inside a case structure.


@hood1 wrote:
in TimeTakenAry when i set 00:00:00 to all three banks.it must not execute at all.why i see some signal on the graph and why i see some execution?


Same answer as above.


@hood1 wrote:
in the inside while loop i am slowing down the while loop by using the delay of 1000. if i dont use the delay, it will execute very fast and if one element of TimeTakenAry i set to 1 hour.it will not run upto 1 hour and like i said, it finishes very fast.why?what is not correct there?
if i set time 1 hour and i dont use any delay.it must run upto 1hour.why it executes so fast and finishes early? moreover one while loop takes how much time to complete one loop.does it take 1000ms to complete one loop?


Your "simulate signal" is set to "run as fast as possible", double click it and select "simulate acquisition timing". Now remove your 1000ms delay, it has no use.

You should also learn how to use shift registers and then eliminate all your local variables. They are creating a mess. For example, there is no guarantee that the code fragment on top that calculates "Cyls2DoAry" even executes before its local variable is used inside the loop. Also, if you use a shift register initialized to zero, you don't need that "initialize to defaults" node.

Attached is a slightly cleaned up version that incorporates some of the suggestions. Modify as needed. Please ask if there are questions. 🙂

(If you set totalcycles=0, there will still be a few points on the upper graph. This seems like a LabVIEW bug and should not happen because its case is bypassed. Can anyone explain this?)
Message 2 of 11
(3,494 Views)
Hello
Thanks for your reply. i used the case structure and it is working fine.i still have some questions.
i will definitely learn how to replace variables to shift registers. now with your example i cannot
update the array elements(i call them BANK)in real time. so with my example, i can update array elemnts
in real time. like when Freq, amplitude and time is in BANK one, and i am generating signal.in real time
if i change the frequency, it will immediately update the signal. i can see it on indicators but also on
graph i can monitor the change. why can i not update the signal inside the array elemnt in real time in
your proposal where we use shift registers.
i am sending my new VI. i modified it as you said with case structure. but i still used local varibales,
because i still have to learn about registers. now in my current VI, i still have some problem. i moved the
arrays outside the loop. actually i would like to set the number of elements. i would like to start the the
program from the labview menu.but then i can select the number of array elemnts( i call them number of Banks).

when i select the number of BANKS/Array elements to 2.then it must show 2 elements.where i can change the values
in frequency or amplitude and time. afterwards when i give all input values, i start the program execution. it will
start execution and it should finish execution when BANK 2/Element 2 reached and if next cycle is also needed, goto
next cycle. begin the execution again from BANK 1. and all this values i can be change in real time. i am doing all
this in my application. but the problem is that when i set Number of Banks to 2. it continues to BANK 3 and after
wards move to BANK 1 again. why is it like this? why not immediately after taking values from BANK 2it moves to BANK 1
for the next cycle?
Thanks for your help
Regards
0 Kudos
Message 3 of 11
(3,467 Views)
I intentionally took the controls out of the inner loop because it seems very dangerous and unpredictable to change them during a run. What if you change an entry that has already been processed? It will have no effect! What if you add an element to AmpAry but the code reads it before you have a chance to add a corrsponding entry to FreqAry?

If you really want to go that route, simply place the index arrays back inside the inner loop in my example. You still don't need any of the local variables.

Always think "data flow". Use local variable sparingly and only if really needed. Have a look at your new code fragment shown in the picture, there is NO need for locals and I show an alternative inside the red glow.

You Banks control only determines how many elements of the array is shown. It does NOT determine the size of the array, which is still size=3 even if you only display 2 elements. you must truncate/expand all relevant arrays to the given number of banks. You can use "reshape array" for this. Alternatively, you could wire the number of banks to the place where you currently read the local varable "AryBlocksNo".
0 Kudos
Message 4 of 11
(3,456 Views)
Hello
Thanks for your reply. well i would like to change the array element values/BANK values on the fly or in real time. you said that it could be dangerous. so is there any safe method to change the values of the elements of array on the fly or in real time??
the second thing is that i change like you said. for control arrays freqARY, amplARY, Timetaken ARY it works fine, but Cyls2DoAry (indicator) does not display and show the corresponding freqARY, amplARY, Timetaken ARY. why an indicator can not be displayed and showed automatically. like we have 3 BANKS for control arrays. why not corresponding indicators BANKS appear for Cyls2DoAry.

thanks
Regards
0 Kudos
Message 5 of 11
(3,442 Views)
here i did the same with reshape array. it gives correct results. could you tell me please did i used the reshape array function correctly?

thanks
Regards
0 Kudos
Message 6 of 11
(3,438 Views)
Hello
Thanks for your mail. Now it seems better. Now i can display Indicators array also based on corresponding control Bank array. in addition to this i can display also LABEL. But still i have a problem. Elapsed time is not working properly. for example when i set running time 5 minutes. if after one minute i break and resume after 2 minutes.it has to resume where it was paused. but it resumes from the current time. i thought this is due to my local variables usage. but also in your example where you use shift registers, this elapsed time after using break, resume button gives strange results. why is it like this please explain?

i am sending my modified example.
Regards
0 Kudos
Message 7 of 11
(3,423 Views)
Hello

There is one more problem.if i replace the simulation VI with Basic function generator VI,the elapsed time execute very fast and finish.why all signal generators VI does not have the same response, when they are generating signal.is it a bug or something different.please explain.

Thanks
Regards
0 Kudos
Message 8 of 11
(3,410 Views)
Hello,

the Express-VI for signal-generation creats a signal, too, if you are breaking your VI with your "BREAK-Button".
I have modified your VI, so that you can break your signal. After this break you get the remaining time of one "bank". The Elapsed-Time works now. If you want to stop really after 10sec. within the break you have to add the break-time.

regards

Markus Weigl
NI Germany
Message 9 of 11
(3,386 Views)
Hello,

Thanks for your reply. this elapsed time is working. but it is also working not only for first BANK, but also for the sucessive banks as well.
sorry i dont understand what do you mean by 'If you want to stop really after 10sec. within the break you have to add the break-time'. i even tried after 10 seconds to break and resume and i also tried to stop after 10 seconds. it is working without any modification. can you please explain what do you meant by this.what break time i have too add and in which break loop?
my other question is if i send this generated signal through a board (E-series board) AT-MIO-16XE-50 to the osilloscope.in which case structure i have to use AO output functions?.in the first case or in the second case? will it work the same there too? can i send the sine signal to the osilloscope?
the number of cycles i will see on the osilloscope will be the same like i see on my user interface in Cyls2DoAry.please explain me these questions.
once i again many thanks for your help.

Regards
0 Kudos
Message 10 of 11
(3,372 Views)