Ah! That's useful information. The DS1302 uses BCD (Binary Coded Decimal) for its numbers with each digit represented in 4 bits, typically 2 digits per byte.
You'd want: (FirstDigit << 4) + SecondDigit to put the most significant digit in the high order 4 bits of the byte and the least significant digit in the low order 4 bits of the byte.
Instead of splitting out the digits, then recombining them, you could take a number from 0 to 99 and convert it to BCD like this:
Ah! That's useful information. The DS1302 uses BCD (Binary Coded Decimal) for its numbers with each digit represented in 4 bits, typically 2 digits per byte.
On a different note, I'm using this chip and when I use the driver from the OBEX:
PUB SetClock '' Set clock from PC clock.
' important note: real time clock (DS1302) and the thermometer (DS1620) share
' the same clock and data lines!
if (mode & 2) > 0
rtc.init( 21, 20, 19 ) ' ports (Clock, data, chip enable)
rtc.config ' Set configuration register
' ---------------
' when propeller sends a string "NOW" to my Excel macro, it replies with
' each parameter on its own line. Year, Month, Day ... etc.
' Control(string) sends a string w/CR and returns a long from the PC.
' ----------------------------
year := Control(String("NOW")) - 2000 ' ask pc 4 time data
month := GetDec
day := GetDec
dow := GetDec
hour := GetDec
minute := GetDec
second := GetDec
rtc.setDatetime(month, day, year, dow, hour, minute, second) ' set clock
return
Tapperman,
I don't have the DS1302 to test with, but a thought occurs to me that often timer chips always store 00 to the seconds value and expect a start on the minute mark to be seconds accurate.
Jim
The datasheet for the DS1302 shows that seconds is written just like any other field, so you should be able to set the seconds. I would suggest testing it independent of the VB code. Maybe the VB code isn't sending the seconds correctly.
Tapperman,
I don't have the DS1302 to test with, but a thought occurs to me that often timer chips always store 00 to the seconds value and expect a start on the minute mark to be seconds accurate.
Jim
When reading or writing the time and date registers, secondary (user) buffers are used to prevent errors when the internal registers update. When reading the time and date registers, the user buffers are synchronized to the internal registers the rising edge of CE.
The countdown chain is reset whenever the seconds register is written. Write transfers occur on the falling edge of CE. To avoid rollover issues, once the countdown chain is reset, the remaining time and date registers must be written within 1 second.
I was just hoping that someone else would tell me thier chip DOES record the seconds value. And I just have a bad chip perhaps?
I would suggest testing it independent of the VB code. Maybe the VB code isn't sending the seconds correctly.
No ... I thought of that ... and the values passed by VB are all there ... and even if I try to set the value hard coded to '30' seconds (lets say) ... the result is the same.
Im thinking about trying it in 'burst' mode? Perhaps that might do the trick.
----[ a little while later]
nope ... that didn't work either.
I'm wondering ... is anyone else confused by this paragraph out of the datasheet:
The countdown chain is reset whenever the seconds register is written. Write transfers occur on the falling edge of CE. To avoid rollover issues, once the countdown chain is reset, the remaining time and date registers must be written within 1 second.
What do they mean by countdown chain? Could this be an issue?
Comments
Do I need it to be a string to accomplish this?
You may recall that in one of your other threads I demonstrated how to read a decimal number from the keyboard you're working with.
Do you mean to do something like: FirstDigit * 10 + SecondDigit
Do you mean to do something like: (SecondDigit + "0") << 8 + (FirstDigit + "0")
How about the other way around: (FirstDigit + "0") << 8 + (SecondDigit + "0")
I'm sure I could figure out other equally valid ways. Which do you want?
Mike Green
That is what I am doing now and it isn't working.
For instance, if the first digit is 0, 0* 10 = 0, if the second digit is 7, 0 * 10 + 7 = 7 not 07
This value will be passed to a DS1302 Real Time Clock for years, seconds, minutes, etc... These all have the potential to be 00
Bruce
You'd want: (FirstDigit << 4) + SecondDigit to put the most significant digit in the high order 4 bits of the byte and the least significant digit in the low order 4 bits of the byte.
Instead of splitting out the digits, then recombining them, you could take a number from 0 to 99 and convert it to BCD like this:
BCD := (Number / 10) << 4 + (Number // 10)
Thank you very much for that interesting piece of information. One of those things that you must know.
Bruce
Works perfectly now. Thanks again very much.
Bruce
On a different note, I'm using this chip and when I use the driver from the OBEX:
http://obex.parallax.com/objects/519/
to store info in the chip. It takes everything but the seconds value. It never records the seconds to the chip. Any idea why?
... Tim
You will need to post your code that sets the time clock, otherwise it will just be a guess for those trying to help you.
Bruce
Okay here's the snippet that sets the clock:
Followup information:
Here's the VB code in excell that respons to the propeller request "NOW".
I added this snippet of code inside the stamp_DataReady() method.
... Tim
Well ... that being done, I'm still left with the question of why the seconds do not store in the chip? Has anyone else noticed this on the DS1302?
I don't have the DS1302 to test with, but a thought occurs to me that often timer chips always store 00 to the seconds value and expect a start on the minute mark to be seconds accurate.
Jim
http://datasheets.maxim-ic.com/en/ds/DS1302.pdf datasheet for this chip
Yeah, I found this is the manual on page 6:
I was just hoping that someone else would tell me thier chip DOES record the seconds value. And I just have a bad chip perhaps?
... Tim
No ... I thought of that ... and the values passed by VB are all there ... and even if I try to set the value hard coded to '30' seconds (lets say) ... the result is the same.
Im thinking about trying it in 'burst' mode? Perhaps that might do the trick.
----[ a little while later]
nope ... that didn't work either.
I'm wondering ... is anyone else confused by this paragraph out of the datasheet:
What do they mean by countdown chain? Could this be an issue?
... Tim