Specifications

BASIC Stamp II
Page 264 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Freqout
FREQOUT
pin, duration, freq1{,freq2}
Generate one or two sine-wave tones for a specified duration.
Pin
is a variable/constant (0–15) that specifies the I/O pin to use.
This pin will be put into output mode during generation of tones
and left in that state after the instruction finishes.
Duration
is a variable/constant specifying the length in
milliseconds (1 to 65535) of the tone(s).
Freq1
is a variable/constant specifying frequency in hertz (Hz,
0 to 32767) of the first tone.
Freq2
is a variable/constant specifying frequency (0 to 32767
Hz) of the optional second tone
Explanation
Freqout generates one or two sinewaves using fast PWM. The circuits
shown in figure I-4 filter the PWM in order to play the tones through a
speaker or audio amplifier. Here’s an example Freqout instruction:
FREQOUT 2,1000,2500
This instruction generates a 2500-Hz tone for 1 second (1000 ms)
through pin 2. To play two frequencies:
FREQOUT 2,1000,2500,3000
The frequencies mix together for a chord- or bell-like sound. To gener-
ate a silent pause, specify frequency value(s) of 0.
Frequency Considerations
The circuits in figure I-4 work by filtering out the high-frequency PWM
used to generate the sinewaves. Freqout works over a very wide range
of frequencies from 0 to 32767 Hz, 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
This program plays “Mary Had a Little Lamb” by reading the notes
from a Lookup table. To demonstrate the effect of mixing sine waves,