Page 240 ·
Robotics with the Boe-Bot
FREQOUT
Command - Fundamentals and Harmonics
The fundamental frequency is the value of the
Freq1
argument when it’s at or below
32768. For example, when you use the command
FREQOUT 4, 2000, 3000
, the
fundamental frequency is 3000 Hz. That's the intended sound, but there is also a harmonic
sound that accompanies it. This harmonic is a much higher frequency that the human ear
can detect, in the neighborhood of 62.5 kHz. Here's how to calculate the harmonic
frequency given the fundamental and visa versa.
Whenever you use the
FREQOUT
command to send a tone in this range, it contains that
hidden (harmonic) tone as well. The equation for the harmonic is:
harmonic frequency = 65536 – Freq1, Freq1 <= 32678
Whenever you use the
FREQOUT
command with a
Freq1
argument above 32768 to send
a harmonic, it contains a fundamental tone. The equation for the fundamental is:
fundamental frequency = 65536 – Freq1, Freq1 > 32768
The key to making each IR LED/detector pair work is to send 1 ms of 38.5 kHz
FREQOUT
harmonic, and then, immediately store the IR detector’s output in a variable. Here is an
example that sends the 38.5 kHz signal to the IR LED connected to P8, then stores the IR
detector’s output, which is connected to P9, in a bit variable named
irDetectLeft
.
FREQOUT 8, 1, 38500
irDetectLeft = IN9
The IR detector’s output state when it sees no IR signal is high. When the IR detector
sees the 38500 Hz harmonic reflected by an object, its output is low. The IR detector’s
output only stays low for a fraction of a millisecond after the
FREQOUT
command is done
sending the harmonic, so it’s essential to store the IR detector’s output in a variable
immediately after sending the
FREQOUT
command. The value stored by the variable can
then be displayed in the Debug Terminal or used for navigation decisions by the Boe-Bot.
Example Program: TestLeftIrPair.bs2
√
Reconnect power to your board.
√
Enter, save, and run TestLeftIrPair.bs2.
' Robotics with the Boe-Bot - TestLeftIrPair.bs2
' Test IR object detection circuits, IR LED connected to P8 and detector
' connected to P9.
' {$STAMP BS2}