10-07-2009 09:44 PM
I would like to design a simple clock that updates the time only every X seconds, as can be specified by the programmer. I have designed a simple clock that updates the time every second.
In place is a while loop with a Boolean stop button to quit running the simulation. Within the loop is a "Get Date/Time String" VI with string and time indicators. I'm thinking I need to utilize the "Wait" VI but I don't know where or in what way.
Any help is much appreciated.
-Undergrad in Hell
10-07-2009 09:51 PM
Homework?
What you are proposing sounds like one way to do it. What is the problem you are having? What have you actually tried?
10-07-2009 10:09 PM
10-07-2009 10:26 PM - edited 10-07-2009 10:28 PM
Inside. That is what causes a Wait in each iteration of the loop. It doesn't connect to the Get Date/Time function.
The Wait function is one of the basic LabVIEW functions. I suggest you spend some time with one of the free online tutorials:
10-07-2009 10:54 PM
I've made some headway on this problem. I used a "Wait" VI with a constant value of 7000 to update it every 7 seconds. The next task is to ensure that the clock is never more than 4 seconds off...do I use a Wait til Next ms with a constant value of 4000 to employ this?
After that we have to save the timestamps to an ASCII .txt file. I found the Save to ASCII VI and have placed it inside the While loop. Of course borrowing the signal running to the time string indicator didn't work because the type coming out is string and going in is 1-D array of Waveform. What settins needs to be configured in the ASCII VI to ensure the file saves correctly? Does the signal need to be bundled? I'm quite new at this.
10-07-2009 11:18 PM
Why would the clock ever be off? The time comes from the Windows clock. If it is off by 4 seconds, then you have a windows problem.
I don't know what "Save to ASCII File" VI you are referring to. If you want to write the time string to a text file, you should be using the functions in the File I/O palette.
10-07-2009 11:27 PM
Yeah, who knows why. I knew the Get Date/Time VI was based on the System clock...my professor just loves us that much.
I've decided to go with the File I/O VI "Write to Text File" (duh. I should have used that one from the start). When I create a control at the "prompt" input, it does indeed write the time in the file...but only the latest time. And since I have the clock set to update every 7 seconds, I get prompted to save a new text file every seven seconds with the most recent timestamp.
What I need is ONE text file with a LIST of timestamps...
10-07-2009 11:39 PM
You are probably opening and closing the file on every iteration of the loop. For a 7 second interval, that is probably okay. For faster times, you would want to open the file before the loop, and close the file after the loop only have the actual file writing in the loop.
If it is asking you for a filename every time, then that means you forgot to wire up a filepath constant to the Open File VI.
Since you are opening it each time in the loop, the file pointer is being set at the beginning and overwriting the old data. You will want to set the file pointer to the end of the file (look in the Advanced File Functions) before you actually write the data.
10-08-2009 04:30 AM - edited 10-08-2009 04:31 AM
Rod.
10-08-2009 04:32 AM - edited 10-08-2009 04:33 AM
Fighting the web interface here.....
Hi,
The combination of update every 7 seconds, never more than 4 seconds out, suggests to me that the clock should be updated every 7 seconds, and the displayed time will not be more than 4 seconds away from the windows time. I bet the test is to run windows adjust date/time at the same time as your VI and eyeball the clocks changing.
A way to get round that one; get the windows time with "Get Date/Time in seconds", add (in seconds) half of your update interval, [do that by a division so that the offset will change with the update interval] and pass the result to "Get date/time string". So the time that is displayed is initially between 3 and 4 seconds ahead of windows time, and is between 3 and 4 seconds behind windows time at the next update.
Also be aware that if you have a wait in a loop, and your stop button is in the same loop, that the stop button will take up to the wait time to take effect.
Rod.