[time-nuts] keeping Arduino timekeeping and clock synced up

2014-01-19 Thread Jim Lux


It turns out there's a handy Arduino library for time. And it will 
ingest GPS or NTP, etc., as well as run off the internal clock.


One strategy, then, is:
Set the clock in the Arduino

then, periodically (once a minute or hour)
look up the date and time
calculate rate
set tick rate for external clock driver

Then you have a thing which generates 1pps ticks at the desired rate.
Right now, I have a little interrupt loop that runs once a 
second(adjusted by rate) do it.


One could also calculate solar time (as UTC + EOT offset) repeatedly 
(after all, there's nothing else for the Arduino to do) and whenever the 
seconds changes, send a tick to the clock.


This technique doesn't try to keep the integral of ticks aligned with 
UTC + EOT offset, though.  If the tick rate were slightly off 
(roundoff errors in the math, most likely), then there will be some 
relative drift.


So, periodically, one would need to reset both the analog clock AND the 
Arduino clock to bring them back to proper alignment.


I suppose that periodically, one could compare number of ticks sent 
with UTC + EOT offset and try to compensate (by dropping ticks or 
adding them).





___
time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.


Re: [time-nuts] keeping Arduino timekeeping and clock synced up

2014-01-19 Thread Tom Van Baak
 So, periodically, one would need to reset both the analog clock AND the 
 Arduino clock to bring them back to proper alignment.
 
 I suppose that periodically, one could compare number of ticks sent 
 with UTC + EOT offset and try to compensate (by dropping ticks or 
 adding them).

And then you'd have a GPSDST (GPS disciplined solar time) clock...

While you're at it, add a rotary switch and allow the (JPL) user to select 
which planet's solar time they want to display. Since there are now only 8 
planets you can also do it with a 3-bit configuration switch (now you know the 
real reason Pluto was demoted).

If your project works ok for the earth clock, the next step is a jaw-dropping 
array of 8 (9) clocks in a JPL lobby showing the differently ticking solar time 
for each planet. Use 24h clocks for best results. They can be had from 
www.clockkit.com, an excellent source of DIY quartz clock parts.

/tvb
www.leapsecond.com


___
time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.


Re: [time-nuts] keeping Arduino timekeeping and clock synced up

2014-01-19 Thread Hal Murray

t...@leapsecond.com said:
 If your project works ok for the earth clock, the next step is a
 jaw-dropping array of 8 (9) clocks in a JPL lobby showing the differently
 ticking solar time for each planet. Use 24h clocks for best results. They
 can be had from www.clockkit.com, an excellent source of DIY quartz clock
 parts. 

You forgot time zones.  I think you need a matrix of clocks.  The row/column 
for a planet would need geographic labels.


-- 
These are my opinions.  I hate spam.



___
time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.


Re: [time-nuts] keeping Arduino timekeeping and clock synced up

2014-01-19 Thread Jim Lux

On 1/19/14 1:51 PM, Tom Van Baak wrote:

So, periodically, one would need to reset both the analog clock AND the
Arduino clock to bring them back to proper alignment.

I suppose that periodically, one could compare number of ticks sent
with UTC + EOT offset and try to compensate (by dropping ticks or
adding them).


And then you'd have a GPSDST (GPS disciplined solar time) clock...

While you're at it, add a rotary switch and allow the (JPL) user to select 
which planet's solar time they want to display. Since there are now only 8 
planets you can also do it with a 3-bit configuration switch (now you know the 
real reason Pluto was demoted).

If your project works ok for the earth clock, the next step is a jaw-dropping 
array of 8 (9) clocks in a JPL lobby showing the differently ticking solar time 
for each planet. Use 24h clocks for best results. They can be had from 
www.clockkit.com, an excellent source of DIY quartz clock parts.



You have divined my ultimate goal..Display local solar time for every 
lander, for instance.


Except at work, I'd get a bunch of 3325Bs (since we have pallet loads of 
them around), driven from the maser based reference, and have a PC 
sending GPIB commands to them to adjust the rates.



Handy to have a source for 24hr clock movements. Last time, I bought a 
couple MFJ 24 hour clocks at the local Ham Radio Outlet..


To be honest, one of the interesting challenges is dealing with power 
failures in these kinds of systems.  The Arduino is not a low power 
device..(at least not in the AA battery for 2 years sense).


So, do you run the whole thing off 12V (which is what I'm going to do) 
and a float charged battery OR do you do something clever like detect 
when power is failing and save it in NV storage, then when you come back 
up, you send a bunch of clock ticks real fast to catch up.


Our lobby isn't that big at JPL.. I'll probably hang them down the hall 
outside my office or something.  I had the Mars clock outside my office 
(with a 50 ft coax to the signal generator under my desk) for about a 
year before I had to take it down in the annual clean everything up 
festival.




___
time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.


Re: [time-nuts] keeping Arduino timekeeping and clock synced up

2014-01-19 Thread Tom Van Baak
 So, do you run the whole thing off 12V (which is what I'm going to do) 
 and a float charged battery OR do you do something clever like detect 
 when power is failing and save it in NV storage, then when you come back 
 up, you send a bunch of clock ticks real fast to catch up.

Use a high-res Arduino web cam facing the wall of clocks and write OHR (Optical 
clock-Hand Recognition) code. That way its a single robust solution for setting 
it the first time, restarting it on power failure, resyncing after replacing a 
failed clock, or self-correcting after any mechanical glitch. You can also use 
the same video feed to show off the project live on the JPL web site.

/tvb

___
time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.


Re: [time-nuts] keeping Arduino timekeeping and clock synced up

2014-01-19 Thread Jim Lux

On 1/19/14 4:10 PM, Tom Van Baak wrote:

So, do you run the whole thing off 12V (which is what I'm going to do)
and a float charged battery OR do you do something clever like detect
when power is failing and save it in NV storage, then when you come back
up, you send a bunch of clock ticks real fast to catch up.


Use a high-res Arduino web cam facing the wall of clocks and write OHR (Optical 
clock-Hand Recognition) code. That way its a single robust solution for setting 
it the first time, restarting it on power failure, resyncing after replacing a 
failed clock, or self-correcting after any mechanical glitch. You can also use 
the same video feed to show off the project live on the JPL web site.




No, a low res cam with a robotic arm that moves it in front of each 
clock in turn..


That is what is called scope creep..

I'll be happy if I get ONE clock running reasonably..

I've got the Arduino code running that does the EOT, once a second (but 
using delay(1000) not the ISR), calculates the rate estimate, and 
accepts a sync command over the (emulated) serial port to set the time 
and date.


Curse the folks who develop processing because the current version 
supports Mac OSX 10.7 and later, but not 10.6, which I am using, so I 
don't have the nifty click here to sync the Arduino routine that's 
provided as an example with the Arduino Time library.



Next I have to integrate the code I've got now with the other sketch 
that does the ISR off the hardware timer.



---

#include Time.h


// Solar clock to drive mechanical mechanism
// Jim Lux, 19 Jan 2014

#include math.h
#define TIME_MSG_LEN  11   // time sync to PC is HEADER followed by Unix 
time_t as ten ASCII digits

#define TIME_HEADER  'T'   // Header tag for serial time sync message
#define TIME_REQUEST  7// ASCII bell character requests a time sync 
message

// T1262347200  - sample sync message

const double refclk=31376.6;  //16 MHz/510?
const int clkpin1=6;  // pins going to external clock
const int clkpin2= 7;

int dd, hh;  //current day and hour
boolean UpdateClockFlag; // tells loop() that an interrupt has occurred

void setup(){

  pinMode(clkpin1,INPUT);  // set pins as inputs High Z for now.
  pinMode(clkpin2,INPUT);

  Serial.begin(9600);
  delay(1000);
  UpdateClockFlag = false;
}


void loop(){
  int DOY;
  double e1,e2;
  double secsperday,ratedelta;
  time_t t;

   t = now();  // get the time
  if(Serial.available() )
  {
processSyncMessage();
  }
  delay(1000);// hack, til we get ISR timer running
  UpdateClockFlag = true;// hack

  if (UpdateClockFlag) {
if(timeStatus() == timeNotSet)
  Serial.println(waiting for sync message);
else  {

  DOY = DayWeekNumber(year(),month(),day(),weekday());
  hh = hour();
  e1 = eot(DOY,hh);// EOT in minutes
  e2 = eot(DOY,hh+1);
  secsperday = (e2-e1)*1440;
  ratedelta = secsperday*1.E6/86400; //ppm for now,
   // but we'll change to 
divisor later

  Serial.print(ratedelta); Serial.print( );
  digitalClockDisplay();
  // code in here to update interrupt divisor, etc.
};
UpdateClockFlag = false;
  }
}


// equation of time code from Tom Van Baak
//http://www.leapsecond.com/tools/eot1.c
double eot(int day,int hour){
double Pi = 4 * atan(1);

double y = (2 * Pi / 365.0) * (day - 1 + (hour - 12) / 24.0);
double eqtime = 229.18 *
( 0.75
+ 0.001868 * cos(y)
- 0.032077 * sin(y)
- 0.014615 * cos(2*y)
- 0.040849 * sin(2*y)
);
return(eqtime);
}
void processSyncMessage() {
  // if time sync available from serial port, update time and return true
  while(Serial.available() =  TIME_MSG_LEN ){  // time message 
consists of header  10 ASCII digits

char c = Serial.read() ;
Serial.print(c);
if( c == TIME_HEADER ) {
  time_t pctime = 0;
  for(int i=0; i  TIME_MSG_LEN -1; i++){
c = Serial.read();
if( c = '0'  c = '9'){
  pctime = (10 * pctime) + (c - '0') ; // convert digits to a 
number

}
  }
  setTime(pctime);   // Sync Arduino clock to the time received on 
the serial port

}
  }
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print( );
  Serial.print(day());
  Serial.print( );
  Serial.print(month());
  Serial.print( );
  Serial.print(year());
  Serial.println();
}
void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon 
and leading 0

  Serial.print(:);
  if(digits  10)
Serial.print('0');
  Serial.print(digits);
}

int  DayWeekNumber(unsigned int y, unsigned int m, unsigned int d, 
unsigned int w){
  int days[]={0,31,59,90,120,151,181,212,243,273,304,334};// Number 
of days at the beginning of the month 

Re: [time-nuts] keeping Arduino timekeeping and clock synced up

2014-01-19 Thread Bob Camp
Hi

Rather than calculating the ppm offset, calculate the number of ticks until you 
drop (or add) one tick. Your output pps can only be offset from the input pps 
by an integer number of ticks anyway. The next decision would be - how big a 
tick can you get away with? For a wall clock, 100 ms is in the ball park of 
begin to big. 10 ms is small enough that it’s below what a wall clock needs. 

Bob

On Jan 19, 2014, at 7:38 PM, Jim Lux jim...@earthlink.net wrote:

 On 1/19/14 4:10 PM, Tom Van Baak wrote:
 So, do you run the whole thing off 12V (which is what I'm going to do)
 and a float charged battery OR do you do something clever like detect
 when power is failing and save it in NV storage, then when you come back
 up, you send a bunch of clock ticks real fast to catch up.
 
 Use a high-res Arduino web cam facing the wall of clocks and write OHR 
 (Optical clock-Hand Recognition) code. That way its a single robust solution 
 for setting it the first time, restarting it on power failure, resyncing 
 after replacing a failed clock, or self-correcting after any mechanical 
 glitch. You can also use the same video feed to show off the project live on 
 the JPL web site.
 
 
 
 No, a low res cam with a robotic arm that moves it in front of each clock in 
 turn..
 
 That is what is called scope creep..
 
 I'll be happy if I get ONE clock running reasonably..
 
 I've got the Arduino code running that does the EOT, once a second (but using 
 delay(1000) not the ISR), calculates the rate estimate, and accepts a sync 
 command over the (emulated) serial port to set the time and date.
 
 Curse the folks who develop processing because the current version supports 
 Mac OSX 10.7 and later, but not 10.6, which I am using, so I don't have the 
 nifty click here to sync the Arduino routine that's provided as an example 
 with the Arduino Time library.
 
 
 Next I have to integrate the code I've got now with the other sketch that 
 does the ISR off the hardware timer.
 
 
 ---
 
 #include Time.h
 
 
 // Solar clock to drive mechanical mechanism
 // Jim Lux, 19 Jan 2014
 
 #include math.h
 #define TIME_MSG_LEN  11   // time sync to PC is HEADER followed by Unix 
 time_t as ten ASCII digits
 #define TIME_HEADER  'T'   // Header tag for serial time sync message
 #define TIME_REQUEST  7// ASCII bell character requests a time sync 
 message
 // T1262347200  - sample sync message
 
 const double refclk=31376.6;  //16 MHz/510?
 const int clkpin1=6;  // pins going to external clock
 const int clkpin2= 7;
 
 int dd, hh;  //current day and hour
 boolean UpdateClockFlag; // tells loop() that an interrupt has occurred
 
 void setup(){
 
  pinMode(clkpin1,INPUT);  // set pins as inputs High Z for now.
  pinMode(clkpin2,INPUT);
 
  Serial.begin(9600);
  delay(1000);
  UpdateClockFlag = false;
 }
 
 
 void loop(){
  int DOY;
  double e1,e2;
  double secsperday,ratedelta;
  time_t t;
 
   t = now();  // get the time
  if(Serial.available() )
  {
processSyncMessage();
  }
  delay(1000);// hack, til we get ISR timer running
  UpdateClockFlag = true;// hack
 
  if (UpdateClockFlag) {
if(timeStatus() == timeNotSet)
  Serial.println(waiting for sync message);
else  {
 
  DOY = DayWeekNumber(year(),month(),day(),weekday());
  hh = hour();
  e1 = eot(DOY,hh);// EOT in minutes
  e2 = eot(DOY,hh+1);
  secsperday = (e2-e1)*1440;
  ratedelta = secsperday*1.E6/86400; //ppm for now,
   // but we'll change to divisor later
  Serial.print(ratedelta); Serial.print( );
  digitalClockDisplay();
  // code in here to update interrupt divisor, etc.
};
UpdateClockFlag = false;
  }
 }
 
 
 // equation of time code from Tom Van Baak
 //http://www.leapsecond.com/tools/eot1.c
 double eot(int day,int hour){
double Pi = 4 * atan(1);
 
double y = (2 * Pi / 365.0) * (day - 1 + (hour - 12) / 24.0);
double eqtime = 229.18 *
( 0.75
+ 0.001868 * cos(y)
- 0.032077 * sin(y)
- 0.014615 * cos(2*y)
- 0.040849 * sin(2*y)
);
return(eqtime);
 }
 void processSyncMessage() {
  // if time sync available from serial port, update time and return true
  while(Serial.available() =  TIME_MSG_LEN ){  // time message consists of 
 header  10 ASCII digits
char c = Serial.read() ;
Serial.print(c);
if( c == TIME_HEADER ) {
  time_t pctime = 0;
  for(int i=0; i  TIME_MSG_LEN -1; i++){
c = Serial.read();
if( c = '0'  c = '9'){
  pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
}
  }
  setTime(pctime);   // Sync Arduino clock to the time received on the 
 serial port
}
  }
 }
 
 void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print( 

[time-nuts] keeping Arduino timekeeping and clock synced up

2014-01-19 Thread Mark Sims

The EOT code that I linked to (http://www.astronomycorner.net/games/analemma.c) 
 and am using is interesting because it appears to be applicable to other 
planets.  It has parameters like the orbit 
obliquity/eccentricity/perihelion/year length that can be changed.  It also 
does not make assumptions like the time of perihelion is 12 days past a fixed 
value of the winter equinox (i.e. Jan 2).
A clock routine that I wrote for the ATMEGA2561/ATMEGA128 runs off of a 10Khz 
interrupt.  It does a first-order compensation for crystal drift by 
occasionally ignoring or duplicating timer tick processing.  It can produce 
very good long-lerm clock performance.   
I also have had very good results using the DS3231 temperature compensated 
clock chip.  My alarm clock uses a Trimble Res-T GPS backed up by the DS3231...
-
I've got the Arduino code running that does the EOT 
  
___
time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.


Re: [time-nuts] keeping Arduino timekeeping and clock synced up

2014-01-19 Thread David J Taylor

From: Jim Lux
[]
To be honest, one of the interesting challenges is dealing with power
failures in these kinds of systems.  The Arduino is not a low power
device..(at least not in the AA battery for 2 years sense).
[]
___

Jim,

For low-power, long life, battery operation, you might take a look at the 
JeeNode. Very similar to Arduino, but he's had the thing running on 
batteries for years - he's done a lot of work to minimise power consumption.


 http://jeelabs.net/projects/hardware/wiki/JeeNode

3 years on one set of batteries
 http://jeelabs.org/2013/09/08/3-years-on-one-set-of-batteries/

Cheers,
David
--
SatSignal Software - Quality software written to your requirements
Web: http://www.satsignal.eu
Email: david-tay...@blueyonder.co.uk 


___
time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.