[time-nuts] arduino solar clock

Chris Albertson albertson.chris at gmail.com
Mon Jan 20 00:22:32 UTC 2014


Really, what it is is calculating the new 1pps divisor for the timer
> driving ISR, which divides down from the clock rate of the Arduino.


The trick is for integer math is to never do or postpone division.  So if
you have 1560 PPS per 1432 ticks (or whatever) the number is a rational
fraction of 1560/1432 and you store it as two integer.  The goals is to
always be exact.   that at the end you need to multiply maybe "23425" by
the ratio it is easy (23425*1560)/1432.  Store fractions as fractions.
But you have to check yourself first if that might be an over flow.  If so
then shift it all over some number of bits and shift the answer back.



-- 

Chris Albertson
Redondo Beach, California



More information about the Time-nuts_lists.febo.com mailing list