Web Site:
www.parallax.com
Forums:
forums.parallax.com
Sales:
sales@parallax.com
Technical:
support@parallax.com
Office:
(916) 624-8333
Fax:
(916) 624-8003
Sales:
(888) 512-1024
Tech Support:
(888) 997-8267
SoundPAL (#28825):
Miniature Sound Player
General Description
The SoundPAL is a tiny module that plays canned and custom sound sequences. It is completely self-
contained, including a microcontroller for generating the sounds and a small speaker for producing them.
The SoundPAL interfaces easily to a BASIC Stamp and can play sounds while the BASIC Stamp is busy
with other chores.
Features
•
•
•
•
•
•
•
•
•
Plugs into servo headers, and works with protoboards.
Virtually goof-proof power sourcing makes it nearly impossible to connect wrong.
Single-pin interface uses a simple serial protocol to define and initiate sound production.
Canned tunes and sound effects can be played with simple commands.
Custom tunes and effects are simple to program using musical notation instead of frequencies.
Total audio range is 6½ octaves in four different tempos and four playing styles.
Onboard EEPROM permits saving custom sound sequences for later playback.
Autoplay feature permits playing a pre-designated EEPROM sequence with only a power supply.
Compact size: stackable side-to-side with additional modules on 0.1” servo headers.
What’s Included
SoundPAL module
Sonic Resonator
What You Need to Provide
•
BASIC Stamp 2 or better and a carrier board, such as Parallax’s Board of Education (BOE).
© Parallax, Inc. • SoundPAL (2007.10.29)
Page 1 of 12
Installation
Installation of the SoundPAL is a simple. If you’re using a system that incorporates three-pin servo
headers (such as the BOE), just plug the SoundPAL into one of them. It has two three-conductor sockets
to choose from for this purpose, and you can insert either one in either direction, yielding four possible
orientations. The SoundPAL will adapt to whichever way you plug it in. Here’s a diagram showing the
SoundPAL’s pinout:
I/O or Gnd
+5V
Gnd or I/O
I/O or Gnd
+5V
Gnd or I/O
The photo below shows the SoundPAL plugged into a servo connector on the BOE Bot.
You will notice from the photo that the “sonic resonator” has been installed on the speaker. This is
provided both to increase the volume level of the SoundPAL and to give it a richer sound.
Important Note:
The SoundPAL is designed to work from 5 volts only! Do not jumper your servo
headers to Vin or use any supply higher than 5 volts to operate the SoundPAL. Operation at lower
voltages down to about 3.3V is okay but will result in diminished output volume.
© Parallax, Inc. • SoundPAL (2007.10.29)
Page 2 of 12
By installing a 3-pin header (included with the BOE-Bot Full Kit, p/n 28132) in one of the SoundPAL’s
connectors, you can also use it with a wireless breadboard, as the following diagram illustrates:
Vdd
Vin
Vss
P15
P14
P13
P12
P11
P10
P9
P8
P7
P6
P5
P4
P3
P2
P1
P0
In lieu of the three-pin header, you can also use three jumper wires or Parallax’s 14-inch LCD Extension
Cable and 3-Pin Header (p/n 805-00012).
Hardware Interface and Initialization
Interface to the SoundPAL takes place through either one of its
I/O
pins. When the SoundPAL powers
up, both pins are configured as normally-high inputs, pulled up to a nominal +5V through internal 20K to
50K resistances. The BASIC Stamp can thus tell when the SoundPAL has powered up by monitoring the
ungrounded
I/O
pin for a high value. This is an important feature when the SoundPAL is plugged into
one of the BOE’s servo headers, since the BOE’s three-way power switch powers up the servos
after
the
BASIC Stamp’s program starts to run.
Communication with the SoundPAL takes place using the BASIC Stamp’s
SEROUT
and
SERIN
commands at any baud rate between 9600 and 19200, positive logic, 8-bit, no-parity. The SoundPAL’s
I/O
pin should always be configured as an input by the BASIC Stamp, except when it’s being pulled low.
It should never be driven high. Therefore, when configuring the baud rate, be sure to set the high bit of
the Baudmode to a “one” (i.e. add 32768, or $8000 to the normal Baudmode value). This will configure
the pin as an open collector output.
The SoundPAL runs autonomously on power obtained from the servo headers or from another 5V supply.
Therefore, it does not reset when the BASIC Stamp resets, and may continue to produce sound during
and after reset if it was producing sound before. But it
can
be reset, nonetheless, by outputting a low
pulse of 2ms or more to its
I/O
pin. This can be a little tricky with the BASIC Stamp, since the Stamp’s
PULSOUT
command always leaves the pin in an output state, which we don’t want to do. But there’s a
simple workaround. Just send a zero byte with
SEROUT
to the SoundPAL at a low baud rate, using the
same open-collector protocol used for normal communication.
When the SoundPAL resets, all output ceases immediately, and it returns to its initial state. Resetting is
the only way to halt infinite sound sequences, such as the siren effect included in the SoundPAL’s internal
repertoire.
The following code snippet illustrates baud rate settings both for communication and for resetting the
SoundPAL. It also includes a reset subroutine.
© Parallax, Inc. • SoundPAL (2007.10.29)
Page 3 of 12
iopin
baud
reset
PIN
CON
CON
15
$8000 + 84
$8000 + 813
'Pin number used for communicaiton with SoundPAL.
'Communication baudrate is 9600 for BS2, BS2e, and BS2pe.
'Reset baudrate is 1200 for BS2, BS2e, and BS2pe.
'See BASIC Stamp Manual for settings with other Stamps.
'----Reset the SoundPAL---------------------
DoReset:
DO:LOOP UNTIL iopin
SEROUT iopin, reset, [0]
RETURN
'Make sure SoundPAL is powered up.
'Output 9 low bits at 1200 baud (i.e. a 7.5ms pulse).
Playing Individual Notes
Pitch and Duration
Sounds are played by the SoundPAL as musical notes, each having an associated pitch and duration. The
pitches available to the programmer are those of the 12-note chromatic scale, and spanning 2½ octaves,
plus four programmable octave offsets, yielding a total range of 6½ octaves. In addition, there is one
pitch corresponding to a “rest”, which makes it possible to program silent intervals as well. The
illustration below shows the notes available in octave zero (oct0).
The note names shown between the staffs above are defined later in a sequence of
CON
statements in a
PBASIC code template. This template is also available for download from the SoundPAL product page on
the Parallax website.
Three additional octave ranges (oct1 –
oct3)
are available, each one an octave higher than its
predecessor. Without specifiying an octave range, the SoundPAL defaults to
oct2,
in which
C_0
is middle
C, and
A_0
is A440.
Each note or rest may have one of eight durations. These durations, along with their musical equivalents
and PBASIC names from the SoundPAL template, are shown below:
A single note in PBASIC consists of a pitch and duration and occupies one byte. If the note is a quarter
note, only the pitch need be given, since quarter notes are the default. To change to a different duration,
just add the duration name to the note name. For example, middle C in
oct0
played as a dotted eighth
note would be
de+C_2,
and an eighth rest would be
e+ZZZ.
For consistency, always put the duration
ahead of the pitch.
The actual note duration depends on the tempo. Four tempos are available (tmp0 -
tmp3).
Without
specifying a tempo, the SoundPAL defaults to
tmp1,
in which there are 266 quarter note beats per
minute. Each successive tempo is double the speed of its predecessor, so the range for quarter note
© Parallax, Inc. • SoundPAL (2007.10.29)
Page 4 of 12
beats per minute is from 133 to 1064. That makes the shortest sixteenth note 14ms long and the longest
dotted half note 677ms long. Although the fastest tempo is
too
fast for most music, it comes in handy for
certain non-musical sound effects.
Now we know how to express individual notes, but how do we make the SoundPAL play them? This is a
two-step process. First we have to get the notes into the SoundPAL. This is done by loading them into a
48-byte RAM buffer. Next, we have to tell the SoundPAL to execute (i.e. play) what’s in the buffer. Both
tasks are performed by issuing commands to the SoundPAL. The load command is an equal sign (=). It
tells the SoundPAL to put everything that follows it, up to and including the first zero byte, into the RAM
buffer. The execute command is an exclamation point (!). Every time the SoundPAL sees one of these, it
will execute the sounds in its buffer, stopping when it encounters the zero. For example, to play a simple
C major scale ending on a half-note, we would issue the following:
SEROUT iopin, baud, ["=", C_1, D_1, E_1, F_1, G_1, A_1, B_1, h+C_2, 0, "!"]
To specify an octave or tempo other than the defaults, just prepend an octave or tempo command to the
sound sequence you want played that way. In the following example, the arpeggio C, E, G, C is played in
the highest octave at the lowest speed:
SEROUT iopin, baud, ["=", oct3, tmp0, h+C_0, h+E_0, h+G_0, h+C_1, 0, "!"]
Style
In addition to pitch and duration, notes can be played in one of four different styles. These are named
marcato, legato, staccato,
and
glissando.
(Musical nomenclature is, by custom, in Italian.)
Marcato
is the default style and simply means that the notes played are demarcated by brief silences between
them. That way, two notes in sequence having the same pitch will be heard separately. By contrast,
notes played
legato
follow each other without intervening gaps. Two sequential notes having the same
pitch and played
legato
will sound like one long note. At the other extreme, notes played
staccato
all
have the same, very short length, with the remaining time (defined by the note duration) being filled by
silence. And finally, notes played
glissando
are not only played legato, but their pitches also slide into
one another, as though they were being played by a trombone or slide whistle.
Glissando
style is used
mostly for sound effects, such as the siren and wolf whistle included in the SoundPAL’s canned
sequences.
To choose a playing style, all you have to do is prepend a style command to the sequence you want to
play in that style. For example, to play “Mary Had a Little Lamb” in
staccato,
you’d do the following:
SEROUT iopin, baud, ["=", staccato, E_0, D_0, C_0, D_0, E_0, E_0, E_0, 0, "!"]
When
glissando
is chosen as the playing style, you can choose from one of 15 glide rates, ranging from
gl1
(fastest) to
gl15
(slowest). Selecting a glide rate by including the glide rate constant in a note
sequence automatically selects
glissando
as the playing style, so you don’t have to do that separately.
The following example shows how the SoundPAL defines a “wolf whistle”:
SEROUT iopin, baud, ["=",legato,S+G_0,gl2,h+G_1,ZZZ,legato,S+G_0,gl4,C_1,h+C_0,0, "!"]
On thing to note from this example is the use of the
legato
style. This is used ahead of the notes that
you don’t want to glide into. In other words, these notes will begin at their defined pitch but, because of
the subsequent
gl2
and
gl4
commands, glide into the notes that follow.
Sometimes you want to play most of a tune
marcato
or
staccato,
but occasionally there will be two or
three notes that you want to play
legato.
In musical parlance, this is known as a
slur
when the two
notes have different pitches, or a
tie
when they have the same pitch. To this end, the SoundPAL has a
special style command called
slur
which is just a
legato
applied to the next note only, causing it to
© Parallax, Inc. • SoundPAL (2007.10.29)
Page 5 of 12