Shop OBEX P1 Docs P2 Docs Learn Events
Pulsout/Serout question — Parallax Forums

Pulsout/Serout question

jcfergusonjcferguson Posts: 86
edited 2007-04-05 15:16 in BASIC Stamp
Hi there,

I am sending information via RF 433 units and wonder if anyone has more information about the Pulsout that goes before the Serout.

as in:

PULSOUT rfpin, 2200
SEROUT rfpin, 240, [noparse][[/noparse] "1", DrivePotVal.HIGHbyte, DrivePotVal.lowbyte, TiltPotVal.HIGHbyte, TiltPotVal.lowbyte, RelayOnCar ]

The text for the RF unit (from parallax) has a value of 1200 for the pulsout - but I switched to a bs2sx and the value doesn't work. How do I pick the "right" value? The text is lacking in this area. Some values seem to make my transmission stutter a bit ( I am driving servos ). Should I just experiment or is there a way to figure this.
Thanks!

Carlos


(here is the text from the parallax website)

Calibration
When initiating communication between the RF modules, a sync pulse should be sent to re-establish the
radio connection between the modules. Sending several characters can accomplish this, however
sending a pulse (which maintains a high state during the synchronization) is more efficient:

√ For BS1s the following code line sends an appropriate sync pulse:

PULSOUT 1, 300

√ For BS2s the following code line sends an appropriate sync pulse:

PULSOUT 8, 1200

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-05 14:01
    If you look in the PBasic manual, you'll see a table at the beginning of the PULSOUT description that has the timing information for the various Stamp models. For the BS2, the units are 2us, so a "PULSOUT 8,1200" gives a 2.4ms pulse. Use the information in the table to figure out your PULSOUT value for the BS2sx for the same pulse width.
  • ZootZoot Posts: 2,227
    edited 2007-04-05 14:03
    Check the Pbasic manual -- you will find the "unit" values for commands like SERIN, SEROUT, PULSIN, PULSOUT, FREQOUT, etc. are dependent on the flavor of stamp you are using.

    The best trick here is to use conditional compilation to set constants for values you will use in these commands. That way when you compile for any kind of Stamp your code will work without changes.

    Here's some sample code with conditional compilation and constants for pulsout that might show what I mean a little better:

    ' =========================================================================
    '
    '   File....... SW21-EX26-Servo_Control.BS2
    '   Purpose.... Servo control and positioning with a potentiomenter
    '   Author..... (C) 2000 - 2005, Parallax, Inc.
    '   E-mail..... support@parallax.com
    '   Started....
    '   Updated.... 01 SEP 2005
    '
    '   {$STAMP BS2}
    '   {$PBASIC 2.5}
    '
    ' =========================================================================
    
    
    ' -----[noparse][[/noparse] Program Description ]---------------------------------------------
    '
    ' This program shows how to control a standard servo with the BASIC Stamp.
    ' Servo position is controlled by reading position of a potentiometer that
    ' is part of opposing RCTIME networks.
    
    
    ' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------
    
    PotCW           PIN     0                       ' clockwise pot input
    PotCCW          PIN     1                       ' counter-cw pot input
    Servo           PIN     2                       ' servo control pin
    
    
    ' -----[noparse][[/noparse] Constants ]-------------------------------------------------------
    
    Scale           CON     $00C6                   ' to scale RCTIME values
    Center          CON     1500                    ' servo center position
    
    #SELECT $STAMP
      #CASE BS2, BS2E, BS2PE
        PwAdj       CON     $0080                   ' pulse width adjust (0.5)
      #CASE BS2SX, BS2P, BS2PX
        PwAdj       CON     $0140                   ' pulse width adjust (1.25)
    #ENDSELECT
    
    
    #DEFINE _Testing = 0                            ' 1 for POT testing
    
    
    ' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
    
    rcRt            VAR     Word                    ' rc reading - right
    rcLf            VAR     Word                    ' rc reading - left
    diff            VAR     Word                    ' difference
    sPos            VAR     Word                    ' servo position
    pWidth          VAR     Word                    ' pulse width for servo
    
    
    ' -----[noparse][[/noparse] Initialization ]--------------------------------------------------
    
    Reset:
      LOW Servo                                     ' initialize for PULSOUT
    
    
    ' -----[noparse][[/noparse] Program Code ]----------------------------------------------------
    
    Main:
      HIGH PotCW                                    ' read clockwise position
      PAUSE 1
      RCTIME PotCW, 1, rcRt
    
      HIGH PotCCW                                   ' read ccw position
      PAUSE 1
      RCTIME PotCCW, 1, rcLf
    
      #IF _Testing #THEN                            ' display raw values
        DEBUG HOME,
              "CW (raw) ", TAB, DEC rcRt, CLREOL, CR,
              "CCW (raw)", TAB, DEC rcLf, CLREOL, CR
      #ENDIF
    
      rcRt = (rcRt */ Scale) MAX 500                ' scale RCTIME to 0-500
      rcLf = (rcLf */ Scale) MAX 500
      sPos = rcLf - rcRt                            ' position (-500 to 500)
      pWidth = (Center + sPos)                      ' finalize pulse width
    
      #IF _Testing #THEN                            ' display scales values
        DEBUG "CW ", TAB, TAB, DEC rcRt, CLREOL, CR,
              "CCW", TAB, TAB, DEC rcLf, CLREOL, CR,
              "Pos", TAB, TAB, SDEC sPos, CLREOL, CR,
              "Pulse", TAB, TAB, DEC pWidth, CLREOL
        PAUSE 100
      #ELSE
        PULSOUT Servo, (pWidth */ PwAdj)            ' move the servo
        PAUSE 20                                    ' servo refresh delay
      #ENDIF
    
      GOTO Main
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • jcfergusonjcferguson Posts: 86
    edited 2007-04-05 15:16
    Thanks Mike,

    I did think that I could just multiply my pulsout value by the unit value for the bs2sx, but it didn't quite seem to work right - I guess I'll just stick with that though...

    I wonder if I should use a pull down resistor on the output (data) pin for the rf transmitter (which is active high) to "clean it up"? Or would that be a bad idea?

    Carlos
Sign In or Register to comment.