Step 1: The circuit diagram
The switch (not shown in the diagram) is just two strips of metal pressed together, with a piece of paper in between. As the card is opened, the paper is pulled away and the two contact each other, thus closing the circuit.
A fragment of the code is shown, too. The program takes up 56 locations in memory. The PIC10F200 has 256 such locations available. A melody consisting of 200 notes or so can be fitted in to this chip.
This should be sufficient for a musical greeting card.
Step 2: The chip
For a really small card, the SOT23 package can be used. I have tested this with the small versions of the 10F200 and 10F206.
The figure shows a PIC10F206.
Step 3: The board
Step 4: The chip
Step 6: The supply leads
Step 7: Program the melody
The Hex file for the tune of "Go Tell it on the Mountain" is provided here.
Step 8: The program
I have used a version of what I call the tonic sol-fa notation to write the notes. Old timers might remember: "Doe a deer, a female deer, Ray, a drop of golden sun ... "
However, it is not what musicians call notation or anything. It is just a convenient way of passing delay values to the routine which makes those music notes. The Assembly Language program is included. You can process it with MPLAB to produce the HEX file.
Change the dt lines to make it sing the tune of your choice.
If you can provide proof that you made it (put up pictures) I can write the program to make it sing the tune of your choice - ONE time. So hurry up.
Step 9: CPU V2
Step 10: Piezo speaker
This, by itself, does not sound loud enough to be heard. Its volume can be boosted by coupling it to a resonant chamber.
Here, I have used the hub from a 3 1/2" floppy disk for the chamber. It has a rounded rectangular cutout which I plugged with a piece of circuit board, drilled to accept the two wires that connect to the piezo element.
The two are stuck together using superglue. The reulting resonant piezo speaker is quite loud, over the range of notes in which it is resonant.
Step 11: The card
It has to be thick enough, and stiff enough, so that it does not lose shape when the electronics and battery gets attached to it.
Plan your layout on the card so that the circuitry does not hide the sentimental text you have printed on it.
It would be wise to do any artwork on the card forehand, because it would not go through any sort of printer after you have attached the electronics to it.
Step 12: The switch
Finally, and, quite importantly, when the victim has heard enough of the squeaky melody and wishes for some peace and quiet, closing the card should turn the &%Â£*&!! thing off again. Or they might have to resort to taking an axe to the thing, just to make it shut the heaven up.
It is made with two pieces of metal, touching each other.
A piece of plastic, (transparent in my version) pushes itself between the said two pieces when the card is closed.
You make it by sticking a stiff piece of plastic or card near the hinge of the card as shown in the figure. Mark its position when the card is closed and open, and then arrange for two metal wires or plates to touch each other in the area covered in between the open and closed positions.
Step 13: The switch
Step 14: The finished switch
Fashioning the switch is the most critical stage in making a musical card. If you would rather avoid all this work, it might be better to buy a musical greeting card and just replace the melody generator with one of your own.
Step 15: The PIC10F six pin processor - V3
Those wires are in a sort of colour code. Black is ground, or zero volt rail, that Microchip calls Vss. Red is positive, +5 volts, or the supply rail, that Microchip calls Vdd. Orange is the programming voltage, and the white and grey carry the Data and Clock for programming respectively.
The white wire is GP0, and the grey wire is GP1. The GP2 connection of the micro is not used, and so it is not soldered. GP1 and GP2 connect to the piezo buzzer after it has been programmed.
Since the PIC will be, in most cases, programmed once and then connected up into its circuit, I find that connecting it to the programming signals in this way is sufficiently quick. If you are trying to program it several times, for example when developing a melody, it might be better to solder it to a socket to accept the connections from your programming circuit.
Step 16: The finished card
When I was looking for a coin cell holder for the lithium cell I came across this set of three cells as part of an LED torch in a pen. Since three new cells will give around 4.5 Volts against the three volts available from a lithium coin cell this will be louder, when new, and so is adopted.
There should be a capacitor of about 0.1 microfarad across the supply terminals of the PIC. No difference was evident with new cells, but when I tried it with three rather 'tired' cells the music stopped and started stuttering half way through. So adding that capacitor will give you more playing time from the batteries.
Step 17: How it works
It produces a musical note by exciting a piezo speaker with a square wave. One output is made high and the other is made low, for a certain time. After some time this state is reversed, the output that was low going high and the other going from high to low. The piezo element, connected between these two outputs, sees a square wave of twice the supply voltage across it and so produces a loud note, louder than that produced if a single output was used.
The musical notes are produced by varying the delay between toggling the pins. The table of delays is according to the data taken from Don Lancaster's website, www.tinaja.com, and reproduced here. He also provided the delay routine with a resolution down to a single instruction period. The frequency of the note is produced by a software delay, and the numbers to be fed to this counter form the table that forms the melody. A 'zero' denotes that the end of the music is reached, and that playing is to be resumed from the beginning. A 'one' denotes that a rest is needed, and a period of silence instead of a tone is produced.
The period for which each note is sounded is measured in terms of the timer tmr0. It is set to increment from the instruction clock with a prescaler of 256, the maximum possible. Five overflows of the timer register TMR0 make up one note length.
A copy of the most significant bit of the timer register is maintained in (flags,tmrh) and if the flag is high when the timer MSB is low a rollover is deemed to have taken place. This check is done within the loop framed within the label "forever" and the instruction "goto forever".
The next note to be fetched is kept in count1. The instruction "call table" returns with the note delay in W. It is ORed with zero to check for the end of the melody. Then it is checked for the value One to check for a rest. If neither, the value in W is passed to the delay routine.
The program flow in the note generation loop has been equalised to take the same number of cycles for all conditions, except for the time that tmr0 rolls over. This is audible as a sort of ticking in the background.
The provided Hex file has been tested with a 10F200 and a 10F202 and found to work. The source code has the necessary changes to be made in order to make it suitable for a 10F204 or 10F206. It has also been tested with a 10F206.
A 10F220 or 10F222 could be used, but will need additional instructions to turn off the peripherals that are not used, and the fuse settings will also need to be modified.
Have fun, and do write if you manage to get a music maker to work. The eight pin DIP versions of these micros are available, and they are easier to handle, and they will work as well in this circuit.