Combining audio with VGA, without SD card or I2S interrupting display time :Teensy 4.1

Stamper321

New member
Hello,
I would appreciate some advice on the possibility of using the inbuilt SD card reader functions and Audio functions,
in ways that avoids seemingly random interrupt requests.

I have a project in creation ( started a very long time ago!) for the Teensy 4.1.
The game is a recreation of the Williams classic arcade game 'Robotron 2084'.
And its fully working, with steady 320 x 240 8 bit display, SNES controller, original sound effects,
authentic game play and realistic attract screens. Built around a game engine of sorts.
My problem is the tiny 'flecks' of disruption of the display, caused by either the SD card reader function or Audio function,
requesting interrupts in between interrupt driven pixel lines and causing an unwanted over run.
It's not a massive glitch, and at this stage of this project, more of an annoyance.
My question is, can the SD card and Audio functions be instructed to have their buffers refreshed at a predetermined time,
with predetermined buffer sizes set to last until the next 60th of a second , being only updated within each
vertical blanking area of my project.

I intend posting the code on Git Hub before long, with or without the 'fix'.
 
Hard to tell what will work, without you posting your code on GitHub. (Can I strongly suggest you have a main branch with known-working code, and one or more development branches for work-in-progress...)

Audio typically uses two interrupts, one from the hardware to copy DMA buffers to audio blocks, and another (triggered by the first) which executes the updates. The second is very low priority (208), the first typically uses the default (which I think is a medium priority of 128). The time is predetermined, but only by the audio sample rate. Hence for the stock 44.1kHz, you get 2x high priority interrupts per 128 samples, i.e. roughly every 1.45ms, plus a low priority one every 2.9ms.

A quick search suggests the SD code seems to have one ISR, which is extremely short; I can't see any code which disables interrupts, which is refreshing. However, SD card accesses can take a long time (40ms or more); because of that, you should avoid use of AudioPlaySdWav etc., because it accesses the card under interrupt.

It's not clear how your "interrupt driven pixel lines" work. I've not tried using VGA output on a Teensy, but I'm aware it's been done, I think using FlexIO, which possibly uses DMA and thus doesn't need precise interrupt timing / latency to work properly. I would think you'd be OK just to raise the priority of your VGA interrupt higher than 128 (i.e. lower number, like 64) - it'd delay audio and SD interrupt response times a bit, but as long as your ISR is short you shouldn't impact audio, and SD really shouldn't care.
 
Back
Top