DS1904 RTC - How to Convert Binary Time into Real Time/Date?


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default

    Hi Bert.

    The point that confussed me more was that the chip was not set by me. It was set by Maxim or another person far far away from me in a different time zone, before winter time.

    As you can see by the attached picture above, it has 0-1 seconds difference from my PC! Amazing. There must be a trick.

    I found this C program but could not understand what really does.

    Code:
    void loop(void) {
      byte i;
      byte present = 0;
      byte data[8];
      byte addr[8];
      uint32_t timestamp;
      int seconds = 0;
    
      if ( !ds.search(addr)) {
    	//Serial.print("No more addresses found.\n");
    	ds.reset_search();
    	delay(500);  // for readability
    	return;
      }
    
      present = ds.reset();
      ds.select(addr);
      ds.write(0x66,1);   // read RTC
      for ( i = 0; i < 5; i++) {
        data[i] = ds.read();
      }
    	timestamp = data[1];
    	timestamp = timestamp << 8;
    	timestamp |= data[2];
    	timestamp = timestamp << 8;
    	timestamp |= data[3];
    	timestamp = timestamp << 8;
    	timestamp |= data[4];
    Serial.println(timestamp);
    delay(1000);
    }
    Ioannis

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ioannis View Post
    Hi Bert.

    The point that confussed me more was that the chip was not set by me. It was set by Maxim or another person far far away from me in a different time zone, before winter time.

    As you can see by the attached picture above, it has 0-1 seconds difference from my PC! Amazing. There must be a trick.
    That is quite incredible! I dont get how the maxim reader could know when the timer was started

    As for the code snippit, I don't know C, but it appears to just read the data into an array, and display it.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default

    Yes it uses an array and does some oring and shifting.

    I really have not quite understood the logic behind it.

    A couple of days say Maxim for the AN to be approoved.

    Will see...

    Ioannis

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,133


    Did you find this post helpful? Yes | No

    Default

    Update from Maxim.

    Well, finally the counter is pure binary and user have to set a referene time stamp.

    So far OK. But how on earth can one calculate the date, months, leap years etc?

    If anyone interested in the details of the AN from Maxim, PM. Code examples are in assembly though.

    Ioannis

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts