Shop OBEX P1 Docs P2 Docs Learn Events
output pulses — Parallax Forums

output pulses

LWLW Posts: 8
edited 2011-04-21 09:24 in BASIC Stamp
I have a basic stamp 2 I wish to make it generate a pulse out on one pin I need it to be around 360 hz the complicated bit is I need it to not generate every 36 pulse. So 35 pulses then a missed pulse. Any ideas welcome. Lynton

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2011-04-21 04:43
    So, what have you tried so far?

    Its always easier to get help if you show folks what you've attempted yourself.

    Cheers,
  • Mike GMike G Posts: 2,702
    edited 2011-04-21 06:42
    See the PULOUT command in the STAMP manual.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-21 07:18
    The PULSOUT statement generates a pretty accurate pulse, but doesn't generate the space between the pulses. What you can do is set aside an I/O pin so it's not connected to anything and use that with a PULSOUT statement to produce the space between the pulses. Let's say that 360Hz is a 3ms period (roughly) and you want a 1ms pulse. The unit for the PULSOUT is 2us on the BS2. You'd have this for one pulse:
    pulseWidth CON 500
    spaceWidth CON 1000
    
    
    PULSOUT pulsePin,pulseWidth
    PULSOUT extraPin,spaceWidth
    
    You'd repeat this 35 times, then the 36th time you'd use
    PULSOUT extraPin,pulseWidth+spaceWidth
    
    You could also put the two PULSOUT statements in a FOR / NEXT loop to get the 35 times, but you'd have to adjust the pulse widths slightly to account for the overhead of the FOR / NEXT statements. You'd have to adjust the timing anyway to account for the overhead of the PULSOUT statements.
  • vaclav_salvaclav_sal Posts: 451
    edited 2011-04-21 07:57
    Mike Green wrote: »
    pulseWidth CON 500
    spaceWidth CON 1000
    
    
    PULSOUT pulsePin,pulseWidth
    PAUSE 2
    
    

    .

    Mike , would this accomplish the same given / assuming the 1 ms on / 2 ms off setup is OK for 35 pulses and than wait 3 ms

    PAUSE 3
    for the 36th pulse ?
    Vaclav
  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-21 08:33
    Yes, but PAUSE is a coarse delay with a resolution in milliseconds while PULSOUT provides a fine resolution (2us).
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-04-21 09:24
    Lynton,

    I believe this will do what you want:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    OUTPIN  PIN 0
    DUMMY   PIN 1
    BAUD    CON 16384 + 227
    
    DO
      SEROUT OUTPIN, BAUD, [REP $f0\35]
      PULSOUT DUMMY, 868
    LOOP
    
    It creates the pulses by sending a stream of characters with SEROUT using inverted mode.You can adjust the width of the pulses by changing the $f0 to, say, $f8 for narrower pulses, or $e0 for wider ones. Because, as Mike points out, PAUSE is so coarse, the inter-burst gap has to be filled with something more precise. This entails using an extra pin for a PULSOUT which, on the BS2 has a resolution of 2 us.

    It's always hard to predict exactly how much delay the PBASIC interpreter's overhead will add to the timing. This is one case where having a good scope helps, since you can twiddle the constants until everything comes out just right. Here's a trace from my scope, showing the OUTPIN output on channel one and the DUMMY output on channel two:

    attachment.php?attachmentid=80406&d=1303402957

    -Phil
    640 x 480 - 13K
Sign In or Register to comment.