×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Delay microseconds in VB 6.0

Delay microseconds in VB 6.0

Delay microseconds in VB 6.0

(OP)
Hi, I have a chaallenge of generate a microseconds delay in Visual Basic, I know how to generate delay on the order of milliseconds (see below) but is too long for my application. Does anyone know how to generate this microsecond delay on Visual Basic 6.0.

Thanks

JM

RE: Delay microseconds in VB 6.0

VB stuff runs under Windows. Windows is a multi-threaded operating system. Therefore you can't be sure that your process will be running in any particular microsecond. It is (theoretically) possible to hijack some of the earlier OSs but inadvisable.

I would use hardware to generate microsecond timing. You will also need to bear in mind that most I/O stuff is interrupt driven so its timing will be subject to stack timing issues.

Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting

UK steam enthusiasts: www.essexsteam.co.uk

RE: Delay microseconds in VB 6.0

Quick Pak professional has a library
Crescent Softwware Inc

RE: Delay microseconds in VB 6.0

Under DOS you can control timing with a few uSec accuracy-
under WINDOWS you are out of luck...

<nbucska@pcperipherals DOT com> subj: eng-tips
read FAQ240-1032

RE: Delay microseconds in VB 6.0

The Windows operating system is a DOS program.
You need only unhook the operating system (suspend) and take control of the processor for your timing software.

This task needs to be more clearly defined (duration).

RE: Delay microseconds in VB 6.0

Could you explain in detail how that might be done in W2K or XP? My understanding is that since W2K the operating system is Windows, and the 'Command Prompt' window merely runs within the Windows envelope.

If that is not the case, then all of XP security could be simply bypassed.

Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting

UK steam enthusiasts: www.essexsteam.co.uk

RE: Delay microseconds in VB 6.0

CODE

;syntax - CALL Pause(uSecs%)
;where uSecs% is the number of microseconds to pause
;Note:  Maximum acceptable value is 27,500 microseconds.
;       Checking is performed on entry.
.Model Medium,BASIC
.Code
Pause Proc, uSecs:Ptr
    push    si
    mov     si,uSecs      ;get the address for uSecs%
    lodsw                 ;put the number of microseconds into AX
    cmp     ax,27500      ;exit if value out of range
    ja      exit
    mov     bx,25         ;calculate number of timer
    mul     bx            ;  cycles equivalent to the
    mov     bx,21         ;  specified number of
    div     bx            ;  microseconds
    mov     bx,ax         ;transfer result to BX
;Disable timer 2.
    in      al,61h        ;clear bit 0 of I/O port 61h
    jmp     short $+2
    and     al,0FEh
    out     61h,al
    jmp     short $+2
;Initialize timer 2 for mode 0 operation with word-size initial count.
    cli                   ;disable interrupts
    mov     al,0B0h       ;output control byte
    out     43h,al
    jmp     short $+2
    mov     al,bl         ;send low byte of count
    out     42h,al
    jmp     short $+2     ;tiny delay
    mov     al,bh         ;then the high byte
    out     42h,al
    jmp     short $+2     ;tiny delay
;Reinitialize timer 0 to make sure a time-of-day interrupt doesn't occur.
    mov     al,36h        ;mode 3 with word-size divisor
    out     43h,al
    jmp     short $+2
    xor     al,al         ;set interrupts for every
    out     40h,al        ;  65,536 cycles
    jmp     short $+2
    out     40h,al
    jmp     short $+2
    sti                   ;enable interrupts
;Start the countdown by enabling timer 2.
    in      al,61h        ;set bit 0 of I/O port 61h
    jmp     short $+2
    or      al,01h
    out     61h,al
    jmp     short $+2
;Loop until the count has reached zero.
readloop:
    mov     al,80h        ;latch timer 2
    out     43h,al
    jmp     short $+2     ;tiny delay
    in      al,42h        ;read count
    jmp     short $+2     ;tiny delay
    mov     ah,al
    in      al,42h
    jmp     short $+2     ;tiny delay
    xchg    al,ah
    or      ax,ax         ;loop if count hasn't
    jns     readloop      ;  reached zero
Exit:
    pop     si
    Ret                   ;return to VBASIC
Pause Endp
End

RE: Delay microseconds in VB 6.0

The OP asked a question about Visual Basic - I must have missed that lesson in the Visual Basic Course! That all looks like old-fashioned assembler to me. What are you doing that prevents OS interrupts? And how does that help if the Visual Basic program is still subject to OS Interrupts?

Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting

UK steam enthusiasts: www.essexsteam.co.uk

RE: Delay microseconds in VB 6.0

(OP)
Ok, just giving you a more detail on why I need to a delay routine in usecs, I developed an RS232 interface to be connected to COM1 using DTR/CTS (Data Terminal Ready/Clear To Send), RTS/DSR (Request To Send/Data Set Ready) as control lines to drive a 24CXX Serial EEPROM (I2C bus type). So far my routines can write and read the EEPROM (in my case an ATMEL 24C01), the thing is that I must delay the Clock Pulse Witdth High of the SCL line of the device(Serial Clock Input)to allow the data that is beig read from or write to the EEPROM to be valid according data sheet. Now with my routines I only can delay down to 1 msec which is too much even for this small 1K EEPROM. If you need further details please let me know, and before you answer that are already something done somewhere, I know that but I want to do my own tool to learn and to customize it to my needs.

Thanks and I hope someone could help

JM

RE: Delay microseconds in VB 6.0

JOHNWM;
The assembler code disables interrupts and takes control of the intel compatible CPU instruction set. Other source code languages such as MASM, C+, FORTRAN etc. may be called from VB6. The ASM code above shows how to achieve usec delays if you want to write your own code. A similar project is found at

http://www.seattlerobotics.org/encoder/200106/16cs...

My first response of using Crescent Software's QuickPAK or PDQcomm is easier (call someone elses library they wrote),
or you can search the internet and find several other pay solutions;

http://www.experts-exchange.com/Programming/Q_2084...
http://c.ittoolbox.com/groups/groups.asp?v=access-...

or a different forum;
http://forums.devshed.com/forumdisplay.php?s=d0b57...

RE: Delay microseconds in VB 6.0

Thank you for the clarification - I will try it sometime with VB. I have used a similar construction with QBasic and other Non-VB Basic Flavours, but I wasn't aware that you could do it from Visual Basic 6 under XP

Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376 before posting

UK steam enthusiasts: www.essexsteam.co.uk

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources