DE BLAUWE SCHICHT on the WORLD WIDE WEB

Main

Tinkering
    ETOPO1
    QL Keys (1)
    QL Keys (2)
    Atari2USB
    MOS 6581 (1)
    MOS 6581 (2)
    Indy battery
    C64 and BT

Writing

Pictures

Retrogaming

Machines

About

Using the MOS 6581 SID chip (part 1)

Much has been - and is still being - said and written about MOS Technology's SID chip. SID stands for "Sound Interface Device"; it was designed by Robert Yannes in 1981 and subsequently used as the sound source in the enormously successful Commodore 64 home computer. In present times the SID is still used for its distinctive sound, both in its original environment (i.e. the C64) and in newer applications. In my collection of old computers there is a defective C64; I salvaged the 6581 SID that lay dormant therein to learn more about this legendary device and how to interact with it.

Extraction

Step one is to remove the SID chip from the C64. This is a tricky job; the 28-pin DIL package is soldered directly onto the main board and it requires care and patience to liberate the SID without damaging it. This YouTube video offers helpful information for getting this done (apparently desoldering components from old PCB's can be made a lot easier by first resoldering the pins with new solder). Incidentally, SID chips can also be found on on-line auction sites like ebay (but beware, rumor has it that there are defective and non-functional counterfeit ones on the market advertised as the real thing).

Atari2USB schematic
The SID and part of the C64 main board from which it has been removed. At this time it is not yet known whether the chip has survived the desoldering or not.

Anatomy

Now that the chip is removed, it is time to investigate its anatomy. The folks at 6502.org have made available a PDF of the (preliminary) version of the datasheet. This document provides the necessary information to operate the SID, including pinout, register description and an example application schematic.

SID electrically and diagramatically
ID pinout and functional diagram; taken from the historical datasheet. Click on the image for more pixels.

From a programmer's perspective, the SID consists of a number of registers that control three voices. Each voice can be set to a frequency, a volume envelope and a waveform (and pulse width when applicable). A further register controls volume and filter characteristics, and acts on all three voices at once. These are all write-only registers; there are also a number of read-only addresses that return values for two potentiometers (if attached) after digitization and data derived from voice 3 that can be used for modulation effects.

The pinout shows an address bus and a data bus (A0-A4 and D0-D7, respectively), through which the SID's registers are selected and programmed. These are augmented by various controls, namely Reset, Read/Write Select, and Chip Select. Further important connections are Phi2 for the 1 MHz clock signal, the Audio Out pin and the Vdd and Vcc supply voltage pins. For the operation of the built-in filter two capacitors are to be connected as well. Lastly, it is possible to connect an input signal and up to two potentiometers can be attached to the built-in 8-bit AD converters.

It is important to note that there have been a number of incarnations of the SID. The one under scrutiny here is the MOS 6581, with a Vdd of 12V. A later version, the 8580, is an improvement in various ways, and requires a Vdd of 9V. Vcc is the familiar TTL-level voltage of 5V.

Reviving SID

Motivating the SID to produce sound involves two distinct tasks: first to provide the necessary electrical environment for the chip to work and second to properly program the registers mentioned earlier.

Appendix C in the datasheet provides a schematic that illustrates how to electrically connect the 6581. True to its origins, the chip is shown there to be associated with a "650x MPU" as the controlling entity (the microprocessor in the C64 is actually a 6510).

SID registers
SID application example; taken from the datasheet.

For demonstrative purposes and simplicity, all addresses, data, and control lines will be manipulated by manual switches in this realization. The remaining other necessary input - the 1 MHz clock signal, normally provided by the microprocessor - is to be generated by a microcontroller. An Arduino (in this case the Arduino Nano) features a number of counters and timers that can be used for that purpose; its internal 16 MHz clock can be devided to the required 1 MHz signal on its D9 ouput pin.

Although the initial object of this project is to directly control the inputs and subsequent behavior of the SID through physical switches, the Arduino involved will also act as a latch for the switches. Incorporating a microcontroller from the start will make future addition of serial, network, or MIDI connectivity easier later on.

The schematic below shows the implementation of the latching Arduino, along with the control lines and how they are connected to the SID. There are thirteen (5 address + 8 data) switches connected to A0 through A4 and D2 through D8 plus D10, respectively. The switches can be read by the microcontroller if the aforementioned pins are configured as inputs, with activated internal pull-up resistors. The software running on the Arduino monitors the state of digital input A5; when the "enter" switch is activated and A5 therefore becomes a logical 1, D13 is made "low" by the software, and the address and data switches can be read and stored. D13 is then set to 5V again and the address and data switches become ineffective. Next, all address and data pins on the Arduino are reconfigured to digital outputs, and the values that were read from the switches are copied to the outputs (the diodes in series with the switches prevent aliasing or "ghosting" during the reading phase).

Nano and SID
Arduino Nano and SID.

CS (Chip Select) on the Arduino's digital output D12 is subsequently set to "low", which causes the SID to read the bits on its address and data buses (presently, R/W is always set to write or "low"). Finally, CS is returned to "high" and the next programming cycle can begin. A sketch that takes care of the plumbing in the Arduino can be downloaded here.

SID on life support
Let's call it FrankenSID.

The procedure for programming the SID is now as follows:

  1. Reset the SID;
  2. Manually set the address of the register of interest, and the data to be written there, using the appropriate binary switches (see image above);
  3. Close and release the "enter" switch;
  4. The Arduino, triggered by the enter switch, configures the appropriate I/O pins to logical inputs; the switches are activated by bringing their common side to 0 V; subsequently, the state of the switches is read and stored, followed by deactivation of the switches (common is set to 5V);
  5. The logical inputs of the Arduino are reconfigured to logical outputs; the stored state of the switches is copied to the outputs;
  6. The CS signal is briefly set to 0V, causing the SID to read the address and data inputs, provided its R/W input is set to "low" and a clock signal is present.
  7. Repeat from 1.

Programming SID, the slow way

On the C64, a user can use the built-in BASIC programming language to generate music and sound effects by setting values in the SID registers using "poke" instructions. Chapter 8 in the Commodore 64 Microcomputer User Manual gives information on how to program simple melodies, and more importantly, descriptions of the various registers and how to use them. The table below (again reproduced from the datasheet) gives a concise enumeration of the controls that are at the user's disposal:

SID registers
SID register description; taken from the datasheet.

A difference between the current implementation and the C64 is that in the latter the SID is approached with a 54272 byte offset added to its register addresses. That is, the registers are mapped to a memory location starting from 54272 and ending at 54300. In this case however, no offset is present and the primitive addresses are to be used. Chapter 4 in the Commodore 64 Programmer's Reference Guide gives a convenient and short example on how to program SID to produce the sound of a bell using ring modulation:

10 S=54272
20 FOR L = 0 TO 24: POKE S+L,0: NEXT
30 POKE S+1,130
40 POKE S+5,9
50 POKE S+15,30
60 POKE S+24,15
70 FOR L = 1 TO 12: POKE S+4,21
80 FOR T = 1 TO 1000: NEXT: POKE S+4,20
90 FOR T = 1 TO 1000: NEXT: NEXT

The program resets the SID chip, writes various values to the frequency and volume envelope registers, sets volume to maximum, and starts (and stops) a bell-like sound twelve times. With the register map in hand, a simpler version of the above can be input in binary on the SID using the manual switches:

Address Data Comment
------- -------- -----------------------------------
00001 10000010 Set Frequency of voice 1
00101 00001001 Set Attack/Decay of voice 1
00110 10000000 Set Sustain level of voice 1
11000 00001111 Set maximum Volume
00100 00010001 Set Triangle waveform and Gate bits

The animation below shows this sequence being entered on the binary switches. Two power supplies are used here; one providing 5 volts, the other 12 volts. The oscilloscope in the background displays the signal on the output pin of the SID chip. Note the frame marked 4/5: setting the volume to maximum results in an increased noise level, which can just be discerned on the oscilloscope screen. The switch setting seen on the final frame triggers the generation of the triangle waveform as can be seen on the display. Click on the image for the stills making up the sequence. (And oh yes, apparently the SID works!)

Look, sound!
Look, sound!

To do

Clearly it would be rather cumbersome to play melodies or elaborate sound effects in this manner. The next step therefore is to control the SID through a serial link with a computer or musical keyboard, but that will be the subject for the next article.

  • Interact remotely.
  • Add code to read data from registers 25 - 28.
  • Build a nice box with blinkenlights.

Credits/useful URLs

  • 6502.org has the 6581 datasheet, and more!
  • Surf here for the Commodore 64 Programmer's Reference Guide.
  • Arduino coding was done using version 1.0.3 of the development software.

(Originally written 2013/03/11 and 2013/03/27)

Back