Go Down

Topic: Time and TimeAlarms Libraries – Ask here for help or suggestions (Read 82721 times) previous topic - next topic

tdf11

Hey all,

I have a question regarding the function time_t now() inside the time library:
Inside this function the Arduino built-in timer ( millis() ) is compared to a last update time of the library.
I wonder what will happen after approx. 50 days of operation when the number returned by millis() has an overflow.

As far as I understood the code, the time will stay at its last update time and will not run anymore.
Did anyone observe such a behaviour or is there a certain function which takes care about such an overflow which I did not recognize?

Thanks,
Thomas

Code: [Select]
time_t now(){
  while( millis() - prevMillis >= 1000){     
    sysTime++;
    prevMillis += 1000;
#ifdef TIME_DRIFT_INFO
    sysUnsyncedTime++; // this can be compared to the synced time to measure long term drift     
#endif
  }

... 

  return sysTime;
}

Nick Gammon

millis will wrap around after 50-odd days. It doesn't stop, or not run.

If you do subtraction that wrap-around won't matter.

eg.

Code: [Select]

if (millis () - startTime >= wantedInterval)
 {
 // do something
 }

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

fallahi

What will happen if you have the following:
  Alarm.alarmRepeat(8,30,0, AlarmA);
  Alarm.alarmRepeat(8,30,0, AlarmB);
  Alarm.alarmRepeat(8,30,0, AlarmC);

Will AlarmA get executed 1st, and then AlarmB and then AlarmC? 

Does the accuracy of the time, depends on other program running, or it has to be idle?  In another words, Do I need to add delay(1) or something like that in my loop? 

Does the time accuracy changes when used with other libraries like PulsePattern?
http://playground.arduino.cc//Main/PulsePattern

Thank you.
Sia

mem

Alarms for the same time will be called in the order the were scheduled.

The scheduler calls the alarm handler in the Alarm.delay function so this should be called regularly in the sketch. There is a readme file in the download with some more details.
When there are more than one alarm ready to be triggered, the first scheduled alarm is serviced on the next call to Alarm.delay, the next scheduled alarm is serviced on the next call to Alarm.delay and so on.
The accuracy of the servicing depends on how often the Alarm.delay function is called.   

I have not used PulsePattern, but if time the code is in the interrupt handler is short, the timing accuracy should not be significantly affected. Why not give it a try. If you print the millis value in the alarm handler you should be able to see if that library is affecting the servicing of the alarms.

I hope that helps.

Have fun!

fallahi

Thank you Mem.  It was very helpful. 

I have been successfully use Alarm.timerRepeat(1, DisplayTime) and it seems to work correctly. Showing "millies" is a great idea, thank you.  I will add that to my code. 

Within my routine, it fetches something from the network, Reading some huge file, and parse and filter what it receives.  I have this done every one minute with Alarm.timerRepeat(60, ReadData).  The problem is when the data is being read, the DisplayClock does not seem to be executed (Clock stops), for 10~20 seconds.  When its done with the ReadData code, it goes back and show the clock every second and the time seems to be correct. 

With in ReadData code, I am using Alarm.delay, client.connect and some other functions from Ethernet library. 

The PulsePattern works on Timer1.  I will give that a try. 

Thanks again. 

keith66

I am a beginner with arduino.
I have a funcioning lcd 20x4 with rtc module after a long time getting the correct libraries to work with arduino1.0.3.
this display the time & date ect but I now need to add alarm functions etc.
the working DS1307library i am using is called DS1307new and my code based on the below that came with library

Scriptname : DS1307_Test.pde
// # Author     : Peter Schmelzer, Oliver Kraus
// # Date       : 2011-04-08
// # Version    : 1.21

I would like to use the alarmtime library and have downloaded the time library from arduino playground but all the programs give compile errors.
I have removed all other libraries to check incase there was any conflicting ones but still does not work.

The above code and library is more complex than the code in the time library and would prefer to use that if possible.

Any help would be appreciated

PaulS

Once you downloaded the code, it became yours. You need to post YOUR code and YOUR error messages.

mem

Keith, there is code for connecting to a DS1307 RTC provided with the Time library download, its called TimeRTC. Why not use that?

Michael

PaulS


Keith, there is code for connecting to a DS1307 RTC provided with the Time library download, its called TimeRTC. Why not use that?

Michael

Well, well. Look who's back. Been a while. Life treating you well, I hope.

mem


Well, well. Look who's back. Been a while. Life treating you well, I hope.


Hi Paul, its good to be back.
I have been busy with all kinds of interesting projects. Still am, but will try to hang out here as much as possible.

Michael

keith66


Keith, there is code for connecting to a DS1307 RTC provided with the Time library download, its called TimeRTC. Why not use that?

Michael


Yes I have tried that but I can´t get any of the code to work of the official time library download, any ideas

keith66

just to illustrate I have just opened TimeRTC from examples/time/time/examples and tried to compile it. I have not touched this code. I just gave the other code so you were aware of what was working, I can post the whole code but becomes rather long.
I'm sure the solution if something simple but can't get it.
It seems to me it is not picking up the library but yet it is in the right place and in shown in examples.. thanks for any help. the errors in compiling shown below.


TimeRTC.pde: In function 'void setup()':
TimeRTC:13: error: 'RTC' was not declared in this scope
TimeRTC:13: error: 'setSyncProvider' was not declared in this scope
TimeRTC:14: error: 'timeStatus' was not declared in this scope
TimeRTC:14: error: 'timeSet' was not declared in this scope
TimeRTC.pde: In function 'void digitalClockDisplay()':
TimeRTC:28: error: 'hour' was not declared in this scope
TimeRTC:29: error: 'minute' was not declared in this scope
TimeRTC:30: error: 'second' was not declared in this scope
TimeRTC:32: error: 'day' was not declared in this scope
TimeRTC:34: error: 'month' was not declared in this scope
TimeRTC:36: error: 'year' was not declared in this scope

mem

It looks like the libraries are not being found.
Make sure you have installed DS1307RTC in the Arduino libraries folder.

The Time.zip file is structured so you can copy the three folders (Time, TimeAlarms, and DS130RTC) into the Arduino Libraries folder.

keith66

Yes that what it seems like to me yet all the folders were unzipped correctly in the library folder.
I've taken the screen shot to show

PaulS

The Time, TimeAlarms, and DS1307RTC folders all go at the same level. DS1307RTC does not go in the Time folder.

Go Up