Shop OBEX P1 Docs P2 Docs Learn Events
Infinite duration for freqout? — Parallax Forums

Infinite duration for freqout?

Evan in L.A.Evan in L.A. Posts: 6
edited 2006-10-12 17:59 in BASIC Stamp
Is there a way to have an infinite duration for the freqout command?· If not, what's the best way to keep if from running out?· Also, I assume that if you issue a new freqout command (i.e. a freqout with a different frequency), it will update immediately and not necessarily wait until the previous duration is completed, is that correct?· I basically want to have a tone always present, but change the frequency at different points in the program.· Thanks so much for the help...·

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-09-21 04:42
    The BASIC Stamp only performs one line of code at a time.

    if you code:
    FREQOUT 2, 5000, 2000
    HIGH 5

    It will sound a tone for 5 seconds before continuing on to put P5 high.

    So, what you want can't be done without external hardware with the BASIC Stamp. The SX or Propeller, yes.

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
    AppBee - XBee ZigBee / IEEE 802.15.4 Adapters & Devices
  • Evan in L.A.Evan in L.A. Posts: 6
    edited 2006-09-21 05:11
    How would you do this with an SX chip?· Sorry for the stupid questions, I am new to this but it's very exciting for me.· :-)
  • Mike GreenMike Green Posts: 23,101
    edited 2006-09-21 05:50
    Basically, the program sits in a loop counting down from some value. Each loop takes a known amount of time. When the count reaches zero, the program toggles an I/O pin (changing from 0 to 1 or 1 to 0) and resets the count to its original value. To change the frequency, you change the original count. The issue is 'how do you do anything else like watch a serial line or somehow interact with the rest of the world'. Usually, the SX uses a timer that does the counting in hardware and causes an interrupt after some period of time. The interrupt routine toggles the I/O pin and starts up the timer again. This scheme leaves a lot of idle time where the SX can do other things. In practice, this sort of thing would be done with a combination of counting and timing. The timer sets the "tick" time and the counter counts them with each "tick" interrupt.

    The Propeller does it even simpler since it has two independent counters in each cog that can generate a frequency on any I/O pin up to about 128MHz and down to less than 1Hz in addition to being able to generate pulses of nearly any complex pattern with programming.
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2006-09-21 09:36
    You can play tunes by issuing multiple commands in sequence:

    FREQOUT 2, 5000, 1000
    FREQOUT 2, 5000, 2000
    FREQOUT 2, 5000, 3000
    FREQOUT 2, 5000, 4000
    etc.
  • Leif MasrudLeif Masrud Posts: 2
    edited 2006-10-12 17:42
    So what I'm hearing is that there's no good way to use the BASIC stamp as a frequency generator? I looks like there's one built into the Professional Development Board, but it only operates at set frequencies. Could the propellor chip be incorporated into a stamp system to act as a frequency generator?
  • Mike GreenMike Green Posts: 23,101
    edited 2006-10-12 17:59
    The Propeller chip has two special counters associated with each cog. Each counter can generate a specific frequency independently from 0 to 128MHz. These are pulse trains though, not sine waves. If you want nice analog tones, you'd either need a lot of external filtering or you can use both counters and the cog itself to generate sine waves (with a little bit of filtering on the output) the same way the Stamps do it with the FREQOUT statement. There are examples in the Propeller Object Exchange. The Propeller can have multiple independent channels of sound synthesis. Chip posted some experiments with vocal tract synthesis a while ago on the Propeller forum so this can get quite complex.

    To answer your question more directly: Yes, but it would be a fairly trivial use of a very powerful processor. You could add a couple of resistors and RCA and PS/2 connectors and have a PS/2 keyboard controlled frequency synthesizer with a TV display of the current settings, plus some keyboard controlled digital switches, plus some logic indicators on the display.

    Post Edited (Mike Green) : 10/12/2006 6:03:23 PM GMT
Sign In or Register to comment.