### Site Tools

한국어

cubloc:freqout:index

# FreqOut

`FreqOut channel, freqValue`

 channel PWM channel (0 to 15) freqValue Frequency value between 1 and 65535

FreqOut output the specified frequency to the specified PWM channel. Please make sure to specify the PWM channel, not the I/O port number. For the CB220 and CB280, ports 5, 6, and 7 correspond to PWM Channel 0, 1, and 2, respectively.

The following chart shows several example freqValues and their corresponding frequencies. The highest possible frequency can be achieved by setting freqValue to 1 and the lowest possible can be achieved by setting freqValue to 65535. A freqValue of 0 does not produce any output.

FreqValue Frequency
1 1152 KHz
2 768 kHz
3 576 KHz
4 460.8KHz
5 384 KHz
10 209.3 KHz
20 109.7 KHz
30 74.4 KHz
100 22.83 KHz
200 11.52 KHz
1000 2.3 KHz
2000 1.15 KHz
3000 768 Hz
4000 576 Hz
10000 230 Hz
20000 115.2 Hz
30000 76.8 Hz
65535 35.16 Hz

You can calculate freqValue using the following formula:

freqValue = 2,304,000 / Desired Frequency

Before using this command, please set the specified PWM port to output mode and set to a logic high or logic low state. To stop the output, use the PWMOff command.

The following is an example:

```Const Device = CB280
Dim i As Integer
Low 5 ' Set Port 5 to low and output.
i = 1
FreqOut 0,10 ' Produce a 209.3Khz wave
Do ' Infinite loop
Loop```

Since FreqOut uses the same resources as the PWM, there are some restrictions to consider. PWM channels 0, 1, and 2 use the same timer.

If PWM channel 0 is used for a FreqOut command, PWM channels 0, 1, and 2 cannot be used for a PWM command.

Likewise, PWM Channels 3, 4, and 5 are linked. If FreqOut is used on PWM channel 3, PWM Channels 3, 4, and 5 cannot be used for a PWM command.

You can produce different frequencies on PWM channels 0 and 3.

To summarize, two different frequencies can be produced at one time, and when using the FreqOut command, a PWM command cannot be used on the same channel.

The following is a chart that correlates freqValue to musical notes:

Note Octave 2 Octave 3 Octave 4 Octave 5
A 20945 10473 5236 2618
Bb 19770 9885 4942 2471
B 18660 9330 4665 2333
C 17613 8806 4403 2202
Db 16624 8312 4156 2078
D 15691 7846 3923 1961
Eb 14811 7405 3703 1851
E 13979 6990 3495 1747
F 13195 6597 3299 1649
Gb 12454 6227 3114 1557
G 11755 5878 2939 1469
Ab 11095 5548 2774 1387
```FreqOut 0,5236 ' Note A in Octave 4(440Hz)
FreqOut 0,1469 ' Note G in Octave 5```