go_away

Author Topic: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?  (Read 1385 times)

0 Members and 1 Guest are viewing this topic.

Offline jackpTopic starter

  • Jr. Member
  • **
  • Posts: 13
  • Helpful? 0
WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« on: May 02, 2010, 01:05:38 AM »
Hi,

I think there's a bug in the documentation for WebbotLib in the timer.h section, specifically for clockGetus().  It states that the TICK_COUNT returned will wrap...

           "...every 0xffffffff or 429,4967,295 microseconds ie every 429.5 seconds or every 7 minutes."

But I think it's meant to state every 71 minutes right? 

BTW, this is important to me because wrapping every 71 min is ok for my timing sensitive application but 7 min may not be.

Thanks
Jack


Offline Cristi_Neagu

  • Robot Overlord
  • ****
  • Posts: 165
  • Helpful? 5
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #1 on: May 02, 2010, 03:21:36 AM »
Apparently...yeah....  0xffffffff is 71.58 minutes.... Interesting... I always took 7.1 minutes for granted :D

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #2 on: May 02, 2010, 04:29:06 PM »
From what Webbot has told me before, even though the clock is wrapping around in the background, the effect is not seen in the user's code. IE, you don't have to worry about it; the lib fixes the time if it wraps.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,121
  • Helpful? 108
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #3 on: May 02, 2010, 05:32:07 PM »
You can "always" subtract values from two calls to 'clockGetus'. The clock code has been written explicitly to allow this to work around the 'wrap around' end points ie when the clock goes from 0xffffffff back to 0x0000000.

ie you can use it, for ever, to detect a delay of say 1 minute  - your code wont suddenly break due to the clock itself wrapping around.

The only time it will fail is if you are trying to measure an elapsed period greater than the total clock period - ie between two times: time 1 and time 2 irrespective of when 'switch on' happened.

Version 1 of the lib had this set as 7 min but I think it is now 71 min (cant remember without re-checking the code!). So what kind of delay are you trying to measure that would be longer than this - and why?
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline jackpTopic starter

  • Jr. Member
  • **
  • Posts: 13
  • Helpful? 0
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #4 on: May 02, 2010, 06:43:31 PM »
Thanks for replies and the clarification.  Good point about the wrap and delays as long as it is < 7 (or 71 min). 

It's actually not measuring incremental delay that may be my issue.  I'm measuring total time elapsed and with 71 minutes, I may not need to worry about wrapping (my board may not be on for that long) but if 7 min I have to track the number of times it wraps to compute total time elapsed.

BTW, if I wanted to use WebbotLib to measure when the wrap occurs, do I just set up my callback via timerOverflowAttach( g_heartbeat, &myCB, pMyData )?

Thanks
Jack

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,121
  • Helpful? 108
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #5 on: May 02, 2010, 08:05:28 PM »
Well its every 0xFFFFFFFF uS ie 4294967295 us
= about 71 minutes
If you want to trap the wrap around then do something like
Code: [Select]

TICK_COUNT prev;

TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
 prev = loopStart; // Store start value for the clock
 .. rest of your code ..

}

TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){
  if( loopStart < prev ){
     // The clock has wrapped around
     
 }
 prev = loopStart;
 .. rest of your code ..
}


NB You cannot do it via a timer overflow as per question.
Coz the timer actually overflows a lot more frequently and this is used to update the clock.
So the clock is like a 'super prescaled' version of your crystal frequency.



Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #6 on: May 02, 2010, 08:12:25 PM »
Really though, if you want time keeping in the magnitude of tens of minutes to hours, isn't a RTC add-on a better option?

Offline jackpTopic starter

  • Jr. Member
  • **
  • Posts: 13
  • Helpful? 0
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #7 on: May 03, 2010, 01:29:17 AM »
Webbot: Makes sense. Timer's only 16-bits max so loop wrap code at every appControl call is better way to detect wrapping.

Madsci1016: Real Time Clock may be overkill but I'll take a look.

Thanks
Jack

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #8 on: May 05, 2010, 11:07:48 PM »
isn't a RTC add-on a better option?
Is there a chip for this?

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #9 on: May 06, 2010, 06:01:07 AM »
isn't a RTC add-on a better option?
Is there a chip for this?

Sparkfun sells one, I will link it when I get to my computer. I think its i2c and can run for decades without external power.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,121
  • Helpful? 108
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #11 on: May 06, 2010, 11:04:00 AM »
Thanks for posting the link.

Is this a hint that there will be a webbotlib driver fo it? ;-)

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,121
  • Helpful? 108
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #12 on: May 06, 2010, 12:04:46 PM »
Thanks for posting the link.

Is this a hint that there will be a webbotlib driver fo it? ;-)

 :-\
Since its standard I2C stuff then it should be programmable in WebbotLib already.

To save me $20 it would be good for someone who buys one to write the first attempt - I can then WebbotLib'ify it and add it to Project Designer for easier use.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #13 on: May 06, 2010, 12:21:54 PM »
Sooooo whats the advantage of an external RTC for a robot? (beyond the timers already on the Axon)

Offline madsci1016

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,450
  • Helpful? 43
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #14 on: May 06, 2010, 12:31:58 PM »
Well, your robot would always know the absolute time of day instead of just the relative time since it was turned on.

And like webbot was saying subtracting calls is fixed, but if you were just recording events or timing something larger then the 71 minute timer wrap then you would have to use a rtc.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,121
  • Helpful? 108
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #15 on: May 06, 2010, 12:38:33 PM »
Good examples would be:
- if you are creating log info then you could time stamp with the correct year, month, day, minute, seconds
- if you are using SDcards in WebbotLib then I could place a proper date/time stamp on each file for last modified date
- an RTC provides a timer that NEVER wraps around back to zero and so could measure delays greater than, say, 71 minutes - even between reboots
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #16 on: May 06, 2010, 08:02:55 PM »
Whats the error buildup rate of an RTC? I glanced through the datasheet, didn't see anything. Probably depends on the external crystal and thermal aspects of the environment . . .

Even with a 0.1% error rate, thats 10 minutes a week, or 8 hours/year . . .

I'd probably need a 0.01% accuracy to do things I have in my head . . . and thats 40 minutes per year error.

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
Re: WebbotLib: clockGetus() wrap every 7.1 or 71 minutes?
« Reply #17 on: May 06, 2010, 09:46:49 PM »
Whats the error buildup rate of an RTC? I glanced through the datasheet, didn't see anything. Probably depends on the external crystal and thermal aspects of the environment . . .

Even with a 0.1% error rate, thats 10 minutes a week, or 8 hours/year . . .

I'd probably need a 0.01% accuracy to do things I have in my head . . . and thats 40 minutes per year error.


I have this on my nightstand. It uses the same chip as the SF module. I bought it 2 months ago and so far I did not miss any meeting. I don't know exactly the accuracy, but I used my PC to set it up and they are still "perfectly" synchronized. Definitely less than 0.1% accuracy anyway.

Chelmi.

 


Get Your Ad Here