CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

DS1682

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hubba-bubba



Joined: 11 Sep 2010
Posts: 3

View user's profile Send private message

DS1682
PostPosted: Sat Sep 11, 2010 6:34 am     Reply with quote

Hi,

Can anybody help me understand how this chip (DS1682+) supposed to work?
I've read the datasheet, even the AN506 application note for it, but they are too cryptic for me to understand.

I can communicate OK with it.
I do receive data from it; but how do I manipulate / transform this data so I can display it on a LCD?
I am interested in the Elapsed Time Counter & Event Counter.

Further more, it increments in quarter of a second.

So I got the data from it, I divided by 4 and I still loose about 6 or 7 seconds every minute.

Anybody has got a piece of code for this chip?
Let me see a sample so I can figure out how to do it in my application.

Thank you.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Sep 11, 2010 7:35 am     Reply with quote

Since you have working code why not post it so someone can help you
figure out where the problem is rather than ask for new code?
_________________
Google and Forum Search are some of your best tools!!!!
hubba-bubba



Joined: 11 Sep 2010
Posts: 3

View user's profile Send private message

PostPosted: Sat Sep 11, 2010 5:32 pm     Reply with quote

Right, here it is a piece of my code:
Code:
  I2C1_Start();           // issue I2C start signal
  I2C1_Wr(0b11010110);    // send DS1682 device address + Write
  I2C1_Wr(0x05);      // address of Elapsed Time Counter ETC location
  I2C1_Repeated_Start();  // issue I2C signal repeated start
  I2C1_Wr(0b11010111);    // send DS1682 device address + Read
  aaa = I2C1_Rd(1);    // Read the data (yes acknowledge)
  aab = I2C1_Rd(1);    // Read the data (yes acknowledge)
  aac = I2C1_Rd(1);    // Read the data (yes acknowledge)
  aad = I2C1_Rd(1);    // Read the data (yes acknowledge)
 
  aae = I2C1_Rd(0);    // Read the data (no acknowledge)

  I2C1_Stop();            // issue I2C stop signal

  ByteToStr(aaa, txt) ;
  Glcd_Write_Text(txt, 49,7,1);

Now I can see the readings going up from 0 to 255, then next bit aab is incremented, and aaa starts again from 0
And if I do:
Code:
aaa /=4.2667 ;
ByteToStr(aaa, txt) ;
Glcd_Write_Text(txt, 49,7,1);

I can see it going up from 0 to 59, like real seconds in a RTC chip.
But it is not acurate. It looses about 7 seconds every minute. Even if I don't divide it by 4.2667 it looses the same seconds.

Thanks
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Sep 12, 2010 4:54 am     Reply with quote

It took me some time to figure out why you are dividing by 4.2667, but then I read:
Quote:
I can see it going up from 0 to 59, like real seconds in a RTC chip.
and then I figured it out:
256 / 60 = 4.2667 Cool

This is your problem. The time data in the DS1682 is split over four bytes, but these are not hour, minutes and seconds, but these four bytes have to be concatenated to a single 32 bit counter.
The DS1862 is counting in Quarter-Second Resolution, so you have to take the whole 32 bit value, divide by four to get the number of passed seconds.

Code:
Pseudo code:
byte1 = read_DS1682(addr_5);
byte2 = read_DS1682(addr_6);
byte3 = read_DS1682(addr_7);
byte4 = read_DS1682(addr_8);
int32 counter = make32(byte4, byte3, byte2, byte1);
seconds = counter / 4;
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group