Parallax BASIC Stamp 2e Programming Manual page 126

Table of Contents

Advertisement

FREQOUT - BASIC Stamp Command Reference
FREQOUT 2, 1000, 2500, 3000
This will generate a 2500 Hz and 3000 Hz tone (on the BS2) for 1 second.
The frequencies will mix together for a chord- or bell-like sound. To
generate a silent pause, specify frequency value(s) of 0.
from I/O pin
from I/O pin
Notes:
C1 may be omitted for piezo speakers
C2 is optional, but reduces high-frequency noise
The circuits in Figure 5.4 work by filtering out the high-frequency PWM
used to generate the sine waves. FREQOUT works over a very wide range
of frequencies (as shown in Table 5.12) so at the upper end of its range,
those PWM filters will also filter out most of the desired frequency. You
may find it necessary to reduce values of the parallel capacitors shown in
the circuit, or to devise a custom active filter for your application.
Demo Program (FREQOUT.bs2)
' This program plays "Mary Had a Little Lamb" by reading the notes from a LOOKUP table.
' It was designed to sound good on the piezo speaker that comes with the BASIC Stamp
' Activity Board. To demonstrate the effect of mixing sine waves, the first frequency
' is the musical note itself, while the second is 8 Hz lower. The difference creates a
' quiver (vibrato) on each note. Subtracting 8 from the note frequency poses a problem
' when the frequency is 0, because the BASIC Stamp's positive-integer math wraps around
' to 65528. FREQOUT would ignore the highest bit of this value and generate a frequency
' of 32760 Hz rather than a truly silent pause. Although humans can't hear 32762 Hz,
' slight imperfections in filtering will cause an audible noise in the speaker. To clean
' this up, we use the expression "(f-8) max 32768," which changes 65528 to 32768.
FREQOUT
' discards the highest bit of 32768, which results in 0, the desired silent pause.
Page 124 • BASIC Stamp Programming Manual 2.0b • www.parallaxinc.com
Driving an Audio Amplifier
1k
1k
0.1µF
0.01µF
Vss
Vss
Vss
Driving a Speaker
10µF (both)
≥40Ω Speaker
+
(or 8Ω in series
+
C1
C2
with 33Ω resistor)
Vss
Vss
Amplifier
(e
.g., Radio Shack
277-1008C)
Figure 5.4: Example RC filter
circuits for driving an audio amplifier
or a speaker.
F
C
REQUENCY
ONSIDERATIONS
2
2
2
2
e
sx
p
NOTE: This is written for the BS2
but can be used for the BS2e,
BS2sx and BS2p also. Locate the
proper source code file or modify
the STAMP directive before
downloading to the BS2e, BS2sx or
BS2p.
.

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?

Table of Contents