Recent

Author Topic: Timer interval increase (SOLVED)  (Read 15211 times)

ziocharly

  • New Member
  • *
  • Posts: 12
Timer interval increase (SOLVED)
« on: May 04, 2015, 11:19:30 am »
My application on Raspberry PI use TTimer component to update continuously the status of my user interface
(approximately each 200 mSec.).

The strange behavior is that the time interval grows (about 10 mSec. each hour) when the application remains active...
I also tried to use FPTimer (cThreads), but the problem still remain...

Note that, under Windows, everything works perfectly,
without any drift in the time interval set.

RBPI hardware > card rev. 1 ver.2
RBPI OS > Debian Raspbian GNU V.7.8 Wheezy 
Lazarus > 1.2.4  (23.02.2015)
FPC > 2.6.4 (SNV Rev. 43696)

Any suggestion is appreciated !

« Last Edit: May 15, 2015, 10:56:53 pm by ziocharly »

dogriz

  • Full Member
  • ***
  • Posts: 126
Re: Timer interval increase
« Reply #1 on: May 04, 2015, 12:55:21 pm »
Raspberry Pi does not have Real Time Clock (RTC), so I guess that can be the source of your problem.
FPC 3.2.2
Lazarus 2.2.4
Debian x86_64, arm

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Timer interval increase
« Reply #2 on: May 04, 2015, 01:27:43 pm »
You can create/buy your own RTC module for Rasperry.

ziocharly

  • New Member
  • *
  • Posts: 12
Re: Timer interval increase
« Reply #3 on: May 04, 2015, 02:29:20 pm »
Thanks for fast reply !

     perhaps I have not explained well,
I'm aware that real time is missing on RBPI,
I'm also aware of additional daughter card that implements this functionality.

My consideration/problem concerns only the interval of the TTimer,
which continues to be incremented, without any possibility of adjust !

I am not worried about the scan rate frequency, but its continuous increment:
one day after power up the application, the time, set to 200 msec.,
becomes 2 seconds !

This is unacceptable...


Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Timer interval increase
« Reply #4 on: May 04, 2015, 03:45:04 pm »
How about you create a thread which checks if TTimer.Interval is in required value and if it is not, adjust it accordingly.

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Timer interval increase
« Reply #5 on: May 04, 2015, 04:03:50 pm »
How about you create a thread which checks if TTimer.Interval is in required value and if it is not, adjust it accordingly.
That would only work if the TTimer.Interval value really does increase. But if that's the case you could also just set the Interval to 200 each time it's executed.

If the TTimer.Interval stays at 200 and the real interval is about 2 seconds after a day... that's a real problem.

@ziocharly, What happens if the TTimer is disabled and enabled every hour? Does the interval increase then too?

ziocharly

  • New Member
  • *
  • Posts: 12
Re: Timer interval increase
« Reply #6 on: May 04, 2015, 04:24:05 pm »
@Cyrax
The strangest thing is that even if you change the time.interval value
does not change the real time interval, or better,
is possible only increase the value but not reduce/fix it !

 @rvk
One of the first things that I tried was to setup again the interval value,
in each ontimer cycle (or when needed) but it does not work!

Last attempt of today:
- removed the timer from the form
- create a new TTimer runtime

  TimerScan:= TTimer.Create(self);
  TimerScan.OnTimer:= @TimerScanTimer;
  TimerScan.Interval:= 200;   

- destroy my TTimer, if the interval it's not ok
- finally TimerScan.free onClose.

Also in this way still does NOT work !
No errors but the interval of new created timer still the same (long) !

 >:( >:( >:(

I almost sold my chances...

There is no possible solution to launch an 'event' on a regular time interval ???

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: Timer interval increase
« Reply #7 on: May 04, 2015, 04:29:41 pm »
What happens if you create a new timer with, say, 2000 ms? Does it take 20 seconds after a day? Or 10 x 10ms (=100ms) more after an hour or so?

What you should find out, is, if another interval with a new timer takes proportional more time then your original. If so, then there must be something really screwed up internally with the TTimer (or depended underlying technology) on RasPi.

ziocharly

  • New Member
  • *
  • Posts: 12
Re: Timer interval increase
« Reply #8 on: May 04, 2015, 04:49:32 pm »
I've to try this suggestion.

After the first trials, most frequent is the 'onTimer' call,
before the defect occurs and the interval increase...

...but it is possible that no one has noticed this behavior !

avra

  • Hero Member
  • *****
  • Posts: 2514
    • Additional info
Re: Timer interval increase
« Reply #9 on: May 05, 2015, 12:07:05 am »
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Timer interval increase
« Reply #10 on: May 05, 2015, 12:25:33 am »
Any suggestion is appreciated !
http://wiki.freepascal.org/EpikTimer
Its not equivalent.
Epik timer does not support intervals can only measure (fairly) accurately time intervals but it is not a replacement for ttimer. It needs work before it can replace ttimer.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

dogriz

  • Full Member
  • ***
  • Posts: 126
Re: Timer interval increase
« Reply #11 on: May 05, 2015, 07:32:54 am »
What is the system load at app runtime?
FPC 3.2.2
Lazarus 2.2.4
Debian x86_64, arm

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Timer interval increase
« Reply #12 on: May 05, 2015, 10:00:31 am »
Why not compare TTime difference given by Now() function? You can run TTimer with interval such as 50ms then. In long term it will be 100% as accurate as the system time is.

ziocharly

  • New Member
  • *
  • Posts: 12
Re: Timer interval increase
« Reply #13 on: May 05, 2015, 10:36:03 am »
@avra
as taazz post, the epiktimer don't have onTimer event
that fireup my update procedure, with configured interval...

@dogriz
the app must read cyclically an external device,
connected through ethernet and update the GUI.
The entire whole process is performed in 20 to 30 msec.

@User137
I already use, inside onTimer event, the instruction Now
in order to check the real interval performed:

procedure TFormMain.TimerRead(Sender: TObject);
begin

  Elapsed:= MilliSecondsBetween(Now, Interval);
  StatusBar.Panels[0].Text:= 'Timer rate : '+ IntToStr(Elapsed) + ' mSec.';
   
  if Elapsed > myScanRate then
  begin
     ... my GUI update ...
  end;

  Interval:= Now;

end;

The problem is that also the TimerRead (50 mSec. timer),
lauched only to check the time Elapsed (with now istruction),
increase his interval !

It would be enough have the launch of one procedures
in a regular interval, that does not change over time ...
 
As already confirmed this issue appears only on RBPI en environment.
Really strange !!!





dogriz

  • Full Member
  • ***
  • Posts: 126
Re: Timer interval increase
« Reply #14 on: May 05, 2015, 10:56:28 am »
Did you try this:

procedure TFormMain.TimerRead(Sender: TObject);
begin
  TimerRead.Enabled := False;
  //do your GUI update and other stuff
    TimerRead.Enabled := True;
end;
FPC 3.2.2
Lazarus 2.2.4
Debian x86_64, arm

 

TinyPortal © 2005-2018