5: BASIC Stamp Command Reference – FREQOUT
BASIC Stamp Programming Manual 2.0c • www.parallaxinc.com • Page 123
FREQOUT
BS1 BS2 BS2e BS2sx BS2p
(See SOUND)
FREQOUT Pin, Period, Freq1 {, Freq2}
Function
Generate one or two sine-wave tones for a specified period.
• Pin is a variable/constant/expression (0 – 15) that specifies the I/O
pin to use. This pin will be set to output mode.
• Period is a variable/constant/expression (0 - 65535) specifying the
amount of time to generate the tone(s). The unit of time for Period is
described in Table 5.12.
• Freq1 is a variable/constant/expression (0 – 32767) specifying
frequency of the first tone. The unit of Freq1 is described in Table
5.12.
• Freq2 is an optional argument exactly like Freq1. When specified,
two frequencies will be mixed together on the specified I/O pin.
Quick Facts
BS2, BS2e BS2sx BS2p
Units in Period
1 ms 0.4 ms 0.265 ms
Units in Freq1
and Freq2
1 Hz 2.5 Hz 3.77 Hz
Range of
frequency
0 to 32767 Hz 0 to 81.917 kHz 0 to 123.531 kHz
Explanation
FREQOUT generates one or two sine waves using a pulse-width
modulation algorithm. The circuits shown in Figure 5.4 will filter the
signal in order to play the tones through a speaker or audio amplifier.
Here’s a simple FREQOUT command:
FREQOUT 2, 1000, 2500
On the BS2, this command generates a 2500 Hz tone for 1 second (1000 ms)
on I/O pin 2. See Table 5.12 for timing data on other BASIC Stamps.
To play two tones on the same I/O pin at once:
2
2
2
SIMPLEST FORM OF FREQOUT.
G
ENERATING TWO TONES AT ONCE.
Table 5.12: FREQOUT Quick