04-09-2010 01:56 PM - edited 04-09-2010 02:00 PM
Hi,
I have some code that collects data and controls a motor. Currently this runs within a loop. I would like to make the code so that the motor and the data collection occur at specified time points, but the interval between points will not be consistent, so using a simple timed loop won't work, unless I can change the value of the frequency. Some times that I might want to use would be like at 0 seconds, 30 seconds, 1 minute, 2 minutes, 5 minutes, 10 minutes 20 minutes 30 minutes, etc.
It would work to either run the current loop at various times, or to have the loop run continuously, but only turn the motor on and write the data to a file at the specified times. I'm not sure which would be easier. I played with the "disable" loop, but it was not straight forward how to enable it or disable it programatically. Whichever method is used, I do need to keep track of and write to the file, the total time the program has been running.
I am attaching the current code in case it helps to see what I am trying to do.
Also, one other question while the code is here... one consistent problem I have with this code is that at various points while the code is running, the voltages read here just go to zero for one reading, then back to the expected value. It seems to happen on somewhat consistent intervals, but other times random intervals. Not sure if it is some problem with a buffer size or something. Any suggestions on this issue would be great as well.
Thanks in advance!
04-09-2010 02:03 PM - edited 04-09-2010 02:06 PM
It seems to me you'd use the Elapsed Timer to trigger the file writing by encasing the file writing part of the code in a case statement. Maybe I'm missing something.
04-09-2010 04:32 PM - edited 04-09-2010 04:33 PM
04-09-2010 06:22 PM
Your code is very difficult to follow. You need to learn good programming technique. Too much clutter on one screen makes it almost impossible to follow the code. You have some wires running from right to left, which also makes it hard to read. Some of your wires are being overlapped by other wires and other structures. I suggest that you learn the state machine architecture and re-write your code. You would be surprised at how easily it may be to spot a problem that is not easily observed in your code now. So much for the lecture. (Just trying to help you write better code)
For your requirement on running loops at different times, you can use the delay function (the one you have the constant 20 wired to) and make that constant into a variable. Set the variable before you enter the loop. That way you can programatically change the delay value for each time you enter the loop.
Elapsed time works like this. You set a value for elapsed time. When that time period has elapsed, the boolean output "Time Has Elapsed" will go TRUE. (Otherwise it is False). Use this boolean with a case statement to perform some action when the time has elapsed. You should use Error In and Error Out wires to tell the timer when in your program you want it to start timing. The way you have it now, the timer starts every time the loop starts a new iteration. I'm not sure what you want to do with this. Your Write To Measurement File will execute once each loop iteration. If this is not what you want, you have to add conditions to tell it when to write.
One more thing, you should add code to stop the loop in case there is an error on the error wire.