CONTENTS

Home
Projects
More Projects
Resume
Computer Skills
Music
Links To Friends
Pictures
About Mike

Random Link
3D Images



Atmel ATmega168 MOS 6581 SID Player

Related pages on www.mikekohn.net: atmel rs232, atmel probe, picarus, msp430 guitar processor, 6581 Sound Chip, VGA On An FPGA

Contents

Introduction
Pictures
Schematic
Explanation
The Software
Sample Sound File
Download

Introduction

A long time ago I popped out all the custom chips out of a blown Commodore 64. Actually, I think the only thing that had really blown up in the system was the CIA chips, so I figured maybe one day the sound and video chips might be fun to play with. Years and years later (March 8, 2008 to be exact) I finally took the sound chip (also known as MOS6581 or SID - Sound Interface Device) and pushed the thing in a bread board. I added an OPA2134 opamp for the sound output, an Atmel ATmega168 for the CPU, and a DS275 chip to change TTL UART voltages to standard RS232 so I can hook this all up to a Linux or FreeDOS machine. The sound output of the entire system is run into a Mini-Marshall guitar amp.

My ultimate goal here is to write software for Linux or DOS that can in real time send songs through the Atmel chip into the SID to play music, hopefully .sid files. I actually might never bother to finish this, since I was really most interested in seeing if using only the documentation from the Commodore 64 Programmers Reference Guide I could get it to play sound.. which just today (March 9, 2008) I did :). I have to say, I find it interesting how in 1983 you can buy a book that has everything about a computer, including chip pinouts and schematics, but today everyone tries to keep how their hardware works as secret as possible. Sad.

Pictures (Click To Enlarge)

Explanation

So this circuit (as you can see from the labeled picture above) has basically 5 distinct pieces. The first piece to the circuit was getting 12v and 5v supplies. I accomplished this with the simple 5v voltage regulator circuit (duh). Since the output of the SID is 6v max, I used the 12v supply on an OPA2134 opamp giving me a 6v cushion to the rails which is quite nice. The opamp is a simple buffer and AC coupler circuit which removes the DC offset from the SID chip.

The next piece to the circuit is the SID itself. It runs both 12v and 5v. One thing to note is I couldn't find the 2200pF capacitors that the book recommended at Radio Shack so I ended up using 4700pf. I believe they are just used as filters and the only real requirement is they are identical. The book recommends a bypass capacitor both on Vcc and Vdd, but I elected not to put them in since it would ugly up the circuit. One important fact I found out the hard way: the 1k ohm resistor from the audio-out pin to ground needs to be there, otherwise it outputs some kind of garbage that almost works. I can already hear my EE friend Jeff Blevins saying "Did you read the spec sheet!?!?!?". Thanks Jeff.

The next piece of the puzzle is the Atmel ATmega168 microcontroller. The SID is connected to the ATmega168 through an address and databus. The address bus is the green wires and they are connected from the SID's A0-A4 pins to PORTC on the Atmel. There is a blue wire there too that gets connected to the last bit on PORTC. This is the chip select signal that is "strobed" from the Atmel chip to let the SID know there is a new value sitting on the databus to read in. The red wires from the Atmel to the SID are the databus. Unfortunately I did not have enough free pins on PORTB so I had to split it up between PORTB and PORTD. Yeah, it makes programming the thing a little more difficult, but I wired it in a way that would reduce the number of instructions needed (aka, no shifts needed on PORTD). CLKOUT from the Atmel chip is wired to the theta (clock in) pin on the SID. The Atmel here is running with a 4MHz resonator and is clock divided by 4. Btw, to make sure the SID never gets more than 1MHz, I set the CLKDIV8 fuse when programming the chip so clock out starts out at 0.5MHz.

The last piece of the puzzle is the DS275 chip. This is used to turn the TTL serial port voltages into RS232 voltages as shown in my Atmel RS232 project.

Note: as I found out today (March 15, 2008), the circuit above has an error. I forgot to jumper the +5v and ground strips from one side of the board to the other. I'm not sure how it worked at all, but all except the rs232 part was functional.

Schematic

Click here for a schematic

The Software

On the Atmel chip itself, I wrote some firmware that basically listens on the serial port for certain commands. A command of 0xfe means it should output 3 lines with the firmware version and copyright. A command of 0xff means two more bytes will follow. The second byte will be the address to "poke" to and the third byte will be the data to poke into that address.

On the Linux side, midi_sid_play.c simply parses a .mid file translating midi events into my protocol and sending commands over the serial port.

I was actually tempted to just make the atmel chip understand midi, but it seemed kinda worthless to me unless I fully implemented the hardware which I didn't really feel like doing. Plus I think I can't get my baud rate high enough running the chip at 1MHz. For a later project I might make a kernel module to create a /dev/midi device for the thing.. not because it would be useful, but just so I can learn how to make kernel drivers.

Sound Sample

The sid_player.mp3 file is the inv2v13a.mid file played through the midi_sid_play program into the circuit. I recorded this through a Shure SM-57 microphone into an M-Audio FastTrack Pro into Garage Band on a MacMini :).

sid_player.mp3
inv2v13a.mid

Of course for this project I had to use the Commodore 64 theme song :).

Download

sid_player-2008-03-16.tar.gz
sid_player-2008-03-16.zip

NOTE: This code is written for the ATmega168. This processor memory maps the UART registers into SRAM. Other Atmel chips might need in/out instructions instead. Using this as a guide it should be pretty simple.


Copyright 1997-2008 - Michael Kohn

Please visit my many other projects, including free J2ME Java games for Mobile phones, graphics and sound programs, chat software, and much more at http://www.mikekohn.net.

This page was designed to work with all standard HTML compatible webbrowsers including Firefox, IE, Safari, and Links.