I have a ‘Ben Eater 6502’ breadboard computer with the associated ‘World Worst Video Card’ breadboard VGA output solution.

It has been a ton of fun but one of the things I have wanted to accomplish is outputting some decent audio without adding any new chips to the system. This goal came with some challenges!

The way the video output works with this systems is that a couple of counter circuits and some simple logic maps 8 of the 16 available kilobytes of system RAM as a simple bitmapped display of 128x64 with 28 ‘off screen’ pixels on the right side to account for the Horizontal Sync time needed for VGA signals. While the screen draws, the 65C02 CPU is halted for this Horizontal Sync (Hsync) between lines as well as the Vertical Sync (Vsync) between each frame. All this means that the CPU is available just 28% of the time!

This would cause issues directly outputting audio with a direct PCM/PWM ‘bit-bang’, as used on systems like the Apple II.

As an alternative, I have tried using the ability to output a square-wave on pin PB7 of the 6522 VIA for simple square wave music, but the audio results were less than impressive.

See my ‘Bad Apple! Demo’ for an example of simple square wave music on the system:

While I am sure better results could be achieved in more musically inclined hands, what I really want is streamed digital audio and sample based music.

One of the other ways that digital audio was often added to 8 bit systems was to attach a simple resistor ladder DAC to a parallel port. This is problematic in my case because of the way my SD card is attached to the system, leaving few available pins, the limited amount of time the CPU is available, and because I arbitrarily want to do this as simply as possible!

Testing has shown that there are several rates that I can output at a regular intervals without the Hsync and Vsync causing extreme ‘jitter’, but with the limited CPU cycles and a desire to do other things like update animations, I’ll need to keep that rate around 3,000 samples a second or less.

The alternative I use in the next example is to send out 1 bit PCM audio over the serial port at a rate of 25,256 bits a second with some 6502 Assembly code. This is how I get around my lack of hardware and the 72% of the time the CPU is halted. I use the serial port as an 8 sample buffer, with each sample being just 1 bit. This means that instead of around 3,000 8 bit samples a second I can output 25,256 1 bit samples a second! This gives me a good Nyquist-Shannon frequency of up to 12,000+ Hz while only using 3,000 bytes a second of data.

It also allows me to put my unused VIA serial port to good use by directly driving a speaker!

The only additional hardware is an inline 100ohm resistor and a 47uF capacitor to provide current limiting and to block DC as suggested by Garth Wilson at 6502.org. I don't want to burn out the serial port by directly powering a bookshelf speaker with it!

As a happy side effect of this limiting RC circuit, since the speaker itself acts as an inductor, the waveform output is very close to what you would see in a ‘Differentiator’ circuit (See: https://ecstudiosystems.com/discover/textbooks/basic-electronics/wave-shaping/differentiators/), with the only difference being that with audible range square waves as an input the voltage in the plateau between the positive and negative spikes of the waveform is slightly above zero. I guess that makes this the output of a RCL circuit?

While this waveform (in blue) looks nothing like either the square-wave input (yellow) or the original audio waveform, it causes the attached speaker to move in a way that is closer to replicating the original audio waveform than a pure square-wave would, having both positive and negative waveform components.

It is not at all smooth like the original audio waveform and is very 'spiky'. The mass of the speaker itself is doing a lot of the heavy lifting when it ...

Read more »