June
2000, Issue 119
The
Chips are Alive with the Sound of Music
Imitatiing
the Dead Melody IC
SOUNDS
LIKE
Square
waves dont 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
ports 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).
|
|
| Figure
3An 8-bit micro makes a simple melody
generator. Both Microchip and Atmel parts can be
used. |
Heres
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 notes 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 1s 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), thats
three beats to a measure. Dont 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 Im
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
1These 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.