Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp 2 timing — Parallax Forums

Basic Stamp 2 timing

R0y4LR0y4L Posts: 23
edited 2009-08-31 09:54 in BASIC Stamp
Hello Basic Stamp geeks

So, I have wrote a clock script. Feeling so proud of myself, even though it is such a simple thing. But I have a problem. To time my clock I use PAUSE 1000, from what I know this is a 1 second. But I have noticed that my clock gets 3 minutes behind after one hour. Hmmmmm...could any one help me out with this problem.

Thanks

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit: www.vbnoobs.co.uk

Comments

  • phil kennyphil kenny Posts: 233
    edited 2009-08-29 18:33
    If you have any other statements in the program, other than PAUSE 1000,
    they will take appreciable time to execute. In order to take this extra time
    into account try reducing the PAUSE from 1000 to 950. This should get
    you better timing accuracy, but most likely it will still be off by a little bit.

    phil
  • stamptrolstamptrol Posts: 1,731
    edited 2009-08-29 18:41
    While the actual PAUSE command is fairly accurate, what it dosen't take into account is the extra time to go through the other program steps in your program.

    Three minutes is about ( 3 * 60 * 1000) mSec = 180,000 mSec. So,in one hour, out of a total of 3,600,000 mSec you're out about 5%; not too bad really.

    You can play with your Pause value (maybe down to 950 or so )and do another test.

    Or for $5 - $10 get a DS1302 timekeeper chip and be right on.

    Cheers

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • R0y4LR0y4L Posts: 23
    edited 2009-08-29 23:16
    Thank you for such quick responses [noparse]:)[/noparse]

    However, after some a bit more testing of my clock code I have noticed that my calculations weren't 100% correct. I decided to do a smaller range test to see how behind my code gets. I have discovered that my clock time gets behind 2 mins in 10 min period. So in one hour I get about 720.000 mS of lost time. That is 20%. And I think this is a lot. I was just wondering/thinking about a calculation/formulae that would allow me to calculate how many mS does that 20% take. If, I get the result in mS, then I can divide it by 6,meaning ill get a result that shows me how mS I am off in 10 min period. Then divide the result in mS by 10, and ill get a result of how many mS I am off in one min. Take the result away from 1000 mS and i should have my offset. I hope this doesn't sound too confusing. I think, I can imagine the process in my head. Do yous think I am on some kind of right track? I'd rather calculate everything myself too [noparse]:)[/noparse] I am intrigued about the idea of reducing the time in mS in my code to allow other parts of code to be executed in that 1000 mS range.

    Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit: www.vbnoobs.co.uk
  • R0y4LR0y4L Posts: 23
    edited 2009-08-29 23:32
    Hurray!! I have finally worked it out [noparse]:)[/noparse] I have found that the correct time in mS for my code is about 810 mS = 1S...now my clock does not get behind or go in front [noparse]:)[/noparse] Thanks for making me think like a clock [noparse]:)[/noparse] problem solved. I did notice that, I will have to change the time in mS if i wrote more code (which I am going to do anyway) [noparse]:)[/noparse]

    Thank you

    I guess thread can be closed. Or if people have any more questions relating to this please leave it open. Maybe any one has more ways of calculating time using PAUSE?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Visit: www.vbnoobs.co.uk
  • phil kennyphil kenny Posts: 233
    edited 2009-08-29 23:35
    As Tom pointed out just reduce the PAUSE value by the percentage your
    actual time is off as a first approximation to the correction. Refine it as
    you make more measurements.

    In this case, drop it by 20 percent or 200. It then becomes PAUSE 800.

    phil
  • MichelBMichelB Posts: 154
    edited 2009-08-31 09:54
    With LcdTimer.bs2 from Smart Sensors I obtained + 1 second / hour· at 26° C with a PAUSE = 979.
Sign In or Register to comment.