I have a timed loop, which is executed every 50 ms - inside this loop different data is sampled (voltage, temperature ect.). This data I want to write to a file (spreadsheet or whatever!?). My problem is that I dont want to write to "the file" every 50 ms, but only every sec. How do I do this and at the same time keep the timed loop to execute every 50 ms?? I hope you understand what I mean?
The previous solution will work *IF* the amount of data is not too big. Remember that when you are writing to a file you're using the operating system's file I/O functions, and they can preempt your data acquistion. If your data acquisition is not tolerant of that then you need to separate the data acquisition from the file write.
Writing the file after the data acquisition is one possibility, but that incurs the risk of data loss if the program crashes or hangs during the data acquisition, as you'll never get to the write file step! Also, if you're running the data acquisition for a long period of time you're going to run into memory issues as you make that array that's collecting the data bigger and bigger. Also, as the array grows in size, so does the time it take to add new items to it.
The best solution is to have separate data acquisition and file write loops. You did not indicate what you're using to perform your data acquistion: is it DAQ, FieldPoint, what? As for architecture, a queue or functional global can be used to collect the data and this is used to share the data between the loops. See this thread for a simple example (given in the last post).