Sunday 7 July 2013

Time : the trouble with clocks running


Taking Clocks

whats time in your clock?...is it correct ? well if you have set it from some clock is your source correct?
There is world problem of clocks running different time with in a room.Difference may vary from mins to half hour.People some time do it to be early at there destination or wake up early .I do that too. So how do you get your watch a correct time.
You may think of matching you time to that of clock at railway station or at airplane .But what if your clock is losing time. you will lose it too unknowing. In my collage Profs don't let you sit in lectures if you are late as the clock timings vary in ever-bodies clock .
One day in class of Embedded Hardware Design Prof ask how would you keep all clock in all rooms of collage in sync? Simple solution was to appoint a person with a clock and asking him to reset all clock to the clock in his hand.
This can be a solution that can help in small places and if labor is cheap .Well as it was an embedded System class Prof's target was an answer in embedded System terms.One of boy suggested that all clocks update time from a single server ,but that could raise the price of clock that has ability to connect to Internet.Nobody had a perfect answer.
Many days Past and I was reading about cognitive radios and the cooperative model of communication and was into few of this concepts .Last night, suddenly I saw clocks talking and  in my ears when I was switching of my ears with fingers pushed in. I heard tick tick tick... although later I found out that it was my heart beat I heard of..stupid me. But it did spark me an Idea.
In past there use to be  a clock signal radio station  on a particular frequency when you tune to it you can listen to the sound of clock.
well anyways , What I though was an experiment ,
consider clock A is present and another clock B comes (assuming clocks can talk to each other) to A, asking for time so that it can reset itself .But how should B trust that A is at correct time?
You can go on thinking over this topics - cognitive radios,game theory, swarm intelligence and distributed computing to find some solutions.



Orignally written about 5 months ago. 

Time and Programing issues with it

Time and Issues with it.
I have worked with RTC (and arduino for a real life project )and some programming problems related to time.
I want to keep it noted so next time dont fall in this trouble.
This problems are mostly while comparing two time instances.

> Time I generally denote as hh:mm:ss ,also consider it 24 hours scale.
24th hour is 00:00:00.

> An hour starts as 01:00:00 and end at 01:59:59 thus an Interval is measured this way. Adding time such as adding 2:15 hours to time 1:47 as

new min=(15+47)%60 where % is module and floor of ((15+45)/60) is added to hour as 2+1+floor((15+45)/60).

> subtracting time such as 3:12 minus 2:31 is like
  subtract minutes as
if (12 <31),
 hour -1(i.e 3 - 1)
 and  than min + 60, (i.e 12+60)
and then subtracting minutes as 72-31=41 min and then subtracting hours as 2 - 2 = 0.
that gives 00:41 answer for the subtraction
I will still put others, I know more issues but I don't remembered most of those I dugout my previous code and put those too here soon.

 I was motivated by  Question on time intervals on Amazon Interview street challenge https://amazon.interviewstreet.com/challenges/dashboard/#problem/4fd651016cd04