lizimunro Posted February 26, 2008 Report Share Posted February 26, 2008 I need a while loop to run for an exact number of minutes whilst reading data from the serial port. I am currently using the elapsed time function but instead of looping for precisely one minute it will run for about 1 minute 20 seconds because it checks the time at the beginning of the loop and if the minute is reached just after the last check it takes several seconds to reach the check point again. Ideally I would like the user to select the number of minutes for the run and for data to be read from the serial port for this time exactly and no more. Any advice would but be great :-) Thanks Download File:post-10705-1203941249.vi Quote Link to comment
jdunham Posted February 26, 2008 Report Share Posted February 26, 2008 QUOTE(lizimunro @ Feb 25 2008, 04:08 AM) I need a while loop to run for an exact number of minutes whilst reading data from the serial port. I am currently using the elapsed time function but instead of looping for precisely one minute it will run for about 1 minute 20 seconds because it checks the time at the beginning of the loop and if the minute is reached just after the last check it takes several seconds to reach the check point again.Ideally I would like the user to select the number of minutes for the run and for data to be read from the serial port for this time exactly and no more. Any advice would but be great :-) Thanks http://lavag.org/old_files/post-10705-1203941249.vi'>Download File:post-10705-1203941249.vi I think you will do yourself a favor by getting rid of the express vi. just read the system time before you start, and loop every 100ms. In every iteration, check the elapsed time the old-fashioned way: subtract the start time from the current time. You will also get a pleasing side-effect in that your STOP button will be polled at the new faster loop rate, so you can stop the loop right away rather than waiting for a minute. Quote Link to comment
lizimunro Posted February 27, 2008 Author Report Share Posted February 27, 2008 QUOTE(jdunham @ Feb 25 2008, 11:37 PM) I think you will do yourself a favor by getting rid of the express vi. just read the system time before you start, and loop every 100ms. In every iteration, check the elapsed time the old-fashioned way: subtract the start time from the current time. You will also get a pleasing side-effect in that your STOP button will be polled at the new faster loop rate, so you can stop the loop right away rather than waiting for a minute. Thanks - will try that :-) Quote Link to comment
lizimunro Posted February 27, 2008 Author Report Share Posted February 27, 2008 I have changed te express vi so I am now checking against system time. The time needs to start at the visa write function just before the loop starts. I think I am missing something or have made an error as the timing is still not exact. I still have to wait a few seconds until the check time section is executed and the time reached triggered. I don't seem to have speeded the loop up to execute once every 100ms. I am relatively new to Labview so may be misunderstanding this completely! Attached is the updated vi Download File:post-10705-1204025858.vi Quote Link to comment
BrokenArrow Posted February 27, 2008 Report Share Posted February 27, 2008 What, exactly, is your issue at this time? Your timing will code work fine, there's no issues there. If you set it for 1 minute, it should run 1 minute plus maybe 100mS. Is your serial port code hanging up? Check and make sure you don't need to send a CR or LF with your commands. Richard Quote Link to comment
Jon Sweeney Posted February 27, 2008 Report Share Posted February 27, 2008 QUOTE(lizimunro @ Feb 26 2008, 06:37 AM) I have changed te express vi so I am now checking against system time. The time needs to start at the visa write function just before the loop starts. I think I am missing something or have made an error as the timing is still not exact. I still have to wait a few seconds until the check time section is executed and the time reached triggered. I don't seem to have speeded the loop up to execute once every 100ms.I am relatively new to Labview so may be misunderstanding this completely! Attached is the updated vi http://lavag.org/old_files/post-10705-1204025858.vi'>Download File:post-10705-1204025858.vi Your "Time Improving.vi" seems to work fine on my pc (within .2 seconds of the requested time), but I of course don't have the same serial stream as you do. Have you been watching the error codes to make sure things are working well and not timing out, which would add 10 seconds with the default timeout. Other than that I don't see what could be adding the extra seconds. Quote Link to comment
lizimunro Posted February 28, 2008 Author Report Share Posted February 28, 2008 Thanks for the advice. I think it is the serial read that is slowing the loop down as the timer seems to work fine in isolation! It just seems to take about 9 seconds to loop round and so if the time elapsed at the beginning of the loop there is a delay before anything is done about it. Quote Link to comment
Jon Sweeney Posted February 29, 2008 Report Share Posted February 29, 2008 QUOTE(lizimunro @ Feb 27 2008, 05:19 PM) Thanks for the advice. I think it is the serial read that is slowing the loop down as the timer seems to work fine in isolation! It just seems to take about 9 seconds to loop round and so if the time elapsed at the beginning of the loop there is a delay before anything is done about it. I don't know why that should happen. But you should be able to determine if the reading is taking a long time with a breakpoint before and after the Visa Read. Also put a probe on the Visa Read error-out wire to see if there are any errors (ignore warnings that there may be more chars available). You should be able to track down the problem source with judicious use of breakpoints and probes. (As a side note, it seems odd that you are sending the "Radio Selection Code" (F,V, or P) twice, but maybe that is necessary.) Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.