Shop OBEX P1 Docs P2 Docs Learn Events
Square Wave pulses ? — Parallax Forums

Square Wave pulses ?

Blackbird455Blackbird455 Posts: 124
edited 2007-09-21 16:13 in BASIC Stamp
1. Is there a way to produce square wave pulses with a BS1?

2. What type of wave does the pulsout command produce with a BS2?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
ETERNAL NOOB, you could learn alot from a dummy.......

"one should not profess ones ignorance, one should just read more books"
······························································ ......unknown

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-09-21 04:47
    There's no nice neat way to produce square waves with either the BS1 or BS2. You really have to just set up a loop like:
    label1:
       high thePin
       goto label2
    label2:
       low thePin
       goto label1
    
    


    The reason for the two labels and two gotos is to balance the execution time in the two halves of the loop.
    This example would produce the highest frequency square wave and the frequency would obviously depend
    on the model of the Stamp being used. To slow it down, use a pause before each goto. That would get you
    a square wave of approximately 500Hz (2ms in the pauses and some time on the order of 100's of us or less
    for the statement execution time). You could also add statements other than a pause before the gotos to slow
    down the loop, but you'd need to experiment to get just the delay you might need.

    The BS1 and BS2 pulsout statements work essentially the same way except for the granularity of the pulse width.
    You could use a pulsout statement to an otherwise unused pin to produce the delays needed in the above loop.
    This would allow you to easily adjust the square wave frequency by varying the pulsout pulse width, yet give you
    a symmetric square wave.

    Post Edited (Mike Green) : 9/21/2007 4:51:59 AM GMT
  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-09-21 10:15
    1khz loop - this is the fastest program I have clocked on a BS2:



    high thepin

    do
    toggle thepin
    loop

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR

    Post Edited (TechnoRobbo) : 9/21/2007 9:12:02 PM GMT
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-09-21 15:06
    Thanks mike,

    Is that what I am doing when I toggle the pin high,

    for reps 1-30
    toggle 2
    pause 16

    that basically switches it high 30 times with a 16ms pause high and 16ms low right?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Noli nothis permittere te terere
  • Mike GreenMike Green Posts: 23,101
    edited 2007-09-21 15:13
    Yes. Actually, the toggle statement is easier to use than high/low as long as you want a symmetric square wave. If you want something asymmetric, separating the high and low functions as I showed is cleaner. You'll need a proper FOR statement:
    low 2                ' sets pin to known state
    for i = 1 to 30  ' repeat for 15 pulses (15 low->high, 15 high->low)
    toggle 2           ' change pin state
    pause 16         ' 16ms in each state
    next
    
    
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-09-21 15:52
    Just for grins, What processor will produce nice neat square waves?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Noli nothis permittere te terere
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-09-21 15:54
    BTW, mike , I do have the proper FOR statement, Im just on a different computer and couldnt cut and paste.........thanks for pointing it out tho.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Noli nothis permittere te terere
  • BeanBean Posts: 8,129
    edited 2007-09-21 16:13
    The SX or the propeller will generate square waves easily. If you use the SX get the SX48, it has 2 hardware timers that can generate square waves without using any processor cycles.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I know what I know, don't confuse me with the facts...
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
Sign In or Register to comment.