|
|
View previous topic :: View next topic |
Author |
Message |
hubba-bubba
Joined: 11 Sep 2010 Posts: 3
|
DS1682 |
Posted: Sat Sep 11, 2010 6:34 am |
|
|
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
|
|
Posted: Sat Sep 11, 2010 7:35 am |
|
|
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
|
|
Posted: Sat Sep 11, 2010 5:32 pm |
|
|
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
|
|
Posted: Sun Sep 12, 2010 4:54 am |
|
|
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
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; |
|
|
|
|
|
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
|