Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 35 of 35

Thread: USB Host polling rate issues

  1. #26
    Figured out its something about reading the USB host shield.
    I think its somewhere at void USBHIDParser::in_data(const Transfer_t *transfer) - hid.cpp, might be that packets are not properly read?

    Setting mouse.move directly results in 1000hz.

  2. #27
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,574
    As the person who created this thread, that their issue was resolved and that maybe you should create your own thread with as much information as possible.

    Again with things like: I am pretty sure you are not testing the same way as mentioned...

    Is your issue that the Model 0 mouse is not reporting 1000 times per second or that your
    code reporting to the PC is not reporting 1000 times per second?

  3. #28
    I tried to do that, although Paul locked that thread.
    Its "Model 0 mouse is not reporting 1000 times per second" to the Teensy.
    USBHost_t36 probably requires some editing, I think from 8 bit support to 16 bit support.

  4. #29
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,077
    Let's continue it here. After the mess of ICS5200 threads (I have them again on my workbench - going to test this weekend) I want to prevent this situation where we get duplicate threads.

    Regarding the polling rate, I recently ran the USB transmit speed benchmark and noticed it was running at only about half speed.

    https://github.com/PaulStoffregen/US...rint_speed.ino

    But I'm trying it again with Ubuntu 20.04 and USB Type "Keyboard + Mouse + Joystick" and I'm getting 15455 lines/sec. At 33 bytes per line, that's about 510000 bytes per second, which is approx 8000 packets per second with 64 bytes per packet. Can't seem to reproduce the half speed result now.

    I did end up getting one of those Model O mice to test this. It's sitting right behind me in a box of USB devices for testing the host library.

  5. #30
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,574
    Paul,

    For what it is worth, I was hacking around with a simple sketch:
    Code:
    #include <USBHost_t36.h>
    
    USBHost usb_host;
    USBHIDParser hid1(usb_host);
    USBHIDParser hid2(usb_host);
    USBHub hub(usb_host);
    
    MouseController mouse_in(usb_host);
    
    void setup() {
      // USB IN
      while (!Serial && millis() < 4000) ;
      Serial.begin(115200);
      Serial.println("Test mouse reads");
      usb_host.begin();
    }
    
    void loop() {
      elapsedMicros em = 0;
      uint32_t count_mouse_reads = 0;
      while (count_mouse_reads < 1000) {
        usb_host.Task();
        if (mouse_in.available())
        {
    #if 0
          // Proxy Mouse
          Serial.print("Mouse: buttons = ");
          Serial.print(mouse_in.getButtons());
          Serial.print(",  mouseX = ");
          Serial.print(mouse_in.getMouseX());
          Serial.print(",  mouseY = ");
          Serial.print(mouse_in.getMouseY());
          Serial.print(",  wheel = ");
          Serial.print(mouse_in.getWheel());
          Serial.print(",  wheelH = ");
          Serial.print(mouse_in.getWheelH());
          Serial.println();
    #endif      
          count_mouse_reads++;
          mouse_in.mouseDataClear();
        }
      }
      Serial.println((uint32_t)em);
      delay(250);
    }
    Where at first I did not think it was working, but then later I found it only output messages when the state changed...

    Output: when I move the mouse a lot...
    Code:
    Test mouse reads
    76819003
    2036999
    2043999
    2042999
    First one does not count as I waited a bit to start moving mouse...
    But from this, it looks like it is polling at about 500 times per second...

    Some Debug output, from the HID Dump program with debug turned on...
    Code:
    USB HID Device Info Program
    
    This Sketch shows information about plugged in HID devices
    
    *** You can control the output by simple character input to Serial ***
    R - Turns on or off showing the raw data
    C - Toggles showing changed data only on or off
    <anything else> - toggles showing the Hid formatted breakdown of the data
    
    USB2 PLL running
     reset waited 6
    USBHS_ASYNCLISTADDR = 0
    USBHS_PERIODICLISTBASE = 2000C000
    periodictable = 2000C000
    port change: 10001803
        connect
      begin reset
    port change: 10001005
      port enabled
      end recovery
    new_Device: 12 Mbit/sec
    new_Pipe
    enumeration:
    enumeration:
    enumeration:
    Device Descriptor:
      12 01 10 01 00 00 00 08 8A 25 36 00 09 01 01 02 00 01 
        VendorID = 258A, ProductID = 0036, Version = 0109
        Class/Subclass/Protocol = 0 / 0 / 0
        Number of Configurations = 1
    enumeration:
    enumeration:
    Manufacturer: SINOWEALTH
    enumeration:
    Product: Wired Gaming Mouse
    enumeration:
    Config data length = 59
    enumeration:
    Configuration Descriptor:
      09 02 3B 00 02 01 00 A0 F0 
        NumInterfaces = 2
        ConfigurationValue = 1
      09 04 00 00 01 03 01 02 00 
        Interface = 0
        Number of endpoints = 1
        Class/Subclass/Protocol = 3(HID) / 1(Boot) / 2(Mouse)
      09 21 11 01 00 01 22 47 00 
        HID, 1 report descriptor
      07 05 81 03 08 00 01 
        Endpoint = 1 IN
        Type = Interrupt
        Max Size = 8
        Polling Interval = 1
      09 04 01 00 01 03 01 01 00 
        Interface = 1
        Number of endpoints = 1
        Class/Subclass/Protocol = 3(HID) / 1(Boot) / 1(Keyboard)
      09 21 11 01 00 01 22 D5 00 
        HID, 1 report descriptor
      07 05 82 03 08 00 01 
        Endpoint = 2 IN
        Type = Interrupt
        Max Size = 8
        Polling Interval = 1
    enumeration:
    USBHub memory usage = 960
    USBHub claim_device this=20007300
    USBHub memory usage = 960
    USBHub claim_device this=200076C0
    
    USBDeviceInfo claim this=20006CA8
    
    ****************************************
    ** Device Level **
      vid=258A
      pid=36
      bDeviceClass = 0
      bDeviceSubClass = 0
      bDeviceProtocol = 0
    09 04 00 00 01 03 01 02 00 09 21 11 01 00 01 22 47 00 07 05 81 03 08 00 01 09 04 01 00 01 03 01
    01 00 09 21 11 01 00 01 22 D5 00 07 05 82 03 08 00 01 
    HIDParser claim this=20006020
    HIDParser claim this=20006660
    HIDParser claim this=2000ACE0
    HIDParser claim this=20004920
    HIDParser claim this=20006CC0
    Descriptor 4 = INTERFACE
    
    USBDeviceInfo claim this=20006CA8
    
    ****************************************
    ** Interface Level **
    09 04 00 00 01 03 01 02 00 09 21 11 01 00 01 22 47 00 07 05 81 03 08 00 01 09 04 01 00 01 03 01
    01 00 09 21 11 01 00 01 22 D5 00 07 05 82 03 08 00 01 
     bInterfaceNumber = 0
     number end points = 1
     bInterfaceClass =    3
     bInterfaceSubClass = 1
        HID (BOOT)
     bInterfaceProtocol = 2
    report descriptor size = 71
      endpoint = 81
        attributes = 3 Interrupt
        size = 8
        interval = 1
    HIDParser claim this=20006020
     bInterfaceNumber =   0
     bInterfaceClass =    3
     bInterfaceSubClass = 1
     bInterfaceProtocol = 2
    HID Parser Claim: 09 04 00 00 01 03 01 02 00 09 21 11 01 00 01 22 47 00 07 05 81 03 08 00 01 09 04 01 00 01 03 01 01 00 09 21 11 01 00 01 22 D5 00 07 05 82 03 08 00 01 
    report descriptor size = 71
    Single endpoint HID:
      endpoint = 81
       size = 8
       interval = 1
    new_Pipe
    Edit: but again could not tell from description so far if issue he is seeing is with the USB type of Mouse... Or with USBHost...

  6. #31
    USBHost.

    I tried to do the triangle mouse movement while mouse.available(), that worked with 1000hz.
    Just when reading values from USBHost and passing them over, I get 500hz.

  7. #32
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,574
    Quote Originally Posted by mcrc View Post
    USBHost.

    I tried to do the triangle mouse movement while mouse.available(), that worked with 1000hz.
    Just when reading values from USBHost and passing them over, I get 500hz.
    As I mentioned in the previous post, that the USBHostappears to only returning 500hz...

    Sorry, it has not been a high priority item for me, So hopefully Paul will find a solution.

    There is one thing I am curious to try here, in that maybe at 1000hz only having one input transfer/buffer may not be sufficient...
    So I may try a quick and dirty hack to HIDParser of setting up 2nd Input buffer, transfer and see if it helps.

  8. #33
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,574
    For what it is worth,

    I pushed up a new Branch of USBHost_t36: https://github.com/KurtE/USBHost_t36...nput_transfers

    Where I added second buffer (Record2) and an extra InputTransfer.

    And then with a slightly modified version of posted sketch:
    Code:
    #include <USBHost_t36.h>
    
    USBHost usb_host;
    USBHIDParser hid1(usb_host);
    USBHIDParser hid2(usb_host);
    USBHub hub(usb_host);
    
    MouseController mouse_in(usb_host);
    
    void setup() {
      // USB IN
      while (!Serial && millis() < 4000) ;
      Serial.begin(115200);
      Serial.println("Test mouse reads");
      usb_host.begin();
    }
    
    void loop() {
      elapsedMicros em = 0;
      uint32_t count_mouse_reads = 0;
      while (count_mouse_reads < 1000) {
        usb_host.Task();
        if (mouse_in.available())
        {
    #if 0
          // Proxy Mouse
          Serial.print("Mouse: buttons = ");
          Serial.print(mouse_in.getButtons());
          Serial.print(",  mouseX = ");
          Serial.print(mouse_in.getMouseX());
          Serial.print(",  mouseY = ");
          Serial.print(mouse_in.getMouseY());
          Serial.print(",  wheel = ");
          Serial.print(mouse_in.getWheel());
          Serial.print(",  wheelH = ");
          Serial.print(mouse_in.getWheelH());
          Serial.println();
    #endif
          count_mouse_reads++;
          mouse_in.mouseDataClear();
        }
      }
      uint32_t delta_time = em;
      Serial.print(delta_time);
      Serial.print(" ");
      Serial.println((1000000.0 / (float)delta_time) * 1000.0, 2);
      delay(250);
    }
    With it setting up to have two Input transfers queued, the number of Hz went up from about 500 to >900.

    Code:
    Test mouse reads
    2830003 353.36
    1085998 920.81
    1106998 903.34
    1099998 909.09
    1075998 929.37
    1079998 925.93
    1077998 927.65
    Paul is it worth it to add a second 64 byte Record for this plus an extra transfer? Note: The transfers are only 8 bytes I think, so could try to instead of Report and Report2, that if transfer size is < half of Report Size than double buffer...

    EDIT: actually If I move the mouse real fast... Then it shows near 1000...
    Code:
    1037998 963.39
    1033998 967.12
    1002998 997.01
    1010998 989.12
    1016998 983.29
    1019998 980.39
    Edit2: @mcrc - You might try using my branch mentioned or simply copy down the two modified files (USBHost_t36.h, hid.cpp)
    Last edited by KurtE; 09-16-2021 at 05:55 PM.

  9. #34
    Will try in a few minutes! That sounds promising.
    Thank you for all your efforts.

    Edit: Works perfectly fine!
    Last edited by mcrc; 09-16-2021 at 06:23 PM.

  10. #35
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,574
    Quote Originally Posted by mcrc View Post
    Will try in a few minutes! That sounds promising.
    Thank you for all your efforts.

    Edit: Works perfectly fine!
    Glad to hear that...

    @Paul - Issued PR... https://github.com/PaulStoffregen/USBHost_t36/pull/71

    Right now adds extra 64 byte buffer. Could hack it that only will create 2nd transfer if the transfer size < half the buffer size or some such thing...

Posting Permissions

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