Is there anyway to know the absolute time ?

BY absolute time(For the lack of a better word) I mean the time between consecutive resets ? Is there any line of code we can write to know that ?

I don't understand what you mean by "the time between consecutive resets".

The elapsed time since the last reset is provided by millis() and micros():
https://www.arduino.cc/reference/en/language/functions/time/millis/
https://www.arduino.cc/reference/en/language/functions/time/micros/

but the term "absolute" does not seem to apply well to those, since they are relative to whenever the reset happened.

When it comes to what I would think of as "absolute time", you'll need to get it from an external source not affected by the reset. That is commonly done by adding an RTC (real-time clock) module to your project or getting the time from an NTP server if your project is connected to a network. Another option is a GPS module.

It somewhat depends on the amount of time that you expect to elapse between resets, and how accurate you need to know the interval. It also depends on the cause of the reset as well.

If it's a reset due to power interruption, then you would need some way of maintaining time like an RTC for example. If you need to know a more precise time (say, to the second) that power is restored, then maybe an internet or GPS based time is not the right way to go as those would require a period of time to establish "connectivity" before being able to extract the time.

Some RTC modules like the PCF85363 from NXP can be configured to automatically log the time that power fails and is restored. They can also log the time an external event happens.

The system clock is millis()

An interupt insets itself when activated

A part of a sketch can act like a stopwatch.

Event> interrupt >note time
Event >interrupt> note 2nd time

Time2 minus time1 = duration

We are just guessing. You need to explain your needs.

A reset is like end of life.
You would need to store. " time now" in eeprom continually.
Then store "time started" when you recovered.
In real time with RTC not system time with millis()

At a murder you cannot ask the dead guy. You look at his watch that got stepped on.

My question is why you want to reset?

thanks you millis() is what i was looking for although how can I use it with time…
for example
time=millis()
if (time<2000) //how do I implement this part where it means if time is less than two seconds from last reset it will ex
{statement} // this statement

Well I am doing a grid navigation and i want my robot to stop at a given location in the grid until a certain time limit is up so that’s why. could you elaborate on the eprom idea?

sericsheon:
thanks you millis() is what i was looking for although how can I use it with time…
for example
time=millis()
if (time<2000) //how do I implement this part where it means if time is less than two seconds from last reset it will ex
{statement} // this statement

If I understand what you’re trying to do, it would be like this:
start_time=millis(); //near the start of your code
.
.
.
if (millis()-start_time > 2000){action to take} //somewhere in the looping part of your code

if (millis()-start_time > 2000){action to take} //somewhere in the looping part of your code

I think OP wanted:

if (millis()-start_time < 2000){action to take}  //somewhere in the looping part of your code

You probably want to set a flag when you’ve taken whatever action you wanted to do so that the action isn’t repeated whilst you’re still less than 2 seconds from a reboot.

Note that all millis() variables must be defined as unsigned long (and constants "UL").

Yes something like that:

Let’s say that i uploaded my code in the Arduino board and gave it some actions to like move forward or backward(as its a robot using arduino board) so lets say I do something like:

time_passed = millis();
if (time_passed < 5000) // less than five seconds
{forward(100); backward(500); stay();}

so it will go forward for 0.1 seconds come backward for 0.5 seconds and then stay at that place until 5 seconds are passed.

Hope this makes it clear enough. (I don’t want the forward backward or stay functions code, Just the part where it can execute the time thing )

Demonstration code for several things at the same time

Look at your clock.
Ask yourself "has 5 minutes transpired? "

The only possible answer is "since when?"

This is the hardest point to grasp when dealing with time. You need to have a reference fime.

Enter grid
Enter_Grid = millis() //reference time

That is your start time
Jump dance whatever.
If (millis() - Enter_Grid>=5seconds
Then Do the next thing

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.