Close

Improving microphone handling with Fast IO

A project log for Street Sense

Portable electronic device to measure air and noise pollution

mike-teachmanMike Teachman 12/28/2018 at 17:430 Comments

The previous log outlined some concerns with microphone handling delays caused by delays when the loop yields to the uasyncio scheduler (e.g. the measure delay of 6ms).  I explored the use of an alternative uasyncio library called Fast IO. The Fast IO library adds a high-priority I/O queue to uasyncio.  This allows a coroutine to be given higher priority than other coroutines that are waiting to run.

I changed the microphone coroutine to use this high-priority queue and ran some performance tests.  The change was done in one line - I used a high-priority millisecond timer in place of the the standard uasyncio sleep timer.  Using this new timer results in the microphone loop getting scheduled in a high-priority queue -- the microphone loop will run before any of the other coroutines.

With this change the yield time in the microphone handling loop was reduced by about 20%.   More importantly, the change insures that the time-critical microphone handling loop always gets priority over other waiting coroutines.  This will greatly reduce the risk of overruns in the received DMA sample buffers.

Discussions