Shop OBEX P1 Docs P2 Docs Learn Events
iButton — Parallax Forums

iButton

johnny_bjohnny_b Posts: 28
edited 2005-05-25 06:12 in BASIC Stamp
Remember this?

"Hi,
Does anyone have a code for tranlating hh/min/sec time from a Dallas 1994 iButton?
Just want to have an RTC addition to the project (BS2p40 with serial LCD), and I have
some iButtons on the shelf...

thanx, johnny"

well, so far I can get the time data, in a form of incrementing sec counter,·but....

OWOUT OWpin, %0001, [noparse][[/noparse]SkipROM, ReadMemory,2,2]
OWIN OWpin, %0010, [noparse][[/noparse]SPSTR 5]
GET 1,temp.LOWBYTE
GET 2,temp.HIGHBYTE
SEROUT LCD_serOUT, LCD_baud, [noparse][[/noparse]27,4,DEC2 (temp/3600),58,DEC2 (temp/60)//60,46,DEC2 temp//60]
(first byte:1/256th seconds, next four bytes are the sec counter)
so something like this, but the 16 bits are not enough to count 24 hours in seconds, so I would need the
next 8 bits also from the stream. (GET 3, ....)

anyone got a nice solution or idea?

Johnny

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-18 14:33
    Hello,

    ·· Tech Support recently answered this question in another thread (In fact it was you who asked for the same code before), but I will repost the link here for you.· We have a book available as a free download in PDF format from our website that has code for the BS2p for this device.· You can find it here:

    http://www.parallax.com/detail.asp?product_id=70001

    Page 172, according to another Tech.· Also see Page 179.· Good luck!

    The original thread is here: http://forums.parallax.com/showthread.php?p=535514






    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-18 14:35
    Looking at the docs, the DS1994 stores time in seconds: the first four bytes form a 32-bit whole seconds value (0 to 4294967296), the final byte is fractional seconds (1/256). My point is that you will need another approach for your calculations. The thing about the DS1994 is not a real-time-clock in the sense of the DS1307 and others that actually tract time elements (hours, minutes, seconds) is separate registers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • johnny_bjohnny_b Posts: 28
    edited 2005-05-18 18:28
    Okay, I read the BS2p book, but that will not solve my problem. Thanx to the book, now I can get the info from the iButton, but still cannot make a clock from it. If I could follow the sec counter, I could make the calculations, and display the time.

    So I ask it an other way: how to handle a 32-bit counter with the BS2p?

    thanx, johnny
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-18 19:21
    johnny,

    ·· Jon has provided you with the information you need in addition to what's in the book.· You're going to need some math.· wink.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-18 20:26
    Tracy Allen has some 32-bit routines on his web site: http://www.emesystems.com/BS2math6.htm.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • johnny_bjohnny_b Posts: 28
    edited 2005-05-23 13:21
    Thanx Jon, nice webpage!·smilewinkgrin.gif

    Hope I'll find some·guidelines there...
    By the way, I prefer the iButton over the 1302 (which I don't have yet...),
    it contains the backup battery already, and only needs 1 communications pin.
    And easier to mount on a proto board.

    Just have to find a way to translate 32-bit counter into 24h clock (Date is
    not necessary...)

    greetings, johnny
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-23 14:46
    Since you're just wanting time you might consider keeping the value of the counter within the limits of 16-bit (word) variable.· This would let you track hours, minutes, and seconds for a 12-hour period.· Your software could keep track of AM/PM.· If you do this, the math is quite simple:

    · hours = counter / 3600
    · mins = counter / 60
    · secs = counter // 60

    When the counter rolls past the 12-hour mark of 43,200 you can "fix" the clock by doing this:

    · counter = counter // 43200
    · ampm = ~ampm

    ... then write the counter back to the DS1994

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • GadgetmanGadgetman Posts: 2,436
    edited 2005-05-23 15:43
    Another solution could be to get a 'ThermoChron' (DS1921) iButton...

    They have a RTC with YYMMDDHHMMSS format...
    (Well, actually, it's in BCD format, so is REAL easy to transfer to an LCD, but a bit more work if you want to do any calculations)
    Accuracy is given as +/-2minutes/month.

    The 512Bytes general purpose memory is just a bonus...
  • johnny_bjohnny_b Posts: 28
    edited 2005-05-24 07:28
    Come on! Why didn't I know about 1921 before idea.gif ??
    I also have one on the shelf...yeah.gif
    Thanx for the idea!

    Jon,
    This is the way I approached, except after the sec and min divisions
    I shifted the 16 bit number by 1 bit to the right, and shifted in the
    first bit from the next byte, to have 24 hr counter.
    Before doing this, I had to add an offset, to the counter, to have the
    correct time. But this did not work...
    Your point is good though, to WRITE BACK!!!! This should solve it.
    Start from 0, no offsets, just basic divisions.

    When I'm done with both this, I'll post it ;-)

    br, johnny

    ·
  • johnny_bjohnny_b Posts: 28
    edited 2005-05-25 06:12
    wow... now I am working on writing info back to the iButton.

    Hope I can do it ;-)

    Self-trained iButton guru-ness, here I come! yeah.gif

    johnny
Sign In or Register to comment.