Shop OBEX P1 Docs P2 Docs Learn Events
Calculating elapsed time — Parallax Forums

Calculating elapsed time

StevezilaStevezila Posts: 35
edited 2009-09-12 03:14 in BASIC Stamp
·I'm trying to figure out how to best to keep track of the run time of several heating units. I have a real time clock, a DS1307 and am using the Stampworks pgm SW21-EX33-DS1307-AMPM.bs2. When·a heating unit turns on I can reference the DS1307 and write to eeprom and when it turns off I can reference the RTC again. If I take the time the unit stops and subtract it from the unit started I get elapsed time. and if I store the result in a different place, I don't have to worry about overwriting it when the unit runs again, and then add to it the result of the next run time. Big trouble here is that I just don;'t know how to do the math to and come away with numbers that make sense. It might be a little if I were to use a 24 hour format instead of 12 but I would rather not. I need to keep track of run time of the units seperately but if I can get it to work for one I can reapply for the rest of them. Can someone Please help me atleast get started·with the time calculation?
freaked.gif

Thanks

Comments

  • Larry~Larry~ Posts: 242
    edited 2009-09-11 21:48
    If it has to do with math you go here (any arguments)
    http://www.emesystems.com/BS2index.htm

    he has a julian date setup look for this I think it will store seconds min,hour,days,weeks,months,years for a number of years in the 65565 limit of the stamp
    I have been going here for years and still don't understand 50% of his stuff but I keep comming back.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2009-09-12 03:14
    On the DS1307 has a HALT command

    In part this is what the data sheet say about this

    Bit 7 of Register 0 is the clock halt (CH) bit. When this bit is set to 1, the oscillator is disabled. When cleared to 0, the oscillator is enabled.

    An easy way to do this to start and stop the clock for elapsed time with a Optic Sensor hook to the compressor·contactor

    I think you are going to have problem with doing more than one AC unit on a Basic Stamp what if more than one running at the same time

    unless you have way of showing more than one unit at a time

    This is how you do this with a DS1302 time chip

    You know that you can save data in the DS1307 chip as well

    You do have to put the Halt_clock Routine in a loop to keep the clock stop and you only need the Restart_clock Routine ·once

    Halt_clock:
    ·reg = $80··································· ' Point to register 80h
    ·ioByte = %10000000·························· ' Set Clock Halt Bit
    ·GOSUB RTC_Out······························· ' Send Command
    ·RETURN


    ·· ·Restart_clock:
    ·reg = $80··································· ' Point to register 80h
    ·ioByte = %0000000··························· ' starts the clock by clearing the Clock Halt bit and clears the minutes to "00"
    ·GOSUB RTC_Out······························· ' Send Command
    ·RETURN


    One note and that is when you restart the clock the seconds start at 00 and not what it had show how ever if you put a 1

    ioByte = %0000001 then it would start at 01· as long as you do not put a 1 in the last slot to the left %10000000··you will·be alright··························

    I hope this helps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them smile.gif

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 9/12/2009 3:41:09 AM GMT
Sign In or Register to comment.