3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Musical Greeting Card

Step 17How it works

How it works
The program in the PIC10F2XX microcontroller has to do two things: it has to produce a musical note, and it has to change that musical note after a specific length of time.

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.

« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
70
Followers
38
Author:neelandan
Employed as an Engineer in Electronics. Interested in building small circuits around tiny chips (the electronic kind).