Hello Guest it is April 19, 2024, 10:00:25 AM

Author Topic: PoKeys56U Digital Output->Latency Too High!  (Read 9025 times)

0 Members and 1 Guest are viewing this topic.

PoKeys56U Digital Output->Latency Too High!
« on: March 26, 2013, 03:16:10 AM »
 :)
I have been using PoKey's Visual C# example to manually control digital outputs.
The problem is that the latency is about 2ms per bit out!
Since I am controlling 2 stepper motors, I am using 8 digital outputs (each are 1 bit).
This means that sending each 8 bit output takes 16ms!
I need to be able to change all 8 bits in under 1ms if possible.
By latency I mean the time it takes to execute a "set output" command and then start the next command.

I am controlling each bit individually with the function PoKeysDevice_DLL.SetOutput(byte pinID, bool outputState);
Is there a faster function? What about a function that can set more than one pin at a time? ???



My entire C# solution is attached, ready to run in Visual C# if you want to help me out ;)

Here is the example file I based my code on:
http://www.poscope.com/uploads/files/PoKeysExamples.zip<C#/Example2_BasicPinFunctions>

Here is my main function&file used to measure latency: (note that it takes me 9 seconds to run the while loop 500 times)
Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;


namespace Example2_BasicPinFunctions
{
    class Program
    {

        public enum pinFunctionsEnum
        {
            pinFunctionInactive = 0,
            pinFunctionDigitalInput = 2,
            pinFunctionDigitalOutput = 4,
            pinFunctionAnalogInput = 8,
            pinFunctionAnalogOutput = 16,
            pinInvert = 128
        }

        static void Main(string[] args)
        {           
            // Create PoKeys55 device object
            PoKeysDevice_DLL.PoKeysDevice device = new PoKeysDevice_DLL.PoKeysDevice();
            // Enumerate devices (this step must never be ommited!)
            int iNumDevices = device.EnumerateDevices();
            if (iNumDevices == 0)
            {
                Console.WriteLine("No PoKeys55 devices found!");
                Console.WriteLine("\nPress any key to exit");
                Console.ReadKey();
                return;
            }
            // Connect to first PoKeys55 device
            device.ConnectToDevice(0);

            int i;
            // Set pins as digital output
            for (i = 2; i <= 9; i++)
            {
                device.SetPinData((byte)(i - 1), (byte)(pinFunctionsEnum.pinFunctionDigitalOutput));
            }
            Console.WriteLine("Pins 2-9 set as digital output");


            bool flop = false;
            int j = 0;






////////////////////////////////////////////////////////////////IMPORTANT PART OF THE CODE
            while (true)
            {
                for (i = 2; i <= 9; i++)
                {
                    device.SetOutput((byte)(i - 1), flop); //is there a faster function that this one?
                }
                flop = !flop; //flop alternates true, false, true, false,...
                j++;
                if (j%500==0) {
                    Console.WriteLine("500 more done"); //prints every time the output changes 500 times (9 seconds)
                }
            }
////////////////////////////////////////////////////////////////END IMPORTANT PART OF THE CODE





            // Disconnect from device
            device.DisconnectDevice();


            Console.WriteLine("\nEnd.\nPress any key to exit");
            Console.ReadKey();

        }
    }
}
Re: PoKeys56U Digital Output->Latency Too High!
« Reply #1 on: March 27, 2013, 02:37:21 AM »
Note that this operator preforms even worse:

device.BlockSetOutput1

(not much worse, but still worse)
Re: PoKeys56U Digital Output->Latency Too High! ANSWER
« Reply #2 on: March 30, 2013, 12:44:33 AM »
 8) ANSWER  8)

I have contacted PoLabs/PoScope and they told me the following information:

Quote
PoKeys56U uses standard HID interface and thus relies on system's drivers for communication. Due to USB specifications, communication is limited to approximately 4-5 ms per one data transfer.
...
In addition - you may have noticed that with the newer firmware updates, Windows asks for a driver for PoKeys - we are working on a faster communication interface that should be available in April. That will allow 1 ms command execution.

As I previously stated, I was able to input new commands for a single bit every 2 ms which is slightly better than what PoKeys told me to expect, which is good. Can't wait for the newer driver.

Thanks PoKeys for the quick and accurate response and the support! ;D

Offline NeoTO

*
  •  504 504
    • View Profile
    • PoLabs
Re: PoKeys56U Digital Output->Latency Too High!
« Reply #3 on: April 15, 2013, 03:34:45 AM »
Hi, Alpaca

It is impossible to guarantee latencies below 1 ms via USB without going under the system's hood. Then, a new version of OS comes out and all over again...

Therefore, Pulse engine was implemented in PoKeys firmware to allow stepper motor control in CNC machines even with high system latencies (up to 100 ms). If you need to drive the steppers, you can use PoKeys pulse engine functions to do that. Pulse engine operates in three modes - buffer (where you specify how many pulses motors receive in each time slot), position control (you just specify the acceleration, decelleration and max speed parameters and send a position reference), speed control (similar to position control, but the reference is stepper motor speed).

If you have any further questions, feel free to contact me at matevz_at_poscope.com.

Regards,
Matevž
www.poscope.com home of PoKeys USB HID, IO, USB, Ethernet controler and PoScope USB PC oscilloscope