Shop OBEX P1 Docs P2 Docs Learn Events
Help! — Parallax Forums

Help!

ChrisKChrisK Posts: 2
edited 2012-01-24 06:26 in BASIC Stamp
I thought this would have been easy for the STAMP to-do but it seems I could have been wrong..

Im looking to write a program for the stamp that will output a series of square waves at different frequencies starting at 2000hz down to 100hz with a 50% duty cycle.

Any ideas on this one?

Comments

  • FalconFalcon Posts: 191
    edited 2012-01-21 06:30
    You might start by giving your post a more descriptive Title. "Help!" is pretty vague, and really easy to skip over. Try something like "Can BS2 generate a square wave?"


    That being said, have you searched on "Square wave" in the BASIC Stamp forum?

    falcon
  • Mike GMike G Posts: 2,702
    edited 2012-01-21 08:27
    Welcome to the forum ChrisK!

    There's an FAQ that addresses your question - 5th from the bottom
    http://www.parallax.com/tabid/385/Default.aspx

    I tried a few things but was unable to achieve a 2 kHz square wave directly.

    My BS2p outputs a 200kHz square (more the most part) using the following PWM command
    PWM 0, 128, 255
    

    I suppose you could run the PWM output to some external logic... a counter, logic gate, a flip-flop
    http://hyperphysics.phy-astr.gsu.edu/hbase/electronic/bincount.html#c2
  • ChrisKChrisK Posts: 2
    edited 2012-01-21 09:12
    Thank you, I came to the came conclusion,

    I have tried using FREQOUT as well

    As the manual states it has a range of 0 to 32767 Hz, but I believe this generates sine waves.
  • davejamesdavejames Posts: 4,047
    edited 2012-01-21 11:36
    Hello Chris - welcome to the Forum.

    Go here:

    http://www.parallax.com/tabid/440/Default.aspx

    and download the "BASIC Stamp Syntax and Reference Manual 2.2 (5.3 MB)".

    Look on manual page 199 (PDF page 203), you'll find the info for FREQOUT.

    It doesn't produce a pure sinewave - it uses PWM to create the wave and it's up to you to filter the high frequency components of that construction as shown on manual page 200 (PDF page 204).

    You could use this filtered output by running it into a Schmitt trigger inverter (i.e. 74LS14) for "squaring up" the waveform.
  • RDL2004RDL2004 Posts: 2,554
    edited 2012-01-21 15:44
    I tried this on a BS2
    DO
    PAUSE X
    TOGGLE 15
    LOOP
    


    but it isn't fast enough for 2000Hz and the resolution isn't good.

    PAUSE 2 is 188.0 Hz
    PAUSE 1 is 301.2 Hz
    PAUSE 0 is 757.6 Hz

    no PAUSE at all is 1.19 kHz

    I suppose you could try to stick some other code in the loop besides PAUSE for the lower frequencies, but 1.19 kHz is as fast as it will go.
  • GadgetmanGadgetman Posts: 2,436
    edited 2012-01-23 02:25
    Which BS2?

    Some of them are faster than others and can do faster LOOPs...
    The classic BS2 and BS2e executes about 4000 instructions/second,
    the BS2sx does about 10.000 instructions/second,
    the BS2p24 and BS2p40 does about 12.000,
    the BS2pe does about 6.000 instructions/second
    and finally, the BS2px24 blazes away at 19.000 instructions/second.
  • RDL2004RDL2004 Posts: 2,554
    edited 2012-01-24 06:26
    It was a BS2. That's about 5000 instructions/sec (without the PAUSE). You could probably guesstimate from there what other Stamps could do. I have a BS2px24, I may try it on that if I get a chance.
Sign In or Register to comment.