Description
This circuit was used as part of Caltech Ditch Day 2007 to play a sound clip (sequence of musical notes) upon opening a box. A single 8-pin PIC is used to generate a PWM output signal at the correct audio frequency. The note format is a subset of QBasic's PLAY command:
- Ox : Select octave x = 0..6 (3 is default, containing/starting at middle C)
- A..G : Play note in current octave
- #/+ : preceding note is sharp (A# or A+)
- - : preceding note is flat (A- = G+)
- . : Play preceding note 3/2 * normal length
- < : move up 1 octave
- > : move down one octave
- Lx : Set tone length x = 1..64 (8 is default, 1 = whole note, 2 = half note, 4 = quarter note...)
- Px : Pause length x = 1..64
- R : Repeat the song
- Z : Stop playing and put the PIC to sleep (bring the MCLR pin low to reset and play again)
The last two commands are my own additions to control playback. The numerical arguments to commands are stored as a number, not in ASCII, and hence consume only a single byte. The length limit to a song is 255 bytes (must fit in a page of memory).
The PWM note tables used were generated using a PWM Calculator Other tables were generated from small C programs.
Code
The full source is here. To change the song played, modify stuff after the MySong label at the end of the code. A precompiled binary for the given hardware is here; it plays the sound in Zelda when Link opens a chest to discover an item.
Sample Songs
Here are some sample songs that you can run in QBasic format:
- Link Finds A... - Reference
- Gay Fuel song - Reference
- lol, internet! - Reference
- Ninja works it - Reference
Photo
Schematic