circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

June 2000, Issue 119

The Chips are Alive with the Sound of Music
Imitatiing the Dead Melody IC


by Jeff Bachiochi

SOUNDS LIKE

Square waves don’t sound smooth. They are irritating on their own, as proven by cell phones and beepers. However, piezo elements allow thin transducers where fidelity (at least the bandwidth is greater than the telephone) is not necessary. The devices’ frequency range fits well into that limited bandwidth. The piezo element can be directly driven from the microcontroller I/O port’s toggling bit. Although you could get more drive from a transistor-driven speaker, if the idea is to hide the circuitry within a greeting card, the speaker is out of the question (see Figure 3).

2006002-F3.gif (4881 bytes)

Figure 3—An 8-bit micro makes a simple melody generator. Both Microchip and Atmel parts can be used.

Here’s how a simple tune translates into a table of entries. Middle C on a piano, and all of the notes within an octave above it, are noted by their capital letters. Notes one octave below middle C have a tick before them, and notes one octave above middle C are followed by a tick.

Notes in octaves further away have multiple ticks. With this notation, you can determine a note’s exact location. Looking at a piece of music, I copied the musical notations and timing duration of each note into a list of notes. Is it an eighth, quarter, half, or whole note? The song "My Bonnie (Lies Over the Ocean)" is in 3/4 time. This means there are three beats to the measure and a quarter note is equal to one beat (eighth note = half beat, half note = two beats, and whole note = four beats). Measures break the music into manageable pieces.

Look at Table 1’s second column, which lists the notes and how many halves of a beat each note gets. I use halves of a beat because the fastest note I can handle is an eighth note (two to one beat or half beat each), even though there are none in this song. Notice that each group adds up to six (half beats), that’s three beats to a measure. Don’t worry about the first and last group, this is a partial listing of the song, they also total three beats. The last column shows the words to the song, so you can follow what I’m writing about.

00010111 G-2 My
00010010 E-2 Bon
00010011 D-2 nie
00010100 C-2 lies
00010011 D-2 o
00010100 C-2 ver
00010110 ‘A-2 the
00010111 ‘G-2 o
00101001 ‘E-4 cean
00101001 ‘E-4
Table 1—These groups contain notations for each measure that is to be played.

The first column in Table 1 is a binary representation of the note and duration. This is the data the micro gets from the table. It also contains other important information. By equating some initial constants for all the possible notes, durations, rests, and last note indication, I could let the assembler calculate the data values for every entry in the table.