09-01-2015 04:12 AM - edited 09-01-2015 04:17 AM
Hello everyone
I am using Labview 2012 for my master thesis. I am supposed to develop a SCADA simulation model of a wastewater treatment plant. As one part of my task, I should log every single measured values from the sensors in the plant and saving them to an excel sheet.
For this purpose, I used my own codes to save the measured values to an excel sheet. I used “wait until next ms” block with a 3000 constant value connected to it, in order to create a 3 seconds time stamps for the logged data. So, I used a separated While loop for data logging which gets updated every 3 seconds and a separated While loop for the main application which gets updated every 700ms.
However, the problem is that I use just one Start/Stop button for the whole operation and when I want to stop the application, it takes about 3 seconds to be stopped. It definitely gets worse when I want to have a longer time stamps for the data logging.
I would like to make the stopping operation faster. Could you please tell me how can I use the delay blocks in the way that doesn’t have any influences on stopping operation?
I could use one Stop button for stopping every while loop, but I really would like to have one Stop button for the whole operation. I should mention this point that it is not possible to use DSC module’s data logging feature as we do not have any shared variables connected to OPC server.
Thank you very much for your help in advance. 🙂
Solved! Go to Solution.
09-01-2015 04:22 AM
Hi Iman1988.
It sounds like your overall structure is pretty good.
What you can do in the logging loop is to let it run just as fast as the other loops, it could be every 100ms.
Then add some logic, that in every iteration asks if 3 seconds has passed => if so, log data - if not, skip data.
You can use the function called Elapsed Time. This function return a boolean when the preset time has passed.
09-01-2015 04:31 AM
You should learn about State Machines. In a properly programmed state machine it is easy to stop/abort and ongoing operation.
However there is another simple solution: in your Data logging while loop, set the “wait until next ms” to for example 200 msec.
3000/200=15, so what you only need to keep tracking is the iteration number, and using a modulo devision you can set a CASE structure to False or True. And put your data logging in your True case.
09-01-2015 04:37 AM
@Blokk wrote:
However there is another simple solution: in your Data logging while loop, set the “wait until next ms” to for example 200 msec.
3000/200=15, so what you only need to keep tracking is the iteration number, and using a modulo devision you can set a CASE structure to False or True. And put your data logging in your True case.
You have to be a little careful with using the iteration terminal - it's an I32 and when it reaches the maximum, it will just stop counting rather than roll over. This means after running for an extended duration that your code will stop running properly. The solution is to use an incrementing U32 on a shift register and correctly handle the roll over.
I'm sure it's probably fine in this case (you can calculate how long it will run correctly for) but something to be aware of if you're using the iteration terminal in a fast running loop!
09-01-2015 04:40 AM
Good point! Or it is often handy to use the "Increment PtByPt.vi" from the Signal Processing palette. Also using an U32 shift register, and the main block diagram stays clean 🙂
09-01-2015 04:50 AM
hmm, if a loop has one iteration per 1 second, then the problem with I32 type will start to happen after:
2^31/3600/24 = 24 855.13 Days? Is this calculation correct??
Actually as I remembered, in ANSI C for example when a I32 overflows, it will just start to count from the "minus end", -2^31. Why is it different in LV?
09-01-2015 04:55 AM
Like I said - it's not a problem if you're running your loops on the order of seconds - but if you're doing fast running loops on an FPGA then it can definitely be a problem! (Particularly if you're program is being used for extended operation)
Yes, LabVIEW will roll over if you increment an I32 past it's maximum value BUT specifically the iteration terminal on loops does not rollover, it just stops on the maximum value.
09-01-2015 04:57 AM
09-01-2015 06:43 AM - edited 09-01-2015 06:44 AM
@A.E.P
Thank you very much for your suggestion.
Vey good to know Elapsed time function. 🙂
I´changed my application accordingly and now it works as fast and as well as how I wanted.
@others:
I also appreciate you guys for your helps and comments. 🙂