Investigating Latencies

Hey people,

for a project of mine I need high speed on the MIDI output. 
I took the NG-firmware and cleaned it from all the stuff that I do not need. Also I added this line to my app.c which speeds up the scanrate of the SRIO significantly

MIOS32\_SPI\_TransferModeInit(MIOS32\_SRIO\_SPI, MIOS32\_SPI\_MODE\_CLK1\_PHASE1, MIOS32\_SPI\_PRESCALER\_8);

I think the standard prescaler is at 64 or so. This gives me an ultra high scanning frequency for the SRIO chain and it works great. I can not see any loss of data.

My setup looks like this: I have the core and a DIO-Matrix connected to it. I connected a simple switch to the DIO-Matrix which sends a note event to the midi-port. 
I connected my oscilloscope to this setup. The first channel is directly connected to the switch, the second channel is connected to the midi-output. Due to the open-drain-mode of the MIDI-out I need to bridge pin4 and pin5 of the midi-jack to get accurate results. The wiring of the MIDI-out is straight forward: Pin 4 is connected to +5V via 220Ohm. Pin 5 is connected to the core via 220Ohm.

So what I notice here is the time between pressing the switch and the midi-out signal differs any time I press the button. Sometimes it’s only 100-200us, sometimes it’s more than a millisecond. 

I’d like to know where this comes from and if it’s possible to minimize this latency. 

Also I’d like to know why the gap between pressing the switch and midi-out signal differs and doesn’t stay the same (which would I expect if there is a buffer involved).

We had a discussion about speed in the past:

http://discourse.midibox.org/t/topic/19817

 But even if I change the baudrate or buffersize of the midi-out, the latency stays. 

Any ideas?

Thanks,
Chris

Just now, FantomXR said:

So what I notice here is the time between pressing the switch and the midi-out signal differs any time I press the button. Sometimes it’s only 100-200us, sometimes it’s more than a millisecond. 

I’d like to know where this comes from and if it’s possible to minimize this latency. 

This is normal, MIDI processing in MIOS32 is a periodic Task called every ms. So if you push your button just before the task you will get " 100-200us " if it’s just after it will be something like 1ms.
 

Just now, Antichambre said:

This is normal, MIDI processing in MIOS32 is a periodic Task called every ms. So if you push your button just before the task you will get " 100-200us " if it’s just after it will be something like 1ms.
 

Thanks! I thought it’s something like that. Is there a chance to halve that?

Not without changing MIOS32 code, what I will not advise

But if you want to try it anyway everything happens in (root)/trunk/programming_models/traditional/main.c
The Hook is MIOS32_MIDI_Receive_Handler(APP_MIDI_NotifyPackage) in TASK_MIDI_Hooks.

you will need to know about freertos.

Good luck :wink: