Shop OBEX P1 Docs P2 Docs Learn Events
Interested a little more information on the BS2 freqout generating the 38.5kHz — Parallax Forums

Interested a little more information on the BS2 freqout generating the 38.5kHz

Russ FergusonRuss Ferguson Posts: 206
edited 2005-03-06 04:03 in Learn with BlocklyProp
The Robotics text has·a 'teaser' comment about the way that the BS2 freqout generates the 38.5kHz harmonic for the IR diode.

I would like to read a little more about what is going on in the BS2. As a hobbiest it would be helpful if the reading was not to technical.

Any suggestions?
·

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2005-03-04 16:11
    You want MORE detail, but then it shouldn't be TOO technical? Arghh.

    My understanding is that the frequencies the BS2 can generate 'top-out' at a certain point -- specifically 32 Khz, I believe. What a VERY clever robotics guy discovered (I don't know his name, sorry) was that since the BS2 is generating SQUARE waves, there's lots of harmonics in the signal.

    Now, a 'pure' tone has no harmonics, and looks like a 'pure' sine wave on an oscilloscope. If you try to 'square-up' the sine wave, you do so by adding in harmonics of the original frequency. A 'harmonic' is the original frequency times an integer -- so two times higher, four times higher, etc.

    This very clever guy discovered if you do a FREQOUT 32000 to an IR-LED, and put an IR-Decoder device 'looking' at that LED, then even though the IR-Decoder was 'looking' for 38 Khz (they're frequency specific, you know) it would see enough 38 Khz harmonics in the signal to trigger. This is all in a Parallax App-note, by the way.

    Well, you also know that the BS2 can only do one thing at a time, right? So if it is outputting that signal, how can the BS2 read the output of the IR-Decoder? It turns out the IR-Decoder has enough latency in its operation that it would 'hold' the read signal long enough for the BS2 to read it. Thus, the BS2 can make an IR-output to an IR-Decoder, and use the two as an electronic 'whisker' to prevent collisions.

    So, what's really going on is the BS2 generates a 32 Khz square wave for the IR-LED. A square wave has LOTS of harmonics in it. The IR-Decoder looking at the IR-LED triggers off the 38 Khz harmonics that the BS2 puts into its 32 Khz square wave.
  • Russ FergusonRuss Ferguson Posts: 206
    edited 2005-03-05 02:04
    Allan, thank you for giving me some input. I will accept a "little more technical" if you get a chance.

    Here is where I am coming from -

    A frequency of 3000 Hz has a 3rd harmonic of 9000 Hz and it has a 5th harmonic of 15000Hz.

    However on page 240 of "Robotics with the Boe-Bot" v 2.2 there is an info box which says that the harmonic generated by FREQOUT 3000 is in the "neighborhood of 62.5 kHz".

    According the the math in the info box - the FREQOUT fundamental of 38500 is calculated by subtrating the freq1 from 65536. The FREQOUT fundamental of 38500 is: 65536 - 38500 = 27038.

    In another info box, page 271, it says that "the FREQOUT command transmits a slightly more powerful (harmonic) signal at
    37.5 kHz than it does at 38.5 kHz." I can understand that a 3rd harmonic would be more powerful than a 5th harmonic. What would make a 37.5 kHz harmonic more powerfull than a 38.5 kHz harmonic frequency?

    How are the fundamental frequencies related to the harmonic frequencies as they are described in the book? The wheels of my mind are spinning and there is alot of smoke coming out but this dragster doesn't seem to be moving. Explaning the relationship of the fundametal and harmonic frequencies by using simple subtraction just doesn't seem to fit.

    One other question that is related: Why does the spec sheet for the IR receiver show the peak "Relative Sensitivity" to be 38000 Hz and yet in the book we use 38500 Hz in all of the activities and math?

    Russ
  • edited 2005-03-05 18:27
    Russ,

    This is a reply to your question about the diffeence between the harmonics a square wave generates and the harmonics the FREQOUT command generates.

    The FREQOUT signal the BASIC Stamp sends is much more complex than a square wave. The signal is actually a series of pulses that vary in duration to digitally synthesize a sine wave. Unlike a plain old square wave, the behavior of the harmonics this pulse width modulated signal creates is completely different. The behavior of the harmonics is as though you mixed two sine waves together. The fundamental appears at the Frequncy value you supply the FREQOUT command, and the harmonic appears at 65536 - the Frequency value. The result is that the harmonic is always the same number of Hz above 32768 as the fundamental is below it.

    The BASIC Stamp is designed to send FREQOUT signals that are less than 32,768 Hz. The fundamental is a sine wave at a frequency (below 32768), and the harmonic is the same number of Hz above 32768. Let's say your FREQOUT command is FREQOUT 8, 60000, 28036. This is the signal I use to examine the behavior of the signal on a spectrum analizer. It lasts a minute, and digitally synthesizes a sine wave of 28036. For more information on how a spectrum analyzer works, see the discussions of the Parallax USB Oscilloscope's FFT function, which is discussed in Understanding Signals. Understanding Signals is a free download from www.parallax.com -> Downloads -> Stamps in Class Tutorials. Anyhow, when I view this signal with a spectrum analyzer, I see an indication that the signal contains a sine wave at 28036 (the fundamental), and another at 37500 (an harmonic). When I change the FREQOUT command's Frequency argument to 27036, I see indications of a fundamental at 27036, and the harmonic at 38500. The behavior of the harmonics is about the same as the "double sideband" signals involved in AM radio signal demodulation.

    The funny thing about the BASIC Stamp is that when you use a command like FREQOUT 8, 60000, 38500, the BASIC Stamp sends the signal for 27036. If you use a Frequency argument of 37500, the frequency the BASIC Stamp sends is 28036. Well, than handy thing about it is that 28036 has an harmonic at 37500, and 27036 has an harmonic at 38500. The end result is that, when you use Frequency values above 32768 with the FREQOUT command, you are specifying the value of the harmonic, not the fundamental.

    Andy

    Post Edited (Andy Lindsay (Parallax)) : 3/5/2005 6:39:25 PM GMT
  • edited 2005-03-05 19:29
    Russ,

    This is a reply to your question about the difference between the stated frequency and the frequency shown in the filter sensitivity graph. Once upon a time, Panasonic's datasheet showed a center freuqnecy of 38500; now it's 38000, as shown in the excerpt on page 270 of Robotics with the Boe-Bot 2.2. With the revisions to date, I have always gone through the books sequentially, starting from Chapter 1. The last couple times the publication deadline has snuck up and bit me as I was in Chapter 8. There were more pressing tech support concerns in Chapter 8, so had to forgo resolving that inconsistency. Please rest assured we will put it at the top of the v2.3 revision list.

    Andy
  • Russ FergusonRuss Ferguson Posts: 206
    edited 2005-03-06 02:30
    Andy:

    Thank you for making this post. It is finally sinking in that FREQOUT is synthesizing a sine wave from some number of digital pulses that are at the appropriate voltage. Both Allen and you have brought this up.

    So it is the voltage change for each one of the pulses that generates a harmonic. The largest voltage steps generate their own distinct harmonic. It appears that those larger voltage steps could occur as many as 4 times per cycle depending on the number of stair step digital pulses used to synthesize the desired sine wave. I'm just thinking out loud, not trying to answer my own question. Does this sound like I am thinking the right way about it?

    Looks like I will be opening up "Understanding Signals" next. My understanding of side band theory is very weak, so maybe it will help.

    Russ
  • edited 2005-03-06 04:03
    Russ,

    Yes, you're well on your way. The BASIC Stamp does send many pulses per sine wave cycle. If you think of each pulse as a very brief square wave, its frequency is pretty high. There are probably lots of little dancing harmonics (3rd, 5th, 7th, etc) that appear and disappear during a FREQOUT command. My spectrum analyzer only measures signals up to 100 kHz, so I can't see them.

    The main thing to keep in mind is that the FREQOUT command really sends two sine waves mixed together. For audio speakers, the higher frequency sine wave is outside the human hearing range of 20 Hz to 20 kHz. Speakers are also natural filters, and they'll certainly·attenuate any of those signals above 32.7 kHz. Fortunately for the Boe-Bot, IR LEDs do not filter out·those higher frequency signals, and the IR detectors do a great job of picking·them up.

    I wouldn't worry about the double sideband thing. Just focus on Understanding Signals; it's an excellent way to look more closely at a variety of ways that the BASIC Stamp can interact with circuits. It's really cool, and will show (among other things) how two sine waves can be mixed together, and how to resolve a mystery signal into its component sine wave frequencies.

    Andy

    Post Edited (Andy Lindsay (Parallax)) : 3/7/2005 3:01:42 AM GMT
Sign In or Register to comment.