Re: Timer() loses time

Started by Chris May 19, 2004
Neil,

Frank is correct, I misspoke. Com3 will not interfere with the RTC.
I was thinking of something else.

Are you perhaps incrementing your Time variable with a "rounded"
Timer result? Doing so would cause the loss of time you are seeing.

Chris

----- Original Message -----
From: "Neil Jepsen" <>
To: <>
Sent: Wednesday, May 19, 2004 4:00 PM
Subject: Re: [BasicX] Timer() loses time > Thanks Chris.
> Specifically, when and how?
> neil
>
> Chris wrote:
>
> > Com3 RX and TX events have the same effect on the RTC as Pulseout.
> > During a Com3 RX or TX event the RTC is not permitted to tick which
> > will cause the loss of time you are seeing.
> >
> > Moving your Com3 devices to Com1 would be a simple fix.
> >
> >
> > Chris
> >
> >
> >
> > ----- Original Message -----
> > From: "Neil Jepsen" <>
> > To: <>
> > Sent: Wednesday, May 19, 2004 2:10 PM
> > Subject: Re: [BasicX] Timer() loses time
> >
> >
> > > Hi Tom
> > > I can post the code if you wish. Basically, its a
> > > scoreboard for indoor basketball. The code uses timer () for the RTC
> > > reference. Timer is compared several times throughout the code, and
used
> > > to time various functions. Timer is never set at any point. Nor do I
use
> > > any of the functions (such as pulseout) listed in my last post. There
is
> > > a lot of serial coms (all com3) to the main LED display via a RS485
> > > device, and there are 2 serial LCDs which are updated each loop. For
> > > the life of me I can't see a good reason why the RTC should lose time.
> > > I'm just cutting and pasting code now to identify where the gremilin
is.
> > > neil
> > >
> > > Tom Becker wrote:
> > >
> > > > > ... the RTC loses about 5 seconds in every minute...
> > > >
> > > > That's an obviously serious error that is not typical of the
machine.
> > > > What does your code do?
> > > >
> > > >
> > > > Tom
> > > >
> > > >
> > > >
> > > > Tom Becker
> > > > --... ...--
> > > > www.RighTime.com
> > > > The RighTime Clock Company, Inc., Cape Coral, Florida USA
> > > > +1239 540 5700
> > > >
> > > >
> > > > *
> > > >
> >
<http://rd.yahoo.com/SIG9glggoh/M)5196.4901138.6071305.3001176/D=groups
> >
/S06554205:HM/EXP84938090/A!28215/R=0/SIGse96mf6/*http://companio
> > n.yahoo.com>
> > > >
> > > >
> > > >
> > > >
> >
> > > > *>.
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > > >.
> >
> > Yahoo! Groups Links >
>





> Are you perhaps incrementing your Time variable with a
> "rounded" Timer result? Doing so would cause the loss of time
> you are seeing.

Five seconds lost in a minute is an 8% slowdown; that might be hard to
blame on rounding.

Can we see your code? Tom
Tom Becker
--... ...--
www.RighTime.com
The RighTime Clock Company, Inc., Cape Coral, Florida USA
+1239 540 5700


You could add a third variable to avoid multiple Cint statements.
Save some uS in process time.

eg:
dim p as integer ' ( decl as public global var before main )
dim ntimer as integer (declare as local variable)
nTimer = Cint(timer)
if (nTimer >=p) then
p = nTimer + 1
game_time=game_time - 1 ' bump clock
end if

Rob

--- In , Neil Jepsen <njepsen@i...> wrote:
> Chris and Frank
> Thanks guys. I really appreciate your
input and
> total frankness here ( excuse the pun..not intended).
> Chris...you have hit on the problem almost exactly, which I tumbled
to
> yesterday, as soon as I realised that timer was not losing time, my
> "game_time" was incorrect.. I've repeated the offending code below,
and
> the fix. Hard to see how I could be so dumb!
>
> I was using this code to generate a 1 second clock, which of course
is
> flawed, and loses time every loop.
>
> dim p as single ' ( decl as public global var before main)
> if (timer>=p) then
> p = timer + 1.0
> game_time=game_time - 1 ' bump clock each second
> end if
>
> What does work is:
>
> dim p as integer ' ( decl as public global var before main )
> if (Cint(timer)>=p) then
> p =Cint( timer) + 1
> game_time=game_time - 1 ' bump clock
> end if >
> neil > Chris wrote:
>
> > Neil,
> >
> > Frank is correct, I misspoke. Com3 will not interfere with the
RTC.
> > I was thinking of something else.
> >
> > Are you perhaps incrementing your Time variable with a "rounded"
> > Timer result? Doing so would cause the loss of time you are
seeing.
> >
> > Chris
> >
> > ----- Original Message -----
> > From: "Neil Jepsen" <njepsen@i...>
> > To: <>
> > Sent: Wednesday, May 19, 2004 4:00 PM
> > Subject: Re: [BasicX] Timer() loses time
> >
> >
> > > Thanks Chris.
> > > Specifically, when and how?
> > > neil
> > >
> > > Chris wrote:
> > >
> > > > Com3 RX and TX events have the same effect on the RTC as
Pulseout.
> > > > During a Com3 RX or TX event the RTC is not permitted to tick
which
> > > > will cause the loss of time you are seeing.
> > > >
> > > > Moving your Com3 devices to Com1 would be a simple fix.
> > > >
> > > >
> > > > Chris
> > > >
> > > >
> > > >
> > > > ----- Original Message -----
> > > > From: "Neil Jepsen" <njepsen@i...>
> > > > To: <>
> > > > Sent: Wednesday, May 19, 2004 2:10 PM
> > > > Subject: Re: [BasicX] Timer() loses time
> > > >
> > > >
> > > > > Hi Tom
> > > > > I can post the code if you wish. Basically,
its a
> > > > > scoreboard for indoor basketball. The code uses timer ()
for
> > the RTC
> > > > > reference. Timer is compared several times throughout the
code, and
> > used
> > > > > to time various functions. Timer is never set at any point.
Nor do I
> > use
> > > > > any of the functions (such as pulseout) listed in my last
post.
> > There
> > is
> > > > > a lot of serial coms (all com3) to the main LED display via
a RS485
> > > > > device, and there are 2 serial LCDs which are updated each
> > loop. For
> > > > > the life of me I can't see a good reason why the RTC should
lose
> > time.
> > > > > I'm just cutting and pasting code now to identify where the
gremilin
> > is.
> > > > > neil
> > > > >
> > > > > Tom Becker wrote:
> > > > >
> > > > > > > ... the RTC loses about 5 seconds in every minute...
> > > > > >
> > > > > > That's an obviously serious error that is not typical of
the
> > machine.
> > > > > > What does your code do?
> > > > > >
> > > > > >
> > > > > > Tom
> > > > > >
> > > > > >
> > > > > >
> > > > > > Tom Becker
> > > > > > --... ...--
> > > > > > GTBecker@R... www.RighTime.com
> > > > > > The RighTime Clock Company, Inc., Cape Coral, Florida USA
> > > > > > +1239 540 5700
> > > > > >
> > > > > >
> > > > > > *
> > > > > >
> > > >
> >
<http://rd.yahoo.com/SIG9glggoh/M)5196.4901138.6071305.3001176/D=
groups
> > > >
>
> /S06554205:HM/EXP84938090/A!28215/R=0/SIGse96mf6/*http://
companio
> > > > n.yahoo.com>
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > >
> > ------------------------------
------
> > > > > > *>.
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > >.
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > > >.
> >
> >





> if (Cint(timer)>=p) then
> p =Cint( timer) + 1
> game_time=game_time - 1 ' bump clock
> end if

FWIW, my experience suggests that a period timer like a game clock is
best kept as a difference from a system clock. When you need to refresh
the clock display, the game clock countdown value is simply
(PeriodEndTime-Now).

When you start the period timer, add the period to the current time and
start displaying the difference between that sum and the current time.
When you pause the period timer, just store the current difference; when
restarted, add that difference to the current time and resume
displaying. This method also allows fractional-seconds period
resolution. Tom
Tom Becker
--... ...--
www.RighTime.com
The RighTime Clock Company, Inc., Cape Coral, Florida USA
+1239 540 5700




Whilst I appreciate the elegance of getting the BX24 to do as much
as possible I think there are times when adding another chip is a
far better solution. A real time clock (via SPI) or a bit of
external logic + clock to provide 1 pulse per second (or faster)
would make Bob's scoreboard project less reliant on internal timing.
This in turn makes it easier to use code without worrying about
unwanted timing effects.

Just a thought

Pat



> ... A real time clock (via SPI) or a bit of external logic + clock to
provide 1 pulse per second (or faster) would make Bob's scoreboard
project less reliant on internal timing.

I disagree, Pat. An SPI device requires polling which is what he's
essentially doing now: waiting for the RTC to change by one second to
tick his clock by one second. The BX-24 can make a good clock. Tom
Tom Becker
--... ...--
www.RighTime.com
The RighTime Clock Company, Inc., Cape Coral, Florida USA
+1239 540 5700


Chris and Frank
Thanks guys. I really appreciate your input and
total frankness here ( excuse the pun..not intended).
Chris...you have hit on the problem almost exactly, which I tumbled to
yesterday, as soon as I realised that timer was not losing time, my
"game_time" was incorrect.. I've repeated the offending code below, and
the fix. Hard to see how I could be so dumb!

I was using this code to generate a 1 second clock, which of course is
flawed, and loses time every loop.

dim p as single ' ( decl as public global var before main)
if (timer>=p) then
p = timer + 1.0
game_time=game_time - 1 ' bump clock each second
end if

What does work is:

dim p as integer ' ( decl as public global var before main )
if (Cint(timer)>=p) then
p =Cint( timer) + 1
game_time=game_time - 1 ' bump clock
end if
neil Chris wrote:

> Neil,
>
> Frank is correct, I misspoke. Com3 will not interfere with the RTC.
> I was thinking of something else.
>
> Are you perhaps incrementing your Time variable with a "rounded"
> Timer result? Doing so would cause the loss of time you are seeing.
>
> Chris
>
> ----- Original Message -----
> From: "Neil Jepsen" <>
> To: <>
> Sent: Wednesday, May 19, 2004 4:00 PM
> Subject: Re: [BasicX] Timer() loses time > > Thanks Chris.
> > Specifically, when and how?
> > neil
> >
> > Chris wrote:
> >
> > > Com3 RX and TX events have the same effect on the RTC as Pulseout.
> > > During a Com3 RX or TX event the RTC is not permitted to tick which
> > > will cause the loss of time you are seeing.
> > >
> > > Moving your Com3 devices to Com1 would be a simple fix.
> > >
> > >
> > > Chris
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: "Neil Jepsen" <>
> > > To: <>
> > > Sent: Wednesday, May 19, 2004 2:10 PM
> > > Subject: Re: [BasicX] Timer() loses time
> > >
> > >
> > > > Hi Tom
> > > > I can post the code if you wish. Basically, its a
> > > > scoreboard for indoor basketball. The code uses timer () for
> the RTC
> > > > reference. Timer is compared several times throughout the code, and
> used
> > > > to time various functions. Timer is never set at any point. Nor do I
> use
> > > > any of the functions (such as pulseout) listed in my last post.
> There
> is
> > > > a lot of serial coms (all com3) to the main LED display via a RS485
> > > > device, and there are 2 serial LCDs which are updated each
> loop. For
> > > > the life of me I can't see a good reason why the RTC should lose
> time.
> > > > I'm just cutting and pasting code now to identify where the gremilin
> is.
> > > > neil
> > > >
> > > > Tom Becker wrote:
> > > >
> > > > > > ... the RTC loses about 5 seconds in every minute...
> > > > >
> > > > > That's an obviously serious error that is not typical of the
> machine.
> > > > > What does your code do?
> > > > >
> > > > >
> > > > > Tom
> > > > >
> > > > >
> > > > >
> > > > > Tom Becker
> > > > > --... ...--
> > > > > www.RighTime.com
> > > > > The RighTime Clock Company, Inc., Cape Coral, Florida USA
> > > > > +1239 540 5700
> > > > >
> > > > >
> > > > > *
> > > > >
> > >
> <http://rd.yahoo.com/SIG9glggoh/M)5196.4901138.6071305.3001176/D=groups
> > >
> /S06554205:HM/EXP84938090/A!28215/R=0/SIGse96mf6/*http://companio
> > > n.yahoo.com>
> > > > >
> > > > >
> > > > >
> > > > >
> > >
>
> > > > > *>.
> > > > >
> > > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > >.
> > >
> > >
> >
> >
> >
> >
> >
> > >.





Neil,

In your code: Messages Messages Help
Reply | Forward | View Source | Unwrap Lines

Message 16268 of 16290 | Previous | Next [ Up Thread ] Message
Index
Msg #
From: Neil Jepsen <njepsen@i...>
Date: Thu May 20, 2004 4:46 pm
Subject: Re: [BasicX] Timer() loses time

ADVERTISEMENT
Chris and Frank
Thanks guys. I really appreciate your input and
total frankness here ( excuse the pun..not intended).
Chris...you have hit on the problem almost exactly, which I tumbled to
yesterday, as soon as I realised that timer was not losing time, my
"game_time" was incorrect.. I've repeated the offending code below, and
the fix. Hard to see how I could be so dumb!

I was using this code to generate a 1 second clock, which of course is
flawed, and loses time every loop.

dim p as single ' ( decl as public global var before main)
if (timer>=p) then
p = timer + 1.0
game_time=game_time - 1 ' bump clock each second
end if

What does work is:

dim p as integer ' ( decl as public global var before main )
if (Cint(timer)>=p) then
p =Cint( timer) + 1
game_time=game_time - 1 ' bump clock
end if

there is still a problem if the timer increments between the two
references to "timer". I suggest something like:

dim p as integer ' ( decl as public global var before main )
dim t as integer
t = Cint(timer)
if (t >= p) then
p = t + 1
game_time=game_time - 1 ' bump clock
end if

Admittedly the chances of such incrementing are small, but it might
make a difference in some other application. In this one it would
result in a one second loss.

Russ --- In , Neil Jepsen <njepsen@i...> wrote:
> Chris and Frank
> Thanks guys. I really appreciate your input
and
> total frankness here ( excuse the pun..not intended).
> Chris...you have hit on the problem almost exactly, which I tumbled to
> yesterday, as soon as I realised that timer was not losing time, my
> "game_time" was incorrect.. I've repeated the offending code below, and
> the fix. Hard to see how I could be so dumb!
>
> I was using this code to generate a 1 second clock, which of course is
> flawed, and loses time every loop.
>
> dim p as single ' ( decl as public global var before main)
> if (timer>=p) then
> p = timer + 1.0
> game_time=game_time - 1 ' bump clock each second
> end if
>
> What does work is:
>
> dim p as integer ' ( decl as public global var before main )
> if (Cint(timer)>=p) then
> p =Cint( timer) + 1
> game_time=game_time - 1 ' bump clock
> end if >
> neil > Chris wrote:
>
> > Neil,
> >
> > Frank is correct, I misspoke. Com3 will not interfere with the RTC.
> > I was thinking of something else.
> >
> > Are you perhaps incrementing your Time variable with a "rounded"
> > Timer result? Doing so would cause the loss of time you are seeing.
> >
> > Chris
> >
> > ----- Original Message -----
> > From: "Neil Jepsen" <njepsen@i...>
> > To: <>
> > Sent: Wednesday, May 19, 2004 4:00 PM
> > Subject: Re: [BasicX] Timer() loses time
> >
> >
> > > Thanks Chris.
> > > Specifically, when and how?
> > > neil
> > >
> > > Chris wrote:
> > >
> > > > Com3 RX and TX events have the same effect on the RTC as Pulseout.
> > > > During a Com3 RX or TX event the RTC is not permitted to tick
which
> > > > will cause the loss of time you are seeing.
> > > >
> > > > Moving your Com3 devices to Com1 would be a simple fix.
> > > >
> > > >
> > > > Chris
> > > >
> > > >
> > > >
> > > > ----- Original Message -----
> > > > From: "Neil Jepsen" <njepsen@i...>
> > > > To: <>
> > > > Sent: Wednesday, May 19, 2004 2:10 PM
> > > > Subject: Re: [BasicX] Timer() loses time
> > > >
> > > >
> > > > > Hi Tom
> > > > > I can post the code if you wish. Basically, its a
> > > > > scoreboard for indoor basketball. The code uses timer () for
> > the RTC
> > > > > reference. Timer is compared several times throughout the
code, and
> > used
> > > > > to time various functions. Timer is never set at any point.
Nor do I
> > use
> > > > > any of the functions (such as pulseout) listed in my last post.
> > There
> > is
> > > > > a lot of serial coms (all com3) to the main LED display via
a RS485
> > > > > device, and there are 2 serial LCDs which are updated each
> > loop. For
> > > > > the life of me I can't see a good reason why the RTC should
lose
> > time.
> > > > > I'm just cutting and pasting code now to identify where the
gremilin
> > is.
> > > > > neil
> > > > >
> > > > > Tom Becker wrote:
> > > > >
> > > > > > > ... the RTC loses about 5 seconds in every minute...
> > > > > >
> > > > > > That's an obviously serious error that is not typical of the
> > machine.
> > > > > > What does your code do?
> > > > > >
> > > > > >
> > > > > > Tom
> > > > > >
> > > > > >
> > > > > >
> > > > > > Tom Becker
> > > > > > --... ...--
> > > > > > GTBecker@R... www.RighTime.com
> > > > > > The RighTime Clock Company, Inc., Cape Coral, Florida USA
> > > > > > +1239 540 5700
> > > > > >
> > > > > >
> > > > > > *
> > > > > >
> > > >
> >
<http://rd.yahoo.com/SIG9glggoh/M)5196.4901138.6071305.3001176/D=groups
> > > >
> >
/S06554205:HM/EXP84938090/A!28215/R=0/SIGse96mf6/*http://companio
> > > > n.yahoo.com>
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > >
> >

> > > > > > *>.
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > >.
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > > >.
> >
> >




Yes I agree Tom, and that was what initially, I had I intended to do
BUT, the game time counts down not up, and of course timer() counts up.
Also, there are frequent times in the game, when the clock is stopped,
and I would have to save the stop and start times from timer() to take
care of these. In the end a cheap and nasty "game_time = game_time -1"
was a lot easier.
neil

Tom Becker wrote:

> > if (Cint(timer)>=p) then
> > p =Cint( timer) + 1
> > game_time=game_time - 1 ' bump clock
> > end if
>
> FWIW, my experience suggests that a period timer like a game clock is
> best kept as a difference from a system clock. When you need to refresh
> the clock display, the game clock countdown value is simply
> (PeriodEndTime-Now).
>
> When you start the period timer, add the period to the current time and
> start displaying the difference between that sum and the current time.
> When you pause the period timer, just store the current difference; when
> restarted, add that difference to the current time and resume
> displaying. This method also allows fractional-seconds period
> resolution. > Tom >
> Tom Becker
> --... ...--
> www.RighTime.com
> The RighTime Clock Company, Inc., Cape Coral, Florida USA
> +1239 540 5700 >
> *
> <http://companion.yahoo.com" target="_blank" rel="nofollow">http://rd.yahoo.com/SIG9qele3n/M)5196.4901138.6071305.3001176/D=groups/S06554205:HM/EXP85155270/A!28215/R=0/SIGse96mf6/*http://companion.yahoo.com >
>
> *>.