Shop OBEX P1 Docs P2 Docs Learn Events
Freakout (freqout) trick — Parallax Forums

Freakout (freqout) trick

Don PomplunDon Pomplun Posts: 116
edited 2006-05-20 02:17 in Learn with BlocklyProp
Is there a better explanation on the "freqout trick" somewhat discussed in the Sumobot book? Searching for freqout didn't make much headway.
-- Don

Comments

  • edited 2006-05-19 22:13
    Do you hava a particular question? At what point did you get stuck?
  • Don PomplunDon Pomplun Posts: 116
    edited 2006-05-19 22:26
    What's the magic (or relevance) to the 27036 mention? Does freqout only respond to parameters <= 32768? If so what is it doing when given 38500? If 38500 is OK as a parameter, then what is the relevance of the harmoinic discussion? What's the "trick"? Only that Parallax intended it to go only to 32768, and the "pair of enthusiasts" found out that they could enter bigger numbers without getting an error?
    -- Don
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-05-19 22:42
    Don -

    This note below, part of the original FREQOUT.BS2 program, may or may not answer your ultimate question. The frequency parameters in the FREQOUT statement are indeed limited to the value that can be contained in a WORD, or 32767.

    Note from program mentioned above:

    "' This program plays "Mary Had a Little Lamb" by reading the notes from a LOOKUP table.
    ' It was designed to sound good on the piezo speaker that comes with the BASIC Stamp
    ' Activity Board. To demonstrate the effect of mixing sine waves, the first frequency
    ' is the musical note itself, while the second is 8 Hz lower. The difference creates a
    ' quiver (vibrato) on each note. Subtracting 8 from the note frequency poses a problem
    ' when the frequency is 0, because the BASIC Stamp's positive-integer math wraps around
    ' to 65528. FREQOUT would ignore the highest bit of this value and generate a frequency
    ' of 32760 Hz rather than a truly silent pause. Although humans can't hear 32762 Hz,
    ' slight imperfections in filtering will cause an audible noise in the speaker. To clean
    ' this up, we use the expression "(f-8) max 32768," which changes 65528 to 32768.
    ' FREQOUT discards the highest bit of 32768, which results in 0, the desired silent pause."

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • edited 2006-05-20 01:55
    Every time you give the FREQOUT command a Frequency argument that's above its top frequency (32768), the resulting frequency the BASIC Stamp transmits is 65536 - (the frequency that's too high). So for the command FREQOUT 8, 1, 38500, the BASIC Stamp intentionally transmits 65536 Hz - 38500 Hz = 27036 Hz. However, while the BASIC Stamp intentionally transmits a digitally synthesized 27036 Hz frequency, it unintentionally transmits a 38500 Hz harmonic. In other words, if the FREQOUT command's Frequency argument is 38500, the BASIC Stamp intentionally digitally synthesizes and transmits a 27036 Hz sine wave and unintentionally digitally synthesizes and transmits a 38500 Hz sine wave. Likewise, if you use the command FREQOUT 8, 1, 39000, the BASIC Stamp intentionally synthesizes a 65536 - 39000 = 26536 Hz sine wave and unintentionally synthesizes a 39000 Hz sine wave. If you could "hear" these frequencies, they would·sound similar to phone tones, which mix two different frequencies. Or perhaps 2 keys that were struck at the same time on some weird piano that could play very high frequency tones. (Keys for those frequencies would be quite a ways off to the right!)

    I guess you could say the "trick" is simply that you can use FREQOUT Duration arguments above 32768 even though the BASIC Stamp wasn't designed for that, provided you have equipment to detect signals in that range. You will still always have a corresponding signal below 32768, which typically won't matter to equipment that's detecting signals in the 38 kHz range.· The couple of Boe-Bot enthusiasts were me and Russ Miller, the guy who designed the Boe-Bot chassis. While I discovered the FREQOUT trick on my own and purely by accident, Russ made the brilliant suggestion of sweeping the frequencies to detect distance. I got it working·and demo'd it for him the following day, and you'll get to try it in Chapter 8.

    Post Edited (Andy Lindsay (Parallax)) : 5/20/2006 2:04:06 AM GMT
  • Don PomplunDon Pomplun Posts: 116
    edited 2006-05-20 02:17
    Ahhh . . . A true feature.
    Thanks, Andy.
    -- Don
Sign In or Register to comment.