GoForSmoke:
You do know that SD cards have controllers of their own? They do quite a lot and sometimes take a little longer to write a block than usual, the bigger the SD capacity the bigger the sectors the longer that may be.
I didn't thought about the SD card controllers, and it make sense that sometimes they take a little longer than usual. And with 16 gb class 10 card i won't expect large timing spikes. And if there were, i would expect miliseconds delay. Witch wouldn't be a problem on a 5 sec interval where the millis timer keeps running, and give the logging loop a signal for running. Correct me if i'm wrong about this.(?)
Robin2:
Now that you seem finally have accepted this it will enable you to start looking for the real cause of the problem. Put in some print statements to allow you to follow the course of the program.
...R
i concluded that with the correcter interval:
if (currenttime >= next_reading) {
next_reading += interval;
with millis the average timing between logging who is at a interval of 5 secs, is exactly 5 second.
There is an interval where within a certain time it takes 6 seconds after that 4 seconds. So that's an average of 5 seconds.
before with:
if (currenttime - previoustime >= interval) {
previoustime = currenttime;
There was a little delay before the next interval time was created (previoustime). And because the program run's within the void loop from the first to latest line, while for example running the sd card logging loop. There will be created a time difference because writing the data to takes some time, before the next interval time is created (previoustime). Witch will include to an inaccurate interval timing.
I prefer to use to RTU as timing because is't more accurate, and the time within the log file is stable at 5 seconds. Because the program will be asked to run with seconds and not miliseconds(completion), and the arduino can atleast run a certain times the hole program within 1 secons. And you don't have to worry about the accuracy difference between RTC and millis over longer periods.
Gert-Jan_Snik:
I didn't thought about the SD card controllers, and it make sense that sometimes they take a little longer than usual. And with 16 gb class 10 card i won't expect large timing spikes. And if there were, i would expect miliseconds delay. Witch wouldn't be a problem on a 5 sec interval where the millis timer keeps running, and give the logging loop a signal for running. Correct me if i'm wrong about this.(?)
More like 100ms or less. Your post saying 5 seconds vs 6 seconds had me wondering if your time output shows seconds not ms.
Still do expect some lags from the card. A dedicated AVR could buffer for the SD, make a little storage subsystem.
GoForSmoke:
More like 100ms or less. Your post saying 5 seconds vs 6 seconds had me wondering if your time output shows seconds not ms.
Still do expect some lags from the card. A dedicated AVR could buffer for the SD, make a little storage subsystem.
Within the information i log i include the time of the RTC of when the data got to the string and will be written. When viewing the difference between those times. I saw that on certain times there was a difference of 6 seconds, where i would expect 5 seconds.
So that time was of the RTC.
Some lag from the card wouldn't be a problem i guess within an interval of 5 seconds. And if the data that will be written to the sd card is correct, i don't really care if it takes 1 sec longer to write it to the sd card. Or for this project than.
Gert-Jan_Snik:
i concluded that with the correcter interval:
if (currenttime >= next_reading) {
next_reading += interval;
with millis the average timing between logging who is at a interval of 5 secs, is exactly 5 second.
There is an interval where within a certain time it takes 6 seconds after that 4 seconds. So that's an average of 5 seconds.
In the normal way I would only expect a variation of a few millisecs between one time interval and the next unless, on some occasions it takes a very long time for loop() to repeat.
Have you printed out the exact values of millis() for each iteration?