* *


Welcome, Guest. Please login or register.
Did you miss your activation email?
January 18, 2018, 10:07:15 PM

Login with username, password and session length


  • Total Posts: 12184
  • Total Topics: 1737
  • Online Today: 32
  • Online Ever: 195
  • (February 11, 2014, 01:46:08 PM)
Users Online
Users: 0
Guests: 22
Total: 25
Baidu (3)

Author Topic: Asked: functions written in C/C++ or other language : Microseconds Delays Timers  (Read 2435 times)

0 Members and 1 Guest are viewing this topic.

Offline Stephane760126

  • Newbie
  • *
  • Posts: 1
  • Bananas: 0
  • Gender: Male
  • I haven't set any personal text yet
Hi all,

I ask me of myzelf what kind of Timers APi can I use for create an delays of microseconds?

I read the MSDN site and I found the topics of different manners for create function that generates an delay of microseconds.

Witch one is the best solution for my problem if the user set the delay in microseconds and the function executes the adjustable microseconds of the user.

I hope that here developers knowledge the WinAPI and low level programming. I work under Windows XP/7

We have the chooice of:

1 Multimedia Timer
2. Waitable Timer
3. Queue Timer

1) Whitch is the best chooice of this timers?
2) How can I rewrite the code for use in microseconds?
3) I wish to change in the exists functions (see above) for programming the functions that using the microsecond
    (delay) timer. I don't know how I can change this in the code:

     DECLARE SUB TimeInit_us()
     DECLARE SUB Delay_us(BYVAL wDelay AS WORD)

' TIME functions
' This set of functions is important for various time measurements. Just as
' with DELAY function (in ms) and Delay_us (in Ás), TIME functions also operate on millisecond or
' microsecond basis.
' TIMEINIT (in ms) and TIMEINIT_US (in Ás) will reset the timers to zero and start them again
' with ms or us precision
' TIMEREAD (in ms) and TIMEREAD_US (in Ás) functions will read the amount of time (in ms or us)
' since the last TIMEINIT or TIMEINITUS function was executed. Both functions
' return a 64-bit integer

4) How can I combine it to an Quad word (64 bit)?

Code: [Select]

#Dim All
#Include "Win32API.inc"

    low_part  As Long
    high_part As Long
End Type

Global g_TimeUnit               As Double
Global g_Start_Time_Low   As Long
Global g_Start_Time_High   As Long

'Milliseconds Delay Timer Functions                                       '

Sub TimeInit()
    'Reset the milliseconds Timer to Zero
    'will reset the timers to zero and start them again with ms precision
    Local f As LARGE_INTEGER
    Local t As LARGE_INTEGER
    Local x As Dword

    x = QueryPerformanceFrequency(f)
    g_TimeUnit = 1000 / f.low_part
    x = QueryPerformanceCounter(t)

    g_Start_Time_Low  = t.low_part
    g_Start_Time_High = t.high_part
End Sub

Function TimeRead()  As QUAD
    ' TIMEREAD functions will read the amount of time (in ms)
    ' since the last TIMEINIT function was executed. The function
    ' return a 64-bit integer
    Local t As LARGE_INTEGER
    Local x As Dword

    If(g_TimeUnit = 0) Then g_TimeUnit = 0.000838096515
    x = QueryPerformanceCounter(t)
    Function = (t.high_part * 4294967296# + t.low_part - g_Start_Time_High * 4294967296# - g_Start_Time_Low * g_TimeUnit)
End Function

Sub Delay(ByVal wDelay_time As Word)
    'With the DELAY function is important for various time measurements. Just
    'as with Delay function, Time function also operate on ms basic
    Local time_start As Double

    time_start = TimeRead()
    While(TimeRead() < (time_start + wDelay_time)) : Wend
End Sub

I hope that here someone help me but I can't written the functions for the microseconds timer

Kind regards

Ps: You can also written it in IWBasic, IBasic no LIB just plean code


To link to us use this code/button on your site




Blue Steel

January 01, 2018, 04:34:54 AM
Happy new year to all

Blue Steel

December 25, 2017, 06:13:27 AM
merry christmas and seasons greetings to one and all

Blue Steel

December 09, 2017, 02:46:53 AM
:) ty fingers crossed

Larry McCaughn

December 08, 2017, 04:10:56 PM
I'll give you a Shout out in the Shout Box for being able to put it back up.


September 20, 2017, 01:57:54 PM
Hey that's my job. Didn't choose this username for nothing you know.  :)

Larry McCaughn

September 19, 2017, 12:24:13 AM
lurking in the shadows, lurkalot.


September 16, 2017, 04:39:43 PM
Good evening all.  Where is everyone?


September 12, 2017, 12:57:36 PM
Good to hear, it's nice to see a empty error log. ;)

Blue Steel

September 12, 2017, 05:04:25 AM
running sites log files overnight heres the result (I know mainly spiners) "There are currently no error log entries." :)


September 12, 2017, 03:19:33 AM
Morning all.  :)

Blue Steel

September 12, 2017, 01:12:33 AM
Let it all out ..
these are the things I can't do without  ;)


September 11, 2017, 11:14:22 PM


September 11, 2017, 08:16:02 PM
Shouting is Go !  ;D

Blue Steel

September 11, 2017, 06:54:02 PM
gradually getting there


September 11, 2017, 05:22:46 PM
Yay, you found it.  ;)

Larry McCaughn

September 11, 2017, 01:07:13 PM
looks like you're making good progress

Blue Steel

September 07, 2017, 10:34:19 PM
yay recent topics are working again in the center of the home page :)

Larry McCaughn

July 12, 2017, 05:46:33 PM
Blue Steel is back running the show.  Maybe he'll be able to build some steam in the ole place!

Blue Steel

June 26, 2017, 04:58:41 AM
hope i didn't scare too many of you

Blue Steel

June 26, 2017, 04:58:12 AM
Boo, i'm still here alive and well , see my post in introductions


July 25, 2016, 01:43:24 AM
That sounds cool. Have to chekc out IWBasic in the next days.

Larry McCaughn

July 22, 2016, 11:47:00 PM
I'm hoping to issue a new maintenance release to the IWBasic 3.x IDE in the next few weeks and Larry Sikes has released an update to the Linux version of IWBasic and is currently working on the 64bit version of IWBasic.  Progress should speed up since he has retired and has apparently resolved his m


July 19, 2016, 02:53:02 PM
Anything interesting going on around BASIC?

Larry McCaughn

July 18, 2016, 09:14:12 AM
Hello Mike