Timing?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jamie

    Timing?

    hey all,

    I am attempting to do motion control for
    a final project, but I have a concern....

    For motion control, timing is everyting,
    the better it is, the better it works.
    Currently I am trying to use the timer
    function block to do a 10ms loop, but
    if I remember correctly.... that timing
    wasnt the best. Any suggestions to improve
    upon it? eg. A high priority thread, calculating
    the thread sleep myself? ....????

    Thankyou in advance,
    jamie.
  • Bob Powell [MVP]

    #2
    Re: Timing?

    Take a look at the System.Threadin g.Timer It has better resolution and isn't
    reliant on the load in the message queue for it's processing.

    --
    Bob Powell [MVP]
    Visual C#, System.Drawing

    Find great Windows Forms articles in Windows Forms Tips and Tricks


    Answer those GDI+ questions with the GDI+ FAQ


    All new articles provide code in C# and VB.NET.
    Subscribe to the RSS feeds provided and never miss a new article.





    "jamie" <anonymous@disc ussions.microso ft.com> wrote in message
    news:014901c54c 03$4b76b1d0$a50 1280a@phx.gbl.. .[color=blue]
    > hey all,
    >
    > I am attempting to do motion control for
    > a final project, but I have a concern....
    >
    > For motion control, timing is everyting,
    > the better it is, the better it works.
    > Currently I am trying to use the timer
    > function block to do a 10ms loop, but
    > if I remember correctly.... that timing
    > wasnt the best. Any suggestions to improve
    > upon it? eg. A high priority thread, calculating
    > the thread sleep myself? ....????
    >
    > Thankyou in advance,
    > jamie.[/color]


    Comment

    • Ignacio Machin \( .NET/ C# MVP \)

      #3
      Re: Timing?

      Hi,

      I think that the best approach you can get is using System.Timer.

      take a look at "Introducti on to Server-Based Timers" :




      cheers,

      --
      Ignacio Machin,
      ignacio.machin AT dot.state.fl.us
      Florida Department Of Transportation



      "jamie" <anonymous@disc ussions.microso ft.com> wrote in message
      news:014901c54c 03$4b76b1d0$a50 1280a@phx.gbl.. .[color=blue]
      > hey all,
      >
      > I am attempting to do motion control for
      > a final project, but I have a concern....
      >
      > For motion control, timing is everyting,
      > the better it is, the better it works.
      > Currently I am trying to use the timer
      > function block to do a 10ms loop, but
      > if I remember correctly.... that timing
      > wasnt the best. Any suggestions to improve
      > upon it? eg. A high priority thread, calculating
      > the thread sleep myself? ....????
      >
      > Thankyou in advance,
      > jamie.[/color]


      Comment

      • Salvador

        #4
        RE: Timing?

        Hi,

        Use a timer but you control the timing using System.Environm ent.TickCount
        that retrieves the ticks from the processor in milliseconds, this is the most
        precise method.

        You can compare your starting tickcount and comparing it with the final one
        the control your timing. The loop can be interrupted by other threads and you
        won't realize if it takes 10, 20 or 30 milliseconds to loop.

        cheers
        Salva


        "jamie" wrote:
        [color=blue]
        > hey all,
        >
        > I am attempting to do motion control for
        > a final project, but I have a concern....
        >
        > For motion control, timing is everyting,
        > the better it is, the better it works.
        > Currently I am trying to use the timer
        > function block to do a 10ms loop, but
        > if I remember correctly.... that timing
        > wasnt the best. Any suggestions to improve
        > upon it? eg. A high priority thread, calculating
        > the thread sleep myself? ....????
        >
        > Thankyou in advance,
        > jamie.
        >[/color]

        Comment

        • Willy Denoyette [MVP]

          #5
          Re: Timing?


          "jamie" <anonymous@disc ussions.microso ft.com> wrote in message
          news:014901c54c 03$4b76b1d0$a50 1280a@phx.gbl.. .[color=blue]
          > hey all,
          >
          > I am attempting to do motion control for
          > a final project, but I have a concern....
          >
          > For motion control, timing is everyting,
          > the better it is, the better it works.
          > Currently I am trying to use the timer
          > function block to do a 10ms loop, but
          > if I remember correctly.... that timing
          > wasnt the best. Any suggestions to improve
          > upon it? eg. A high priority thread, calculating
          > the thread sleep myself? ....????
          >
          > Thankyou in advance,
          > jamie.[/color]

          I'm not entirely clear what you want exactly, but if you need a timer that
          fires exactly every 10 msec , you have choosen the wrong platform - both OS
          and .NET, You need a Real Time Operating system for this and Windows is not
          a RTOS.

          Willy.


          Comment

          • Howard Swope

            #6
            Re: Timing?

            Jamie:

            One can't do really precise motion control under windows, or any PC
            operating system for that matter. You will need a real-time operating system
            (RTOS). By definition an RTOS can say that an event will occur within a
            certain amount of time with absolute certainty.

            That being said, and hoping that your final project is not implementing a
            pace maker, if you want to do this in windows and you want to do this from
            C# you will probably want use a System.Threadin g.Timer and from within your
            OnTick routine call the Win32 function QueryPerformanc eCounter to calculate
            the actual time elapsed with PInvoke.

            Checkout







            "jamie" <anonymous@disc ussions.microso ft.com> wrote in message
            news:014901c54c 03$4b76b1d0$a50 1280a@phx.gbl.. .[color=blue]
            > hey all,
            >
            > I am attempting to do motion control for
            > a final project, but I have a concern....
            >
            > For motion control, timing is everyting,
            > the better it is, the better it works.
            > Currently I am trying to use the timer
            > function block to do a 10ms loop, but
            > if I remember correctly.... that timing
            > wasnt the best. Any suggestions to improve
            > upon it? eg. A high priority thread, calculating
            > the thread sleep myself? ....????
            >
            > Thankyou in advance,
            > jamie.[/color]


            Comment

            • Brian Gideon

              #7
              Re: Timing?

              Jamie,

              You'll have to use multimedia timers to achieve the best possible
              resolution for the hardware. I'm not sure how the garbage collector
              affects the resolution.

              <http://msdn.microsoft. com/library/default.asp?url =/library/en-us/multimed/htm/_win32_multimed ia_timers.asp>

              jamie wrote:[color=blue]
              > hey all,
              >
              > I am attempting to do motion control for
              > a final project, but I have a concern....
              >
              > For motion control, timing is everyting,
              > the better it is, the better it works.
              > Currently I am trying to use the timer
              > function block to do a 10ms loop, but
              > if I remember correctly.... that timing
              > wasnt the best. Any suggestions to improve
              > upon it? eg. A high priority thread, calculating
              > the thread sleep myself? ....????
              >
              > Thankyou in advance,
              > jamie.[/color]

              Comment

              • Markus Stoeger

                #8
                Re: Timing?

                jamie wrote:[color=blue]
                > hey all,
                >
                > I am attempting to do motion control for
                > a final project, but I have a concern....
                >
                > For motion control, timing is everyting,
                > the better it is, the better it works.[/color]

                C# and Windows aren't the best platforms for real time applications. If real
                time is important for your application I would use a software PLC. Do the
                real time stuff in the PLC and provide control access through a nice GUI
                written in C#. :-)

                Max

                Comment

                Working...