Navigation
Home & news
Random page
All pages
Site search:
Databases
Fortune cookies
Haikus
SID themes
Page collections
Blag
Chip music
Games
Hardware projects
Music downloads
Obfuscated programming
Piano music
Sane programming
Scene productions
SID related pages
Software downloads
Video downloads
Featured pages
Autosokoban
Binary Art
Brainfuck
Chimney claw
Chopin romance
Craft
Fratres
Freecell
Hardware chiptune
One man and his piano
Paraforce
Plasma
Remote control
Reverberations
SID septet
Slaepwerigne
Stranded
Syntax highlighting
TTY demystified
Townwoofer
Turbulence
Warpfruit
Forum
Register
Log in
Latest comments
Feedback
  • Swedish content
  • Personal content
  • Offensive content

The hardware chiptune project

by kryo

Download:

Normally, when you create a chiptune, you start with an existing chip (such as the SID chip or the YM2149) and write a tune for it. We decided to start from scratch, and create a chip and a tune.

It all started at St. Lars Meeting III, an oldschool demo party held in Lund. Yarrick, flex and I were there. I had gotten the idea for the project on the day before the party, so things were a bit spontaneous, and we had to make do with whatever components I had laying around.

In the beginning, we used a homebrewn AVR programmer, which I had built as part of a course in mechatronics. flex valiantly supplied the USB-to-serial adapter. However, at one point we started experimenting with the so called fuse bits of the AVR, basically trying to make the processor run at 8 MHz instead of the default 1 MHz. When we did this, the AVR programmer stopped working.

Luckily, I had brought some spare microcontrollers, but we knew that we'd eventually need those 8 MHz anyway. So we called Laban on the telephone, and asked him to bring his STK500 (a commercial AVR programmer). In order to use it, we realized that we needed some software, so Yarrick downloaded avrdude, using his mobile phone as an internet gateway. (Did I mention it was an oldschool party?)

chiptune stlarschiptune stlarschiptune stlarschiptune stlars

We wrote all the sound-reproducing software at the St. Lars meeting. One particularly interesting bug that kept us wondering was the fact that when we tried to multiply two integers on a particular source code line in the interrupt routine, all sorts of weird things would occur. If we commented out the multiplication, things would work. However, there were other multiplications in the interrupt routine that did work. The "weird things" were that, for instance, we wrote a constant to an output port at startup, and never wrote to that port anywhere else in the program; but when we un-commented the multiplication in the interrupt routine, that output port emitted a quite different signal.

This confused us to no end, until we looked at the generated machine code and started counting the clock cycles. Apparently, the multiplication was the final straw that caused the interrupt routine to run for too long. Before the interrupt routine would finish, another interrupt would occur, causing a new frame to be pushed onto the stack. The stack would fill up and the new stack frames would overwrite RAM and eventually the I/O registers.

This meant that we would have to rewrite the interrupt routine in assembly language.

Once we had the software up and running, we had to compose a chiptune. I had been experimenting with chip trackers before, so I re-used some code, and hooked it up to the sound routine, which was quickly ported from the AVR.

Unfortunately the party was very noisy, and we were sitting just below a loudspeaker, so it was quite impossible to compose anything. Since I lived nearby, and had recently had a cold, I was sleeping at home. So, this night I went home, got some sleep, and wrote the chiptune in the morning.

Sadly, when I got back, the party was already over. There were several people left, but the lights were on. I asked the crew if we could stay for an hour or so, and see if we could get it to work (which would have been nice, because then we would have completed the whole project in just one weekend). We were allowed to stay, but alas, the chiptune that I had written was too large to fit into the 8 KB of flash ROM together with all the code. This was such a setback that we had to give up.

I brought it all home, and ordered a few new components (in particular, a resistor ladder, so that we wouldn't have to use discrete resistors for the D/A conversion). flex and I also discussed various ways of compressing the song data.

chiptunechiptunechiptunechiptune

Eventually, we managed to cram it all into 8 KB. We couldn't use any standard compression algorithms, since we were so low on RAM (i.e. there was no room for the unpacked data). Instead, we devised a solution involving variable bit-length data structures and lots of bit shifting. We also removed one of the command tracks; as you can see in the tracker screenshot, every note can be followed by two effect commands. To save space, we removed support for the second command, and edited the tune to cope with this new limitation.

At this point we had decided to bring the project to Birdie 17, and participate in the wild compo.

The time had come to move the project from the solderless protoboard. The technique of using schematics printed on paper, glued to a veroboard, is part of the rapid prototyping method taught in the mechatronics course. I wrote the schematics in PostScript, using a set of functions that I had designed during that course.

chiptunechiptunechiptunechiptune
chiptunechiptunechiptunechiptune

We ended up with a 5th place in the Birdie wild compo. That's actually good, given that it was a non-technical audience. The winning entries featured humour and/or singing girls, of course. =)

Here's the Pouët page for the chiptune project.

Posted Saturday 30-Jun-2007 11:04

Discuss this page

Disclaimer: I am not responsible for what people (other than myself) write in the forums. Please report any abuse, such as insults, slander, spam and illegal material, and I will take appropriate actions. Don't feed the trolls.

Jag tar inget ansvar för det som skrivs i forumet, förutom mina egna inlägg. Vänligen rapportera alla inlägg som bryter mot reglerna, så ska jag se vad jag kan göra. Som regelbrott räknas till exempel förolämpningar, förtal, spam och olagligt material. Mata inte trålarna.

Anonymous
Wed 6-Feb-2008 22:15
You've got a lot of patience to do all of that. I'd say fuck it half through. Keep up the good work though.
Anonymous
Mon 7-Apr-2008 05:57
Nice job you did. I will study the work you made and try to learn from it. Iĺl put a post on my blog about it as soon as possible.
Jeronimo, from Brazil
www.blogdoje.com.br
Anonymous
Mon 7-Apr-2008 10:32
Great Job, impressive!

One small hint for prototyping boards. The vertical "bridges" are looking a bit messy (i know, its a prototype).

Before using silver wire: Unroll 1 Meter of wire, attach it to a fixed object, grab the other end (with a gripper) and pull it hardly. Now you have very straight silver wire which looks quite nice :)

Thx for the idea of gluing the layout onto the board, i will give it a try....

kiu
Anonymous
Fri 25-Apr-2008 12:18
can i use this as a project for college?

i mean, could u tell me what i need to build it?

like the components?
Anonymous
Mon 28-Apr-2008 00:53
You should compose some nice tunes for it and share them :)
Anonymous
Fri 2-May-2008 17:20
AWESOME!

What diode did you use? I just started to order all the parts needed ;-)
Can i use any standard diode at the 9V power source?
Anonymous
Tue 6-May-2008 21:06
Is the AMplifier chip actually needed? My electronics shop do not have those. Can i use a LM386 instead?
Anonymous
Wed 7-May-2008 21:41
Use external audio DAC, you got much better sound quality... This is my simple MOD player based on ATMEGA32 and TDA1543:
http://youtube.com/watch?v=tuvwfJhWyik
Anonymous
Mon 19-May-2008 16:22
This is cool, I have also begun building my own hardware player but I´m using a PIC18F452. And I do all the programming in C as I´m not that good in assembler, just have to run the core at 40Mhz instead =). I have got basic sound via the ressitor ladder to work but using a DAC sounds more interesting, what type do you use ?
Anonymous
Mon 16-Jun-2008 18:41
Yeah ! Very good job ;)
Anonymous
Sun 3-Aug-2008 22:37
Sounds like Jeroen Tel :D
Anonymous
Sat 20-Sep-2008 03:07
Linus, I'm trying to compile the tracker under mingw32 envirotment... well.. it compiles allright (after getting rid off err() calls, replacing ncurses with pdcurses and adding some os specified libraries for SDL) but nothing happens - not even an error message (i replaced err with printf())
could you provide any help? i'm more assembly coder than c one :(
Anonymous
Sat 20-Sep-2008 05:22
after another two hours i got this to work
instead pdcurses for win32, there is pdcurses for SDL library which works as it should (win32 version needs LINES and COLUMS as system envirotment variables, and works only if run from command prompt)
anyway...
MakeFile:
LDFLAGS=-lpdcurses -lmingw32 -lSDLmain -lSDL -mwindows

main.c:
if(argc != 2) {
fprintf(stderr, "usage: %s <filename>\n", argv[0]);
}
...
if(SDL_OpenAudio(&requested, &obtained) == -1) {
fprintf(stderr, "SDL_OpenAudio");
}

and <err.h> (main.c, gui.c) is no longer needed

hope it will be of some use for someone...
Anonymous
Fri 7-Nov-2008 01:51
You could have probably used a much more powerful chip, like the atmega324p or the atmega644p.
Anonymous
Wed 19-Nov-2008 16:37
Nice work. Why you don't use one PWM output with one resistor and one capacitor instead of all that parts for D/A??
Anonymous
Fri 19-Dec-2008 00:06
For the fun of it, I've made a SID version of the tune:
http://galway.c64.org/~sid/Kryo_Chiptune.sid

Thanks for the great inspiration!
Anonymous
Tue 27-Jan-2009 10:19
You guys are awesome. And you just have saved my day. A cool tune which i can listen to during office hours and a nice idea that i can work on after that. This is the best Idea for what i can do with my Atmel's which are laying around.
Anonymous
Wed 11-Feb-2009 07:12
it's amazing. good job!
Anonymous
Wed 11-Mar-2009 05:50
Im gathering all the parts from different dealer. this is just awesome!!
Anonymous
Sun 5-Apr-2009 01:51
Wonderful design and music ! I'm trying to reproduce it and to understand it, but for now I'm stuck on a few build problems.

Thierry C.
Anonymous
Wed 8-Apr-2009 19:53
hah... thats amazinggg.(: youre wayy smart *___*
Anonymous
Fri 8-May-2009 14:03
At last it worked ! (mysterious failure worked around).
(project adapted on ATMega8, with a PWM with low-pass filter based "DAC").

Thierry C.
Anonymous
Fri 3-Jul-2009 03:54
Really cool. This is also one of the first things I did in 2001 with my first AVR project. I did a rendition of Zoolook, but only with pulze waves.
Some other variations: using 9 colors of c64 video to create sound (with loud buzzing from vsync!), using sp of CIA (8bit autoshift register) to create stereo pwm dac (I never saw anyone else do this, they were always hooking up parallel dac0808).
One could make an exact sid replacement in microcontroller.
I always wanted to make a portable music toy to capture/compose musical ideas on the go .. like coffeeshop. Inspriation hits at odd times, sometimes upon waking.