Hi all, About 2 weeks ago I posted a message talking about a PIC-based synthesized music box I built about 4 years ago. I said that I could post code and schematic if people were interested. Several people asked for it but it took me a while to go back into my archives and pull it all together. In addition, the only schematic I had was a mess and was hand drawn. SO, I downloaded gEDA and had to learn to use its schematic editor so I could produce a better schematic. That's done now and you can download a ZIP file containing the docs at: http://www.cheapgalvis.com/mbox.zip This ZIP file contains the following: ASM code for the PIC in the device Two JPG images (sorry for the poor quality, back then I had a very poor digital camera) of the inside and outside of the device. C code for generating the HEX file to be programmed into the serial EEPROM chip in the device (contains the data for the tunes as well as sampled notes) PDF of the schematic. Please note that when I originally did this, I had only about two weeks within which to do it so it is not my best work (the comments in the code are rather sparse). I am also not 100% sure that nothing changed in the actual device compared to the schematic. This PDF contains what I have on paper and may be slightly different from what is in the actual device. If anyone needs further explanation, I'd be glad to answer questions. I can also provide a gEDA schematic file but since I am not entirely sure yet how to export it along with the necessary symbols I created, I did not put it in the ZIP file. Please refer to my message of Dec 17 2008 about this as well (text is copied below). Sean Text of message from Dec 17 2008: Hi Adam, About 4 years ago I made a synthesized music box using a 16F876, an 8 bit DAC, audio amp, LCD, and a serial EEPROM. It turned out that in the end it sounded so good that people were surprised that it wasn't a real music box. When they saw it, their reaction was "yeah, so what, it's a music box" until I showed them that there were no moving parts inside :) Probably overkill for your app as it was designed to play four simultaneous voices (two lines of music along with decay from the previous note on each). However you might be able to scale up the idea. PWM would probably work fine as a DAC method for your case, too. The basic idea was simply recording samples into the serial EEPROM and playing them through the DAC at appropriate times. In my case, I stored two octaves worth of notes (24 tone snippets, since I wanted the full chromatic scale). Each snippet was long enough that repeating it over and over didn't cause audible discontinuities. Inside the PIC I would multiply each snippet by the output of an "attack/decay" lookup table to give a realistic sounding envelope. The output of each of the four channels was then added and scaled to prevent saturation, and then fed to the DAC. The "snippets" were generated by a PC-based C program which added together several harmonics. I initially tried to model an actual music box or even a plucked piece of metal but in the end, the best sound came from just tweaking the harmonic amplitudes and listening to it. This program directly generated a .HEX file to be programmed into the serial EEPROM. The serial EEPROM also contained the musical "score" for each piece (about 8 in total which could be selected via the LCD and buttons). The scope specified which note (or a rest) to play at each timestep, and for how long to play it. Playing it longer didn't mean changing the attack/decay, it just meant how long to wait before loading the next note (like a piano). If anyone is interested, I can dig up the source code and probably a schematic. Unfortunately, since it was a one-off, and I needed to get the project working in time, I ended up slightly overclocking the SPI to the serial EEPROM since there was a tremendous amount of data flowing from it into the PIC. Sean -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist