Audio DAC

I thought it would be nice to have some audio output a little more sophisticated than a simple 1-bit software-toggled speaker. An R/2R network would typically need 8 output bits for phone-quality audio, 16 or more for CD quality. PWM outputs use just one bit, but this has to be clocked at 256 or 65536 times the audio sampling rate for 8 or 16 bit resolution.

Fortunately, the huge consumer market for CD players means there are many CD-quality DACs on sale. They are all fed 16-bit data samples, but often filter and convert them at up to 24-bits per sample. Shopping around, I expected to see many cheap CD DACs for sale. Looking in the RS catalogue (and I appreciate this is not the best place to look for cheapness), DACs are surprisingly expensive. Granted, many are for non-CD applications, but you'd hoped to see just one cheap CD DAC in a few-pin package.

So I had a look through what was on offer and found the MAX549, with the following features:

GND 1 -MAX-
-
549-
8 VCC
OUTA 2 7 REF
!CS 3 6 OUTB
DIN 4 5 SCLK
Pin Names and functions
!CS Chip select
OUTA, OUTB Outputs, unbuffered (Zout ~ 33k3)
DIN Serial Data In
SCLK Serial Clock, shifts data on rising edge
Vcc Power (2V5 to 5V5 DC)
GND Ground

It was readily available from RS catalogue, so I bought one. I plugged it into my project and it failed to show any sign of life. I checked my tiny test code and could not see anything wrong.

I went to order a replacement, but RS had discontinued it!!! The nearest alternative is the AD3703. It is slightly more expensive but at least it comes with output buffer amps which reduce the output impedance a lot and negate the need for further buffering. Analog Devices are very experienced in ADC and DAC chips, and their pin placement looks better.

OUTA 1 AD
-
7303-
8 OUTB
VDD 2 7 !SYNC
GND 3 6 DIN
REF 4 5 SCLK
Pin Names and functions
!SYNC Synchronise voltage out with data in
OUTA, OUTB Outputs, buffered (Zout ~ 40R)
DIN Serial Data In
SCLK Serial Clock, shifts data on rising edge
Vcc Power (2V7 to 5V5 DC)
GND Ground

Obviously 16 bits could be better, for CD-resolution, but this pushes the price up a lot and such chips tend to be surface mount.
It also puts more burden on the host CPU to store and move data. Eight- bit resolution is good enough for games and speech.

The serial signals for CD DACs usually consist of serial data, serial clock, and a left/right clock. The latter selects which DAC channel receives the shifted data.

The MAX549 doesn't use this scheme though. Instead, it uses !CS to clock samples from the data shift register into the DACs. There are 16 data bits clocked in per conversion, the first 8 are control bits, the second 8 are the actual sample.

Dual-system interface

The two different schemes can be accommodated by assigning the following FPGA pins:

Left/Right Clock Used by CD DACs only
Serial Data Format depends on standard selected
Serial Clock Shifts data on rising edge
!CS or !SYNC Used by MAX549 or AD7303 only

The FPGA can contain logic to output in either format.

Sampling rates

There are various sampling rates used throughout the world. There is not much scope for common crystal clocking, though a few moments scribbling suggests an 18.432 MHz master clock would be useful:

Rate/Hz Chans Bits Application Using 18.432 MHz master clock
Divisor Freq./Hz Application Error/%
8000 1 8 Telephony 288 64000 8 x 8000Hz Telephony 0
8192 1 8 Telephony 280 65507.14... 8 x 8192Hz Telephony -0.044
44100 2 16 CD standard 26 708923 16 x (44307+11/16). 0.47
48000 2 16/24 Audiophile Music 24 768000 16 x 48 kHz 0
96000 12 1536000 16 x 96 kHz 0
192000 6 3072000 16 x 192 kHz 0
        10 1843200 16 x 115200 (PC max baud rate) 0

However, I have got TV-colour carrier crystals in my system, so these give larger errors:

Application NTSC master clock
(315/22 =14,318,181.
81)
PAL master clock
17734475
Divisor Freq./Hz Error/% Divisor Freq./Hz Error/%
8 x 8000Hz Telephony 224 63920.45 -0.124 277 64023.37... 0.036
8 x 8192Hz Telephony 218 65679.7... +2.19 270 65683.24... 0.225
16 x 115200 (PC max serial port baud rate) 8 1789772.72 -2.9 10 1773447.5 -3.78
16 x (44100). CD standard 20 715909.09 +1.46 25 709379 +0.535
16 x 48 kHz (Audiophile Music) 19 753588.5... -1.87 23 48191.50... +0.4
16 x 96 kHz (Audiophile Music) 9 1590909.09 +3.57 12 92367.05... -3.78
16 x 192 kHz (Audiophile Music) 5 2863636.36 -6.78 6 184734.11... -3.78

The figures above suggest that it might be best to:

The PC itself uses NTSC master clock for timing, so it may not be spot-on accurate for audio either.

Anyway, my main interest is getting an audio port to get simple sound effects to TVs or cheap speakers. Neither of these are hi-fi, and 8-bits will do. NICAM is a possibility, but requires extra analogue modulation and is not present in all TVs - especially not the cheaper ones.

If precise sound playback rates were to become an issue, there is a chip that will generate them from a 14.31818 MHz crystal: the MK1412 from ICS is designed for systems using 32 kHz, 44.1 kHz, 48 kHz and 96 kHz sampling rates. Output clock frequencies of 256 x and 512 x of the audio sampling rates compatible with most DACs.

S1 S0 CLK      CLK/2  Accuracy
0 0   16.384   8.192   1 ppm	256 * 32   kHz
0 1   22.5792 11.2896 25 ppm	256 * 44.1 kHz
1 0   24.576  12.288   1 ppm	256 * 48   kHz
1 1   49.152  24.576   1 ppm	256 * 96   kHz

 

Status

This chip is now working. I first used software to load the DACs. This verified they were actually working. A machine code program to ramp through 256 values produced a waveform at around 13 Hz. I then designed a circuit to load the serial bits automatically, so that the CPU is not burdened by this process. Each load takes about 1 microsecond, faster than the CPU can write the 8-bit value. The sawtooth now sounds more like a musical note than a buzz, and random values are a hiss not a rumble.

Most sound-generator projects present a parallel output for driving an R/2R ladder or parallel-loading DAC chip. I created a small logic block to trigger DAC loading whenever a change in the parallel bits is detected. This minimises the fast serial traffic, and therefore power and RF emissions.

The LM386 amplifier seems to be working fine. Worth noting that my mono speaker portable takes audio left and right, so the simple buzzer output can connect to one while the DAC connects to the other.