Motion Control and Motor Drives

cancel
Showing results for 
Search instead for 
Did you mean: 

Windows Media Player makes NI-Motion faster

I've found a strange situation while using the NI-Motion driver in VB 6.0. It appears that running Windows Media Player reduces the time it takes to make calls to the NI-Motion driver. I wrote a sample program to demonstrate this. This program calls a NI-Motion function (flex_enable_limits) 3000 times and measures how long this process takes. If I run this program after booting up my computer, it takes about 24 seconds to complete the 3000 calls. Then I open Windows Media Player 11 and close it. The same program takes 6 seconds to run (1/4 of the time) after running WMP. 

 

I am running this on a Pentium 4 processor with Windows XP. I am using NI-Motion 7.6 with Visual Basic 6.0.

 

What is WMP doing to speed up calls to the NI-Motion driver?

 

 

The sample program: 

 

Option Explicit

Declare Function flex_enable_limits Lib "FlexMotion32.dll" (ByVal boardID%, ByVal limitType%, ByVal forwardLimitMap%, ByVal reverseLimitMap%) As Long

Public Sub Main()

  Dim ErrVal As Long
  Dim StartTimer As Single
  Dim LoopIdx As Long
  Dim Var1 As Long
    
  ' This is a simple calculation loop used to make sure Windows isn't doing anything to slow down the program
  DoEvents
  StartTimer = Timer
  For LoopIdx = 1 To 300000000
    Var1 = Var1 + 1
  Next LoopIdx
  Debug.Print "Calc Loop Time = " & CStr(Timer - StartTimer) & " seconds"
  
    ' On my computer, this section takes 24 seconds before running WMP and takes 6 seconds after running WMP
  DoEvents
  StartTimer = Timer
  For LoopIdx = 1 To 3000
    ErrVal = flex_enable_limits(1, 0, 0, 6)
  Next LoopIdx
  Debug.Print "NI-Motion Loop Time = " & CStr(Timer - StartTimer) & " seconds"
  Debug.Print "------------------------"

 

End Sub

 

 

0 Kudos
Message 1 of 16
(5,070 Views)
Could you post your entire project? Thanks! Also, how many times have you tested this, and how consistent are these measurements?
--Michelle

National Instruments
0 Kudos
Message 2 of 16
(5,033 Views)

Here is the link to the project files.

 

The results seem very repeatable to me. I have tried this on two different systems (a Dell Pentium 4 desktop and an Advantech Dual Core industrial PC) and I am seeing similar results.

 

I tried running the program 3 times after rebooting. The calculation loop took 4.4 seconds, 4.5 seconds, and 4.4 seconds for each try. The loop that call the NI-Motion driver took 23.6 seconds, 23.3 seconds, and 23.3 seconds on each try.

 

Next I opened Windows Media Player and left it open for a few seconds while it started up. Then I closed Windows Media Player and tried the program again.

 

After running Windows Media Player, the calculation loop had no change in times as I would expect. The calculation loop took 4.5 seconds on all 3 tries. However, the loop that calls the NI-Motion driver now only took 6.1 seconds, 5.8 seconds, and 5.9 seconds for each try. This loop is running 4 times faster after running Windows Media Player.

0 Kudos
Message 3 of 16
(5,016 Views)

Hi chvogt,

 

When I run the code it gets to displaying the loop calculation time, but then gets stuck and never makes it to the NI Motion call time. Can you tell what needs to be changed to fix this?

--Michelle

National Instruments
0 Kudos
Message 4 of 16
(4,989 Views)

The time it takes to do each loop is arbitrary depending on the speed of your PC. You can reduce the number of loops to reduce the amount of time you wait.

 

My original sample program timed how long it took to perform a fixed number of iterations. The problem with this method is you don't know how long it will take to run through each loop until you run the program. So I changed my method and made a new program that counts how many loops can be completed in a fixed amount of time. This way you will know how long to wait for each loop to finish. In the new program, you specify the duration to run each loop and the program counts how many loop iterations it can perform in the specified amount of time. I also dressed this up a little with a simple user interface.

 

You can download the new test program from here

 

Be sure to check out the 'Read Me' PDF for additional information.

 

 

0 Kudos
Message 5 of 16
(4,980 Views)
I have tested it and am not seeing the large increase in performance that you are seeing. Also, I've run this code several times and the loop durations are not consistent due to background processes running on my Windows Machine.

Has anyone else been able to see this work for them? Can you try this on another PC?
--Michelle

National Instruments
0 Kudos
Message 6 of 16
(4,954 Views)

So far I have only encountered this issue while using a PCI-7344 board. I tried this test on a virtual PCI-7344 board created in NI-MAX but it doesn't behave any differently after running WMP. 

 

I have tried different PCI-7344 boards in different computers and they all run the test program faster after running WMP.

0 Kudos
Message 7 of 16
(4,925 Views)
Hello chvogt,

I tried to reproduce this behavior on my machine as well, but I did not see any significant change regardless of WMP status. I followed your directions explicitly, and ran the test immediately after a restart. I repeated the test while WMP was playing my favorite song. Then finally closed WMP and ran your test again. The results for my machine are a steady ~1022 loops per second. Note that I performed this test with an actual PCI-7344 card installed in my machine. The screenshots of your test program under these 3 WMP states are attached.

You mention that you can reproduce this behavior on several computers. Could you provide more specific information about the other computer setups? Without reproducibility, I would attribute this behavior to non-deterministic operating systems in general.

The Windows operating system is non-deterministic. If you hope to maintain consistent loop iteration rates and virtually eliminate jitter in your motion control application (or any application for that matter), I recommend using a deterministic operating system like LabVIEW Real-Time.
David G
Sales Engineer - SE Michigan & N Ohio
National Instruments
0 Kudos
Message 8 of 16
(4,889 Views)

I understand the problems that can come up while running applications in Windows. However, if Windows was doing something that would vary the speed of the loops, I would expect to see it affect both the calculation and the NI-Motion loops. It's true that the computer is doing different things when making a call to NI-Motion versus just adding up some numbers but what really doesn't make sense to me is that running WMP makes the test program run faster not slower (at least on the computers I've checked). Also, it's not just a little faster, it is 4 times faster. Most of the problems I've encountered with Windows is that things start to slow down when you start running more processes, not speed up. 

 

Some more info: 

 

  • I tried the test program on an older computer this morning that had WMP version 9.0 and was able to see the 4x speed increase. The computer probably has an older version of NI-Motion as well but I will need to verify that.

 

  • On most of the PCI-7344 boards I have tried, I have upgraded the firmware to the latest version. (68331 firmware is version 7.40.3001, DSP firmware is 7.30.3001, FPGA1 & FPGA2 are 7.00.3001)

 

  • Most of the computers are industiral PCs with 'out-of-the-box' configurations. These are bare-bones Windows XP installations (no anti-virus, no Microsoft Office, etc.).  We take the computer out of the box, install VB6, NI-Motion, and either NI-DAQ or NI-DAQmx, run Windows update and that's it.  

 

  • Most of computers have all of the latest Windows updates, but the one I test this morning hasn't been updated for a while.

 

  • All of the systems that I have tested have Intel chipsets. I have not tried this on an AMD machine yet.

 

I appreciate the attention that you have been giving to this issue and I will continue to see if I can come up with a way to reproduce this on your system.

 

 

0 Kudos
Message 9 of 16
(4,876 Views)

David

 

I might have found the reason why you aren't able to reproduce the problem with the test program. It appears that Internet Explorer also speeds up the NI-Motion loop. I rebooted my PC and tried the test program. The NI-Motion loops run at 128 loops/sec consistently. I then started Internet Explorer instead of WMP, let it run for a few seconds and closed it. Now the NI-Motion loops are running at about 1020 loops/sec which is the same speed you were reporting. Note that the speed increase after running WMP is about 4x faster (510 loops/sec) but it is about 8x faster after running IE (1020 loops/sec).

 

I have verified this on 2 different PCs with 2 different PCI-7344 and the results are repeatable. However, I found that you need to actually be connected to the Internet for this to work. If I run Internet Explorer on a PC that doesn't have an internet connection, there is no change in the time and the loop still runs at 128 loops/sec.

 

 

 

0 Kudos
Message 10 of 16
(4,865 Views)