CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 1999
    Location
    Islamabad, Pakistan
    Posts
    12

    Controlling execution speed on variuos PCs

    I have just written a software to control a machine with stepper motors. Now to move stepper motor some slowing down delay must be there between successive pulses, as:
    For i=1 To 5000: Next
    Now, when the same program is run on computers of differing capacities, it just looses control of the motor speed. I know how many times the For...Next must be executed to give a particular speed. However, it is system specific.
    Can anybody tell me how can I make the program system independent, general-purpose, so that I can control motor speeds from any computer, whether it is a 386, 486 ot pentium.
    I tried Timer, etc, but these do not work as i have to send hundreds of pulses per second.
    Thankyou.


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Controlling execution speed on variuos PCs

    Try using the sleep API, wich will force the PC to wait a number of milliseconds.
    Should give the same result on 386 or 500 MHz


    Declare Sub Sleep Lib "kernell32.dll" (byval dwMilliseconds as Long)

    'just use it like this
    sleep(numberOfMillisecondsToSleep)




    Note: the use of a for next loop isn't the good way to implement a delay in a process. This will only cause your program the ask a lot of CPU-power. The sleep command does the opposit. It doesn't use any (or very little) CPU-power, and the interval will be the same on no matter what computer.

    Tom Cannaerts
    [email protected]

    The best way to escape a problem, is to solve it.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Dec 1999
    Location
    Islamabad, Pakistan
    Posts
    12

    Re: Controlling execution speed on variuos PCs

    Thank you.
    Now I can have a control down to milliseconds, but can I go even finer...!
    Any horrible or tricky technique.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured