Announcement

Collapse
No announcement yet.

Miliseconds

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Scott Turchin
    replied
    Here's how I do it when I hit the atomic clock:

    Code:
    'Record your starttime In milliseconds
    Start = TimeGetTime()
    Tcp Open Port wPort At lserv As #hTcp TIMEOUT aTimeOut
    Do
      Tcp Recv #hTcp, 1600, buffer
      lpbuf = lpbuf + buffer
    Loop While Len(buffer)
    Tcp Close #hTcp
    lpbuf = Trim$(lpbuf, $LF)
    Replace $LF With $CRLF In lpbuf
    UTCTime = Trim$(lpbuf, $LF)
    Function = UTCTime
    Delay = TimeGetTime - Delay
    Stopp = TimeGetTime()
    
    'Convert your Atomic time into a SYSTEMTIME structure ST
    'FILETIME returns 100's of NANOSECONDS so you have to adjust
    'Delay To reflect this resulotion
    Delay = (Stopp - Start)* 10000
    ------------------
    Scott

    Leave a comment:


  • Dave Stanton
    replied
    The routine was developed to output a strobe to a hardware port
    in the range 1 to 10 msec.
    Looking at the output on a 'scope, the time delays were very close
    to that expected. Most of the time errors were about +/- 30usec,
    but once in a while the errors jumped to +/- 100usec.
    I didn't investigate further - it did the job.
    By the way, outputting to a hardware port directly will only work
    using WIN95/98

    HTH.
    Dave

    ------------------

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Heya, this was so long ago, but I did some research and to accurately determine the elapsed amount of milliseconds, use the timeGetTime() function, look it up in your win32api include, you impliment it exactly like you would PowerBasic's Timer function... in otherwords..

    counter = timeGetTime()

    code to time or whatever goes here

    elapsed_milliseconds = timeGetTime() - counter

    welcome

    ------------------

    Leave a comment:


  • Lance Edmonds
    replied
    "too much error"... do you mean compiler errors or inaccurate delay times?

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Hi there,

    Anybody can show me how to use Dave DelayUsec Function,
    I try it but with too much error.

    Thank & regards
    Aisin

    ------------------

    Leave a comment:


  • Dave Stanton
    replied

    These routines may be of use
    The delay is good for about */- 100usec
    Regards
    Code:
    #INCLUDE "WIN32API.INC"
    
        #IF NOT %DEF(%WINAPI)
        DECLARE FUNCTION QueryPerformanceCounter LIB "KERNEL32.DLL" _
                         ALIAS "QueryPerformanceCounter" _
                         (lpPerformanceCount AS QUAD) AS LONG
    
        DECLARE FUNCTION QueryPerformanceFrequency LIB "KERNEL32.DLL" _
                         ALIAS "QueryPerformanceFrequency" _
                         (lpFrequency AS QUAD) AS LONG
    
       #ENDIF
    
    
       FUNCTION WinUsec() AS DOUBLE
           DIM UsecFactor AS GLOBAL DOUBLE
           DIM TickF AS LOCAL QUAD
           DIM Ticks AS LOCAL QUAD
           IF ISFALSE UsecFactor THEN
              QueryPerformanceFrequency TickF
              UsecFactor=TickF/1000000
           END IF
           QueryPerformanceCounter Ticks
           IF UsecFactor THEN FUNCTION = Ticks / UsecFactor
       END FUNCTION
    
    
       SUB DelayUsec(BYVAL Usec AS QUAD)
           DIM UsecFactor AS GLOBAL DOUBLE
           DIM Cproc AS GLOBAL DWORD
           DIM TickF AS LOCAL QUAD
           DIM Ticks AS LOCAL QUAD
           IF ISFALSE Cproc THEN Cproc=GetCurrentProcess
           SetPriorityClass Cproc,%REALTIME_PRIORITY_CLASS
           IF ISFALSE UsecFactor THEN
              QueryPerformanceFrequency TickF
              UsecFactor=TickF/1000000
           END IF
           QueryPerformanceCounter Ticks
           Usec=Ticks+Usec*UsecFactor
           DO
              QueryPerformanceCounter Ticks
           LOOP UNTIL Ticks>Usec
           SetPriorityClass Cproc,%NORMAL_PRIORITY_CLASS
       END SUB
    ------------------

    Leave a comment:


  • Scott Turchin
    replied
    I have ICMP code available if you'd like a copy, already took care of all of that.
    It has a minor bug in it but should be easy to fix, just haven't spent the time.

    Also, for my Atomic clock I dropped down to QUAD level time and get guaranteed 50ms acuracy out of it....(Well, I subtract the delay form 50ms if it's lower, add if it's higher to account for network latency)..

    Be happy to send you all the code you need.


    [email protected]


    Scott

    ------------------
    Scott
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Semen Matusovski
    replied
    Matt--
    Search MSDN or BBS forAPI GetTickCount and QueryPerformanceCounter

    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Guest's Avatar
    Guest started a topic Miliseconds

    Miliseconds

    Hello, I'm a writing a [ping] type of program, and I need to return the amount of time elapsed in miliseconds, anyone know how I can do this using the Timer function.. ?

    ------------------
Working...
X