LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

should I use timeloop?

Hi, I am writing a program where every time a measurement is taken, it will also record the time. So basically  what I need is when I press the "start measurement", it will start at t=0 sec and take measurement every 5 sec. The output is going to be in a table format and can also save to file. I used the Insert Into Array... but it's not working ......and I'm not sure is this the right way to do it either.  I saw there are couple timeloops functions. Should I replace it for the while loop?  and will the timeloop do what I want?? I've attached my code here, would someone mind take a look at it?
 
Thanks,
0 Kudos
Message 1 of 12
(3,812 Views)
There are many things wrong with your VI, but I am not sure what kind of output you really want.
  1. Your outer case structure (and OK button) makes no sense unless we assume that you run your VI with the "continuous run" button. Don't!!! Make a state machine that's either doing nothing or acquiring data.
  2. Opening the visa session and configuring the serial port needs to be done exactly once outside the loop. Only the reading and writing belongs inside the loop. Close the session after the loop has finished.
  3. How does your raw string look like? Your "editing" to get the mass seems a bit odd and inefficient.
  4. I don't see anywhere where you "record the time"? (You don't really need to, because it can be calculated from [i].)
  5. You should probably initialize your shift register.
  6. "Built array" is a more natural function than "insert into array" (both have same result, though).

Could you be a bit more specific?

0 Kudos
Message 2 of 12
(3,804 Views)
I need to write a program that control a weight balance that it can plot a mass vs time graph and calcaute the mass rate(g/min), the weight balance is already connected to the computer with a rs-232 cable, and water is dripping at a rate of 10 drops/min.
 
What I need on the front panel are buttons("power on", "power off", "zero", "start measurement", and "stop measurement"), a graph, mass rate, and a table that list the time(timestamp?) and mass output everytime it takes measurement(this is the part need to be save in file) .  since it is a serial cable, i used VISA to do the basic programming. The piece that I attached before is only the "start measurement", the reason why I have all those search/split thingy is because the response is in a "S S    11.13 g" format. Therefore I'm trying to cut the string and get the number. But I'm not sure is this the right way to do it.....
 
right now I'm trying to build that table ("mass history" in the vi), and my friend told me I need to loop it in order to make it work....  but at the same time I saw there is a timeloop thing. I wonder will that function work, because to do the mass rate, I need to add up all the mass and divide by the time the program run.
 
do you understand what I'm trying to do? the concept is pretty straight forward.. I just not sure how to put it in LabVIEW...
 
Thanks,
0 Kudos
Message 3 of 12
(3,793 Views)
I think you need system time with the measurement.
Here is the VI which shows how to combine both.
----------------------------------------------------------------------------------
I have still not got what I love.....
0 Kudos
Message 4 of 12
(3,790 Views)

Please disregard the previous post, there is an error in the attachments

OK, if I understand, you right, you just want to average the reading.
 
(Dividing by a "time" makes no sense, but dividing by the number if times the loop has iterated does. :D).
 
For this you don't even need to save the history. Simply add the values into a shift register and divide by i+1. Here's a quick draft of the crucial parts. I don't have visa so I repaced it by a string diagram constant. Modify as needed. It makes absolutely no sense to carry a number around as strings or array of strings. Use a DBL!
 
 
.


Message Edited by altenbach on 04-12-2008 09:32 AM
Download All
0 Kudos
Message 5 of 12
(3,768 Views)


Halemani wrote:
I think you need system time with the measurement.
Here is the VI which shows how to combine both.

NOOO!!!!!!!   Your code makes absolutely no sense:
  1. Why accumulate the same data in a 1D array and then in a 2D array?
  2. What is the purpose of "systime 2"
  3. Why is the SysTime terminal out in the woods a few screens away?
  4. Why use controls if they should be indicators?
  5. Why use local variables? All you need is a shift register.
  6. You don't show how to combine anything with any measurement.



Message Edited by altenbach on 04-12-2008 09:48 AM
0 Kudos
Message 6 of 12
(3,761 Views)
I think I understand your idea..... I've change my entire code with my friend, and right now my problem is when I run it, I can only press the button once... the rest are not responding at all... would you mind take a look at it and see what we did wrong??
 
Thanks,
Download All
0 Kudos
Message 7 of 12
(3,727 Views)
Sorry....please ignore the previous post... I changed the code a little bit, and right now the "power on" and "power off work" except the others... so should I add the rest of the function in the event structure?? 
 
Thanks,
0 Kudos
Message 8 of 12
(3,724 Views)
You still have way too much code. The outer while loop and the outer sequence frame serve no purpose at all. You can remove both without any change in functionality.
 
I'll study the rest later if I have time.
 
 
0 Kudos
Message 9 of 12
(3,711 Views)

The zero on and start measurement buttons won't work because they are only read once outside of the inner most loops.  The only way for them to get read again is for all the innermost loops to stop and your outer loop to iterate.  That won't happen because the inner loops only stop with the stop measurement button, which will also stop the outer loop.

As Altenbach says, the sequence frame and the outermost loop do nothing for you.  And there is a weird mish mash of parallel loops and event structures within that.  It seems that several of the case structures and loops could be combined.  Look at the examples for producer/consumer architecture with events.

0 Kudos
Message 10 of 12
(3,699 Views)