Scott4

02-16-2010, 03:28 AM

Can someone point me to a routine to compute elapsed time to use with·one of the·clock chips that presents time in BCD format? -Scott

View Full Version : Elapsed time routine for use with clock clip?

Scott4

02-16-2010, 03:28 AM

Can someone point me to a routine to compute elapsed time to use with·one of the·clock chips that presents time in BCD format? -Scott

Mike Green

02-16-2010, 03:39 AM

In case no one has an example of exactly what you want, how about describing specifically what you want to do including which clock chip you want to use and the range of elapsed time you want to deal with. Also mention how you'd like to deal with time that crosses a day boundary.

Scott4

02-16-2010, 04:18 AM

Thanks for the inquiry, Mike. I am reading the "DS1302 Timekeeping Chip". When I start my engine, I want to record the time. The chip would output hours-tens digit, hours-ones digit, minutes-tens digit and minutes-ones digit as I understand it. When I turn off the engine, I want to compute the elapsed time in hours and minutes.

I am not concerned about crossing a day boundary as I will not be flying more than 4 hours or at night. So I am just looking to determine the hours and minutes from start to stop.· -Scott

Stop········ 1:30 pm

Start·······11:59 am

----------------------

··············· 1:31 elapsed time

I am not concerned about crossing a day boundary as I will not be flying more than 4 hours or at night. So I am just looking to determine the hours and minutes from start to stop.· -Scott

Stop········ 1:30 pm

Start·······11:59 am

----------------------

··············· 1:31 elapsed time

Scott4

02-16-2010, 04:22 AM

p.s. I can do this the "hard" way, I just thought someone had a clever way of doing it. -Scott

Mike Green

02-16-2010, 04:47 AM

My own personal bias would be to read the minutes and hours bytes and convert them to binary minutes in a word (in a subroutine). You'd call this subroutine at the beginning of the interval and at the end. Computing the elapsed time in minutes would be simple (just subtract ... if negative, add 24 * 60). It's relatively easy to format minutes into hours and minutes.

To convert two BCD digits (like the hours and minutes bytes) to binary do:

binary = (BCD >> 4) * 10 + (BCD & $F)

Obviously, if you have the hours in binary, you multiply by 60 to get minutes which you add into the minutes in binary to get a time of day in minutes.

Post Edited (Mike Green) : 2/15/2010 8:55:02 PM GMT

To convert two BCD digits (like the hours and minutes bytes) to binary do:

binary = (BCD >> 4) * 10 + (BCD & $F)

Obviously, if you have the hours in binary, you multiply by 60 to get minutes which you add into the minutes in binary to get a time of day in minutes.

Post Edited (Mike Green) : 2/15/2010 8:55:02 PM GMT

Steve Andrues

03-02-2010, 12:14 PM

I built a real nice timer using the DS1302.· The down-and-dirty-loose-and-sloopy fix is to set the clock registers to January 1, 2010 at midnight.· Now your timer is counting days,hours, minutes, and seconds from zero.· The only drawback is if you go past 6 days, 23 hours, 59 minutes, and 59 seconds then you need some more elaborate math.· Since you are going for only a few hours this should work just fine.· Converting to BCD is just a math routine.· If this is going on a car you can start it by tapping the oil pressure switch.· It is a switch to ground and should work just fine with a Stamp.· This sounded like it may be going on an aircraft in which case you may not atach ANYTHING to the electrical system without the express blessing of the FAA in the form of a Form 337.· Good luck.· I'll post code if you would like.