# FREQOUT

FREQOUT Example

Syntax: FREQOUT Pin, Duration, Freq1 {, Freq2}

## Function

Generate one or two sine-wave tones for a specified duration.

- Pin a variable/constant/expression (0 - 15) that specifies the I/O pin to use. This pin will be set to output mode.
- Duration a variable/constant/expression (0 - 65535) specifying the amount of time to generate the tone(s). The unit of time for Duration is described in the table below.
- Freq1 is a variable/constant/expression (0 - 32767) specifying frequency of the first tone. The unit of Freq1 is described in the table below.
- Freq2 is an optional argument exactly like Freq1. When specified, two frequencies will be mixed together on the specified I/O pin.

Note: See SOUND for the BS1.

## Quick Facts

| BS2 and BS2e | BS2sx | BS2p | BS2pe | BS2px
Units in Duration | 1 ms | 0.4 ms | 0.265 ms | 1 ms | 0.166 ms
Units in Freq1 and Freq2 | 1 Hz | 2.5 Hz | 3.77 Hz | 1.51 Hz | 6.03 Hz
Range of frequency | 0 to 32767 Hz | 0 to 81.917 kHz | 0 to 123.531 kHz | 0 to 49.478 kHz | 0 to 197.585 kHz
Related Commands | DTMFOUT, PWM

## Explanation

FREQOUT generates one or two sine waves using a pulse-width modulation algorithm. The circuits in the figure below work by filtering out the high-frequency PWM used to generate the sine waves. FREQOUT works over a very wide range of frequencies 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.

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 the table above for timing data on other BASIC Stamp models.

To play two tones on the same I/O pin at once:

      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.

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012