DS1302 measuring elapsed time (stop watch) ?
techstudent
Posts: 21
I got the RTC to work and display time/date onto an LCD, but what I am after is using it for measuring elapsed time, somewhere in the ranges of 45 min to 2hrs 45mins (seconds are not important) I want to set it up like a stopwatch where I can push a button to start measuring time elapsed and then push the button again to stop and display the amount of time elapsed. My problem is in figuring out how to do the math on the hrs/mins data from the DS1302 to count elapsed time? My clock is in 24hr mode, and then the next question would be how to compensate for timing 'over midnight' and doing the math from when the hours go from 24 to 1. I think what is confusing me is that the data is displayed in HEX2 format, and to go from hour HEX2 "09" to hour HEX2 "10" it is skipping HEX2 "0A" to HEX2 "0F"
I am thinking others have built stopwatch type applications, and if you could point me to any examples/discussions or just give a general idea of how to go about doing this?
Thanks
I am thinking others have built stopwatch type applications, and if you could point me to any examples/discussions or just give a general idea of how to go about doing this?
Thanks
Comments
·
·Here is where I used in a Project @ this Post
http://forums.parallax.com/showthread.php?p=737892
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 1/8/2009 12:15:45 AM GMT
Here what you have to do if you use two DS1302 time chips
One word of caution you will run out of memory very fast if you are not ·careful how you write your code routine this happen to when writing this code using two time chip if you want to keep track of total timed
event
If you can find a way to use the DS1302 Ram to save these values Please Post Your Code
I would like to see it when your done
Here is the code where Rev the frist code
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 1/8/2009 2:00:55 AM GMT
~techstudent
julian0 = hours.nib1 * 10 + hours.nib0 * 6 + minutes.nib1 * 10 + minutes.nib0
That converts the HEX2 into a number that goes straight from 0 to 1439 as time goes from 00:00 to 23:59. The format from the clock is actually called BCD (binary coded decimal), which is similar to HEX, but as you noticed, it includes only digits 0 to 9 and not A to F. The above calculation goes strictly left to right (no precedence for multiplication, a peculiarity of Stamp math).
At the end of the time interval you calculate again
julian1 = hours.nib1 * 10 + hours.nib0 * 6 + minutes.nib1 * 10 + minutes.nib0
Then
elapsed = julian1 - julian0 + 1440 // 1440
The purpose of +1440//1440 is to account for possible transitions past midnight, positive definite.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Another benefit is you can have multiple counters, each with a resolution of 1 second. These can count up (like a stopwatch) or down (like a count-down timer) and can occur concurrently with each other. If you like each can be enabled/disabled via flag variable.
Basically all you do is in your main loop when you need to count, each time the seconds change you update your counters as well as the old seconds value. This happens each iteration at exactly 1 second intervals and allows for many other events to happen between the changes, such as updating the enabled (if you use that) counters and activating any sort of indication of a completed event (or logging the date/time). I hope this helps. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
seems like this is exactly what I need to do, but I am not experienced enough to figure out the code. What I am trying to do is have my camera take pictures at defined intervals (e.g every hour or once every 24 hrs). I would like to use the DS1302 as a count up clock, and at the appropriate intervals, trigger the picture. Can you give me an example of code on how to implement that with the DS1302?
Thanks
I hope this helps
Here's what I did so far, using Chris's DS1302 template and ideas I gleaned from your response.
I can adjust time for exposure (shutter speed of camera) and interval the photos are taken.
The one last thing I would like to do is be able to stop the program after a certain period of time. Is there a way the program can count the number of iterations that the program completes from the start: portion through the goto start portion?
fsb
Please explain in more detail what you want to do here
Are you wanting to stop the " Timer "for some amount of time ?
or
Do you want to wait for some amount of time before the your code routine run again ?
What you have to do is different in the way you write the code for the first question vers the second question
I am trying to stop the process after a certain amount of time. For instance, if I am taking a picture every hour, I would, for instance, want to stop after 48 hrs. This would be 48 iterations of the program. Not sure if BS2 can do something like that. May have to learn spin
fsb
OR
Something like this
I hope this helps
I will try this
fsb
If you need help with this Please ask and I will help you as much as I can how ever I do not have one set to test the code right now but it is not hard to do
This is some thing a little while ago so might give you idea what can be done
For the DS1302 to save your data all you need a 1 MFD super cap to do this with this set up it would hold you data for more than a week
Here is where you buy a MFD super cap
http://www.allelectronics.com/make-a-store/item/CBC-17/1-FARAD-5.5-VOLT-SUPER-CAP//1.html