Yet another ds1302 question
press9761
Posts: 6
I need a timer so, I'm using a ds1302. I downloaded the code posted in the forums ( the big one made by a parallax employee) and disassembled it to the smallest form possible. The original code used something like 96% of the memory on the bs2. The code I have uses 4%. However I would like to get it a bit smaller and gain some understanding of how the ds1302 /bs2 interact. So, first off, here is the code I am using. It works quite well as a timer.
************************************************
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] I/O Definitions ]
DataIO PIN 1 ' DS1302.6
Clock PIN 0 ' DS1302.7
rst PIN 2 ' DS1302.5
'
[noparse][[/noparse] Constants ]
WrBurst CON %10111110 ' Write Burst Of Data
RdBurst CON %10111111 ' Read Burst Of Data
'
[noparse][[/noparse] Variables ]
secs VAR Byte ' Seconds
mins VAR Byte ' Minutes
hrs VAR Byte ' Hours
'
[noparse][[/noparse] Program Code ]
DO
HIGH rst
SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]wrburst]
SHIFTOUT DataIO, Clock, LSBFIRST , [noparse][[/noparse]secs, mins, hrs,0,0,0,0,0]
LOW rst
DO
HIGH rst
SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst]
SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs, mins,hrs]
LOW rst
DEBUG HOME
DEBUG HEX2 hrs, ":", HEX2 mins, ":", HEX2 secs
LOOP
LOOP
**********************************************
I changed the write/read burst from hex to binary so I could see what was going on. I removed all the variables I could. My problem is with the date, month, day, year component. If I remove these peaces the clock stops working properly. I found that if I removed those variables and put 0's in the second shift out line ( to keep the space) the clock works fine.
My question is what is going on with that? why cant I just have the sec/min/hour.
I am having trouble making changes to the burst mode data. I have looked at the data sheet and anytime I change the binary I have a clock failure. any suggestions.
I'm just trying to make things as simple as possible
JP
************************************************
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[noparse][[/noparse] I/O Definitions ]
DataIO PIN 1 ' DS1302.6
Clock PIN 0 ' DS1302.7
rst PIN 2 ' DS1302.5
'
[noparse][[/noparse] Constants ]
WrBurst CON %10111110 ' Write Burst Of Data
RdBurst CON %10111111 ' Read Burst Of Data
'
[noparse][[/noparse] Variables ]
secs VAR Byte ' Seconds
mins VAR Byte ' Minutes
hrs VAR Byte ' Hours
'
[noparse][[/noparse] Program Code ]
DO
HIGH rst
SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]wrburst]
SHIFTOUT DataIO, Clock, LSBFIRST , [noparse][[/noparse]secs, mins, hrs,0,0,0,0,0]
LOW rst
DO
HIGH rst
SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst]
SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs, mins,hrs]
LOW rst
DEBUG HOME
DEBUG HEX2 hrs, ":", HEX2 mins, ":", HEX2 secs
LOOP
LOOP
**********************************************
I changed the write/read burst from hex to binary so I could see what was going on. I removed all the variables I could. My problem is with the date, month, day, year component. If I remove these peaces the clock stops working properly. I found that if I removed those variables and put 0's in the second shift out line ( to keep the space) the clock works fine.
My question is what is going on with that? why cant I just have the sec/min/hour.
I am having trouble making changes to the burst mode data. I have looked at the data sheet and anytime I change the binary I have a clock failure. any suggestions.
I'm just trying to make things as simple as possible
JP
Comments
·· I think the code you are referring to was one I posted.· The reason it took up so much space is that it was designed to demonstrate use of most of the functions of the DS1302 except the trickle-charger, and it required a user interface to do this.· That takes up space.
·· Bottom line is that I have used the DS1302 in well over a dozen projects and it takes up very little space in the program, few variables and only one extra I/O line to implement.· Anyway, on to your problem...
·· The problem is you're using BURST mode, which expects all the variables in one transmission.· If you only want to read the hours, mins and secs, you will need to do it one register at a time, and pad the remaining input with a NUL variable.· For example, you could change your SHIFTING to read:
Where tmp is a byte variable that you will just throw away.· Otherwise you will need to read the individual registers and not use burst mode.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
'
[noparse][[/noparse] Constants ]
'
[noparse][[/noparse] Variables ]
secs······ VAR···· Byte··········· ' Seconds
mins······ VAR···· Byte··········· ' Minutes
hrs······· VAR···· Byte··········· ' Hours
'
[noparse][[/noparse] Program Code ]
init:
secs = $00
mins = -1
hrs = 0
DO
HIGH rst
SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]128]
SHIFTOUT DataIO, Clock, LSBFIRST , [noparse][[/noparse]secs]
LOW rst
DO
HIGH rst
SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]129]
SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs]
LOW rst
IF secs=$00 THEN mins = mins + 1
hrs = mins/60
DEBUG home,·· DEC hrs, ":",DEC mins, ":", HEX2 secs
PAUSE 999
LOOP
LOOP
By way of explanation the 128 in the first loop = %10000000.· The MSB 1 enables the clock.· The LSB 0 puts it in a write mode.· In the second loop 129 = %10000001 the LSB 1 puts it in a read mode.· Let me know how it works out for you.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
Delete the line that says "hrs = mins/60" and substitute the following:
IF mins=60 THEN
hrs = hrs + 1
mins = -1
endif
This makes sure that when hrs rolls over to 1, mins is reset to 0.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
Wouldn't that be -
IF mins=60 THEN
hrs = hrs + 1
mins = 0
endif
Bob N9LVU
Thanks for checking, Bob.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
Gotcha!
Bob N9LVU
I set mins = 58 in init, and had to change mins from -1 to 0 to get it to display correctly.· I also had to add "clreol" after "debug hex2 secs" to suppress a mysterious 9 that kept appearing on the debug screen.· Now I think everything is OK.· Thanks again.
JP, please take note and adjust your program.· If you have any problems let me know and I will rewrite the whole program for you.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html
·
·· I don't see why you are manipulating the hrs, mins and secs...The DS1302 can keep track of all of that information by itself.· It knows when one item has rolled over and when to update the next.· No math should be involved in that process, you're just adding to the code by doing so.· The OP was trying to cut back on it as I recall.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Sid
·· The Burst Mode is the quickest and easiest way to get the variables.· I would use a variable that you're not using at that time (or create a dummy one if you have the variable space) and do what I showed.· That will keep the code functional.·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Thank you all for you responses. It was very helpful. What I gathered from all the posts is that I was not far off the mark. Thanks bob, Sid and Chris. Oh and Chris, thanks a lot for the original code.
Jordan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com