USB MIDI Interface

Post a reply


This question is a means of preventing automated form submissions by spambots.
Smilies
:D :) :( :o :shock: :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen:

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: USB MIDI Interface

Re: USB MIDI Interface

Post by horo » Sun Apr 02, 2017 5:41 pm

Hi,

me again. I've cleaned up the attiny85 midi code at bitbucket, added pwm out and a 2nd analog input.

Possible tested I/O functions are:
PB0: Digital input or digital output or pwm output.
PB1: Digital input or digital output or pwm output (active high LED attached).
PB2: Digital input or digital output or analog input ADC1.
PB3, 4: USB data lines.
PB5: 1 analog input (ADC0, shared with the /Reset function, but you can apply a voltage between Vcc/2 and Vcc -> 512..1023 without resetting the device).

Ciao, Martin

EDIT 20170403:
I did some timing tests with an empty main loop, PB1 toggles every 3µs (idle) with a gap of 150µs (USB transfer) every 2ms.
So we still have >90% CPU time for our program available. This looks similar to my measurements from 2009.
Test system: Lenovo T400 with Linux 4.10.8-towo.1-siduction-amd64 #1 SMP PREEMPT siduction 4.10-14 (2017-03-31) x86_64 GNU/Linux.

Short test on Win7 -> USB transfer every 8ms.

Win / Mac users: please double check on your systems.

Code: Select all

int main(void) // test loop
{
   uchar iii, value;
   uchar midiMsg[8];

   DDRB |= 2;      // LED pin output
   PORTB |= 2;      // LED on

   setName( 0 );

   usbDeviceDisconnect();
   for(iii=0;iii<20;iii++){  /* 300 ms disconnect */
      _delay_ms(15);
   }
   usbDeviceConnect();
   PORTB &= ~2;      // LED off

   wdt_enable(WDTO_1S);
   usbInit();
   sei();
   value = 0;
   for(;;){    /* main event loop */
      PORTB ^= 2;   // toggle LED while idling
      wdt_reset();
      usbPoll();
      if ( usbInterruptIsReady() ) {   // prepare and start USB transfer
         iii = 0;
         midiMsg[iii++] = 0x0B;
         midiMsg[iii++] = 0xB0;
         midiMsg[iii++] = 70; // cc 70
         midiMsg[iii++] = value++;
         midiMsg[iii++] = 0x0B;
         midiMsg[iii++] = 0xB0;
         midiMsg[iii++] = 71; // cc 71
         midiMsg[iii++] = value++;
         usbSetInterrupt(midiMsg, iii);   // transfer message
         if ( value > 127 ) {
            value = 0;
         }
      }
   }
   return 0;
}

Re: USB MIDI Interface

Post by horo » Thu Mar 30, 2017 6:31 pm

Hi,

after a quite long time I've added a new demo project - V-USB-MIDI-ATtiny85.
Runs on a real cheap development board, e.g. Digispark - available as china clone for about 1..2 € or $.
Image
Image
The board has it's own USB bootloader - no need for a programmer - connect via USB and download your *.hex :)
16.5 MHz without xtal, 1 key input,one potentiometric analog input.
MIDI out is also possible, e.g. PWM or digital.

Have a look at my Bitbucket.

Ciao, Martin

Re: USB MIDI Interface

Post by winelight » Fri Mar 24, 2017 4:26 pm

I think the exchange rate is determined by the operating system on the PC and how quickly it polls the USB port. Obviously there is an upper limit imposed by the speed of USB too.

Re: USB MIDI Interface

Post by Claudiu » Tue Jan 24, 2017 3:38 pm

Hello,

Does the VUSB MIDI work with latest linux kernel versions still with 2ms high speed?

Thx in advance

Re: USB MIDI Interface

Post by Coda » Thu Jan 28, 2016 9:20 am

@jokkebk - no the USB does not cause an issue with 31250 baud serial comms, I have successfuly programmed a MIDI-USB cable using a tiny4313 which can handle large streams of sysex in both directions. It sounds like you are getting an overrun because you are not doing any flow-control. You need to make a buffer of at least 16 bytes in ram (I used 32), so that the receive routine has got somewhere to store incoming bytes for the USB routine. Then you need to make sure you are servicing USB requests every 1 millisecond (check the binterval, as written above by 'Eye').

Re: USB MIDI Interface

Post by jokkebk » Mon Jan 11, 2016 12:48 am

Hi all!

Thanks to Martin for the great V-USB MIDI efforts. I combined Adafruit Trinket USB HID keyboard code and MIDI project to arrive at Adafruit Trinket & Pro Trinket MIDI library:

https://github.com/jokkebk/TrinketMIDI

Unfortunately, my ultimate goal wiring the Pro Trinket hardware UART RX line to a old school MIDI connector (via optoisolator of course) has failed. It may be bugs in my code, but because ATmega328's "data overrun" flag in USART registers is getting set, I'm suspecting V-USB communication under OS X is taxing the MCU too much to receive 31 250 baud UART transmissions (there's only 2 byte FIFO in the thing, Trinket ATtiny85 did not even have HW UART so that was useless).

Does someone know how long V-USB interrupts, usbPoll and sending the MIDI packet takes? Based on quick calculation, two bytes of 8N1 MIDI data take 640 us. Is there a way to measure V-USB processor usage? Oscilloscope? Timing usbPoll()? Timing usbSetInterrupt()? It would be helpful if there was documentation how different parts of V-USB work together to even puzzle out which methods take up the most time...

Re: USB MIDI Interface

Post by winelight » Mon Sep 14, 2015 9:38 am

OK I did remember eventually. But in usbport.sys in W10 I can't find any of the relevant byte sequences.

So I did some research and it appears that Microsoft has removed the poll rate limitation in Windows 10.

Re: USB MIDI Interface

Post by winelight » Wed Aug 05, 2015 11:45 pm

I am guessing (it is only a guess) that it will be similar to 7 and Vista; but at a different location and with a slightly different byte sequence. Next week I may have time to take a look if that will help (and if I remember!).

USB MIDI Interface - W10?

Post by jasmin » Wed Aug 05, 2015 11:02 am

Ok, there's a solution for Vista and W10, what's about W10?

jasmin

Re: USB MIDI Interface

Post by winelight » Mon Jan 19, 2015 10:00 pm

Thanks for that - looks great. I imagine it must be similar on Vista; will do some work on that when I get a chance.

(edit) On Vista the location is different (on mine it was 01f824) and the byte sequence is slightly different too:

3C 08 73 09 C6 86 1E 01 00 00 08

Note the two 08s are in the same relative position.

Re: USB MIDI Interface

Post by Eye » Mon Jan 19, 2015 8:04 pm

I've found a solution for the latency (slow interrupt transfer) problem in Windows 7 32-bit.
You have to patch usbport.sys file. USBPORT_OpenEndpoint() function in the USB port driver limits polling period to 8-32 range. Here is the lower limit checking code:

Code: Select all

00009e18: 3c08            cmp al, 8                    // compare with 8
00009e1a: 7309            jnc loc_00009e25             // skip if greater than or equal to 8
00009e1c: c6831a01000008  mov byte ptr [ebx+11ah], 8   // set interval to 8

So, for example, to change the limit to 1, search for the sequence:
3C 08 73 09 C6 83 1A 01 00 00 08
and change to:
3C 01 73 09 C6 83 1A 01 00 00 01

Tested with usbport.sys 6.1.7601.18251 and .18328 (offset for the sequence = 00009e18).

Warning: Windows 7 allows only signed drivers to be loaded, so you have to sign modified usbport.sys before replacing the original file.
1. copy C:\Windows\System32\drivers\usbport.sys to some folder
2. patch the copy of the file with a hex editor
3. run Driver Signature Enforcement Overrider (DSEO) and enable test mode
4. run DSEO again and sign the patched file (check if the file has changed its size after signing)
5. replace the original usbport.sys with the signed copy (use Se7en File Replacer)


Don't forget to change bInterval values in your project's Interrupt IN/OUT Endpoint Descriptors. bInterval=1 seems to work fine - tested with long sysex dumps.

Re: USB MIDI Interface

Post by winelight » Tue Apr 08, 2014 1:40 pm

There is nothing that can be done on Windows 7. I don't know about Windows 8.

Re: USB MIDI Interface

Post by Fabian » Tue Apr 08, 2014 1:25 pm

Hi,

any improvements of the 8ms problem on windows? I saw tests some pages above with linux, but how is windows performing?

Thank you
Fabian

Re: USB MIDI Interface

Post by winelight » Tue Jun 18, 2013 9:56 pm

Unfortunately that patch only helps mice, I eventually discovered. This is a real problem on Windows and really the only option is to use something else in most cases. Windows XP has a higher polling speed, but the application I run needs a minimum of Windows 7 and ideally Windows 7 64-bit.

Re: USB MIDI Interface

Post by Guest » Tue Jun 18, 2013 9:27 pm

I've used this library to build a little CV/Gate interface and it's working great on OS X (>= 10.6.3+ when they removed the "sanity check" on the poll interval), iOS and Linux, but on windows we are limited by the 8ms poll time. I am wondering if someone has successfully tried to patch system drivers to overcome this limitation - looks like it's a common practice among gamers who want to increase the poll rate of their mice.

Top