Hey Group,
I am using a Dallas Semiconductor DS2417 RealTimeClock
This little OneWire device simply starts counting seconds from where ever you tell it to start from (your date reference)
and gives the count back to you in a 4 byte 32bit register
With 32 bits the clock can count up for 136 Years before rolling over.
I need some help figuring out the math to convert the 32bit seconds to HH:MM:SS
My code below is able to do the conversion correctly on the first 16bit ok but fails to take into account the second 16 bits of the 32 bit data.
so after 18 hrs 12 min and 15 sec (65535 or $FFFF) it rolls over to zero.
I need to know how to deal with and include the upper 16 bits of the 32 bit data.
My code takes the lower two bytes (C&D) and combines them into a Word (CD)
and then does the math to convert to HH:MM:SS
But I am at a loss as to what to do with the upper 16 bits.
For now I am not interested in the DAYS, I am only wanting to keep track of a rolling 24 hour clock.
So I expect to just devide the seconds down and discard multiples of 24 hrs.
Code:
'=============================================================
' Read OneWire Clock
'=============================================================
GetOWtime:
owout OWTPin,%000,[$cc,$66]
owin OWTPin,%010,[owctrl,ByteD,ByteC,ByteB,ByteA] 'ByteD=LSB ByteA=MSB
AB.byte1 = ByteA 'MSB
AB.byte0 = byteB
CD.byte1 = bytec
CD.byte0 = byteD 'LSB
return 'with time
'=============================================================
' convert the one wire seconds count to HH:MM:SS
'=============================================================
HMS:
owHH= CD/3600
owMM= (CD/60)-(owHH*60)
owSS= CD//60
return
I need help in figuring out what to do when the word "AB" starts counting above zero (which happens after the 18:12:15 point is reached (assuming I start from zero)
My plan is to start the clock at zero and store the actaul time I started the clock in a variable and add/subtract the stored time variable from the incrementing count to get the current real time.
I know there are other clocks that do all this for you (like the DS1307) but that one is I2C and I specifically need a One Wire solution.
thanks for any help or guidance you can give.
dwight
Bookmarks