LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I want to set the code's running time to 2 sec/ 3 sec/ 5 sec

Solved!
Go to solution

Hi,

 

Thanks for your reply. Actually, I placed elapsed time (orange LINE counter) so I could note the code run time as I set the input sampling rate to 100 Hz per second. Due to that, I placed it, and the blue counter shows a number of iterations. Yes, I used two separate file saving options for RAW and Average values as I don't know how to save both within the same file.

Kind regards

 

Hasham

0 Kudos
Message 21 of 31
(526 Views)

Hi,

 

Sorry for disturbing you all. As I am trying to run code by replacing while loop with for loop and for which I set 100Hz/sec sampling rate and set number of iterations 100 in FOR loop but it completed before one second around 0.03 sec and give only three samples data and when I am setting value in thousands like 3000 or more than it is completing run near to one second and give 100 samples data. Could you please guide me why my code is behaving like this in FOR loop environment and can I set or control number iterations in while loop as it is continues loop.

 

Kindly please guide me.

 

Kind regards

 

Hasham

0 Kudos
Message 22 of 31
(581 Views)

Hi Hasham,

 

we already asked you more than once to cleanup your code, but you failed again.

Didn't you say you want to learn from our suggestions & recommendations?

 


@Hasham622x wrote:

As I am trying to run code by replacing while loop with for loop and for which I set 100Hz/sec sampling rate and set number of iterations 100 in FOR loop but it completed before one second around 0.03 sec and give only three samples data and when I am setting value in thousands like 3000 or more than it is completing run near to one second and give 100 samples data.


Where exactly do you define the sample rate?

All you do is reading data from an external device, connected by serial port!?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 23 of 31
(561 Views)

can you elaborate more what you are trying to achieve ? 

How fast you need your loop to run ? You may need to add a timing function  (wait (ms) function

inside the loop to time the code every iteration

 

 

Message 24 of 31
(539 Views)

This is now the third place where you post this exact VI. Why can't you keep it all in one place? And why can't you clean up your code! (see also). In comparison, most of my programs are 100x more complex and still comfortably fit on one screen. With your "programming style" (for lack of a better term), my code would fill a football field and would not be manageable.

 

A toplevel VI should be a state machine, not a downhill run and you have plenty of ways to stop your loop after a certain number of rows have been collected (you even count the number of acquisition twice at the moment!). You cannot (Yes!!!! cannot!!!) use a FOR loop here, because the number of loop iterations is not necessarily linked to the number of acquisitions because it also iterates if the "bytes at ports" is low. Of course all bets are off, but I assume you want to control the number of acquisitions, not iterations, right???

 


@Hasham622x wrote:

g

Sorry for disturbing you all. As I am trying to run code by replacing while loop with for loop and for which I set 100Hz/sec sampling rate and set number of iterations 100 in FOR loop but it completed before one second around 0.03 sec and give only three samples data and when I am setting value in thousands like 3000 or more than it is completing run near to one second and give 100 samples data. Could you please guide me why my code is behaving like this in FOR loop environment and can I set or control number iterations in while loop as it is continues loop.


There is no reasonable unit of Hz/sec (Hz is 1/s, so Hz/s is 1/s²) and I can't even imagine what that means, except maybe for a chirp signal, for example.

 

Your loop speed is limited by the speed of the serial communication and that entirely is the responsibility of the sender. You have no control over that!

Message 25 of 31
(524 Views)

Hi,

 

Sorry for disturbing you by controlling the while loop; I introduce a comparison function inside the loop, in which x represents required iterations and y starts from 0. As it reaches the required value, the loop will stop. Outside while loop from averages, first, subtract the same constant value from each average value, then subtract the average values like a veg Val1 - a veg Val2, .... Kindly please guide me if I am doing the correct stepping, or again I am making a mistake?

 

I also attached the LV code (LV19 version).

 

Kind regards

 

Hasham 

Hasham622x_0-1721475144299.png

 

0 Kudos
Message 26 of 31
(439 Views)

Hi,

 

Sorry for disturbing you by controlling the while loop; I introduce a comparison function inside the loop, in which x represents required iterations and y starts from 0. As it reaches the required value, the loop will stop. Outside while loop from averages, first, subtract the same constant value from each average value, then subtract the average values like a veg Val1 - a veg Val2, .... Kindly please guide me if I am doing the correct stepping, or again I am making a mistake?

 

I also attached the LV code (LV19 version).

 

Kind regards

 

Hasham 

Hasham622x_0-1721475144299.png

0 Kudos
Message 27 of 31
(437 Views)

This is still a horrible hairball and you did not implement most of our suggestions:

 

  • Your code is still a downhill run instead of a state machine.
  • Your diagram and front panel are still maximized to the screen. It helps to see both windows AND some others (e.g. the help pages that you really need!!) at the same time.
  • Why are your controls randomly scattered over the front panel? Do you like herding cats?
  • Most of your file IO has no path wired. Why can't you use lowlevel file IO after the loop to append the statistics to the same file?
  • A fixed file path in the downloads folder is not useful. Why not make it e.g. relative to the VI?
  • You are still writing the average and the last acquisition to the file right after the loop. Why?
  • Your still doing the counting twice for no reason
  • I prefer a "greater or equal comparison" instead of "equal", just for safety and as a good habit to have. In your case, if the control is changed from 10 to 5 after 6 acquisition, your loop would never ever stop!
  • .Why are some of your label in tiny font? "x" is not an intuitive name for a total count and zero is not a useful default value.
  • Your FOR loop on the right makes absolutely no sense and just results of 16 identical values (adding "negative 0" to a number just returns the input, right?), we can  guarantee that your pairwise subtractions will result in an array of 8 zeroes, so what's the point?
  • You are still creating an array of times that is never used and then even autoindex at the output tunnel to get an inflated 2D array with mostly redundant elements.

 

Then you have pure Rube Goldberg code to subtract adjacent elements, for example here's an alternative that would take seconds (instead of minutes)  to code (equivalent of raising your hourly wage by a factor of 10!)

 

altenbach_0-1721489919849.png

 

Message 28 of 31
(426 Views)

@Hasham622x wrote:

Outside while loop from averages, first, subtract the same constant value from each average value, then subtract the average values like a veg Val1 - a veg Val2, .... Kindly please guide me if I am doing the correct stepping, or again I am making a mistake?


Your description has no resemblance to your code and is very ambiguous, but if you want to subtract the average of the array averages and take the pairwise difference, here's what to do;

 

altenbach_0-1721492343503.png

 

Note that the array of averages is a 1D array, i.e. the second row of your 2D array. Your first row is the last non-averaged record that you already saved to file. Follow the wire!

 

Message 29 of 31
(421 Views)

Hi,

 

Thanks for your guidance. I tried to use the 1D decimate array option, but it gives an error as after the loop, the average array is 2D due to that I tried other options, and please guide me on how I could save each file with the current date and time so it should not have fixed same file name as at the moment I have to delete or shift data file after code run.

Once again, thanks for your reply.

Kind regards

Hasham

0 Kudos
Message 30 of 31
(396 Views)