DS 1307 Real Time clock and functions
ryankh2450
Posts: 5
I'm relatively new to stamp programming and electronics. I went through most of the exercises on the homework board sometime ago, but I still have much to learn.
I am using a PDB board and BS2px stamp to prototype an electronic unit that will control the cycle times (on/off) of electrical devices. Very simple task. However, I am having some issues. It wasn't all that easy for me to pull the time out of the built in real time clock - but I did manage to figure it out. What I am trying to do now seems like it should be very simple. I need to use the clock to time a device to turn on for a certain amount of seconds, turn that device off and turn another one on etc. It needs to do this for 6 devices. Accuracy is important, but only within +/- one second. If someone knew how to make the clock work like a timer, instead of a clock, it would make my job much easier and I wouldn't be forced to start throwing things.
I am using a PDB board and BS2px stamp to prototype an electronic unit that will control the cycle times (on/off) of electrical devices. Very simple task. However, I am having some issues. It wasn't all that easy for me to pull the time out of the built in real time clock - but I did manage to figure it out. What I am trying to do now seems like it should be very simple. I need to use the clock to time a device to turn on for a certain amount of seconds, turn that device off and turn another one on etc. It needs to do this for 6 devices. Accuracy is important, but only within +/- one second. If someone knew how to make the clock work like a timer, instead of a clock, it would make my job much easier and I wouldn't be forced to start throwing things.
Comments
Well, it's not a count-down timer.· So, you'll have to establish a hierarchy of tasks, poll/query the RTC, and then perform those tasks.
I can make the clock display in hours[noparse]:mins:[/noparse]secs and print the day below... that is all good. However, when I try to combine the hours and mins, it gives me the wrong answer [noparse][[/noparse]secs = (hours * 60) + secs] and even that is flawed because if it is 10:00:12 is not 12 seconds.... at least if one is trying to run the clock like a timer.
Thank you very much PJ Allen. It's hard to help those that can barely help themselves. I am learning though.....
Attached is the code I am using.
It uses synchronous serial communication instead of I2C, but there is a good explanation of this protocol in experiments #28 & #29 in the StampWorks Manual (downloadable for free from [noparse][[/noparse]url]http://www.parallax.com/detail.asp?product_id=27297[noparse][[/noparse]/url).
You can use the clock chip, but you just need to do a little math. If your time intervals are all less than 60 seconds, you won't even need to do too much of that because you can ignore everything except the seconds field of the current time. Something like this should work:
If you have intervals greater than 60 seconds, you'll need to incorporate minutes into the equation.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
"(hours * 60) + seconds" is incorrect. It's "(hours * 3600) + (minutes * 60) + seconds". But 16 bits isn't enough to hold the number of seconds in a day. Do you need to be able to count that many seconds?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
Thank you
Keep in mind that this is just pseudo-code to give you an idea. It's not plug-and-play.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows
links:
My band's website
Our album on the iTunes Music Store
elapsedSecs = minutes.nib1 * 10 + minutes.nib0 * 6 + seconds.nib1 * 10 + seconds.nib0
That is computed left to right and comes out at 3599 at the end of an hour.
You could reset the clock to zero at the start of each event, and time up to the assigned interval.
Another way to do this with the DS1307 is to use the square wave output from pin 7. With a pullup resistor and connection to a Stamp pin, that gives you a one second heartbeat and the program could simply count up seconds by watching the transitions on that pin.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
The I2CIN command can use the HEX2 formatters to read in the data, and in that case, the time values in the Stamp will no longer be in BCD format.
versus
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thank you very much. I think ya'll might keep me from getting fired today.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.
That is why they call it the present.
Don't have VGA?
Newzed@aol.com
·
Granted, you are feeling very clever, and I too,once a century or so, feel that I have outwitted Father Time. So I had put up a page about Julian time calculations here, even before the year 2000 bug came along. I actually do use Julian time frequently. For example, when a data logging project has to start on such and such a date at a certain time and then go for a certain number of days and hours, it is much more convenient to reduce it all to Julian time, simple sequential numbers from an arbitrary starting point. The events become simple comparisons of magnitude, and special case programming for crossing boundaries of days, months, years is avoided. And if you carry it far enough, centuries and epochs. Someone else can worry about that starting in 2099.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com