Shop OBEX P1 Docs P2 Docs Learn Events
BS2 to BS2sx program compatability — Parallax Forums

BS2 to BS2sx program compatability

peteppetep Posts: 5
edited 2008-10-24 15:24 in BASIC Stamp
First off, I'm new to robotics and programming...

So I've been using a BS2 chip with a boe bot for a couple months. I started running out of code space, so I decided to purchase the BS2sx chip.

The first thing I noticed when I plugged in the BS2sx chip was that the drive servos needed to be recentered.

To recenter them I used:
pulsout 750
pause 20

Then I started playing around and tried to load all my old BS2 programs onto the·BS2sx·chip. The boe bot stutters and barely moves.

The batteries are brand new.

Is this happening because of the different processor speed? What do I need to change in my BS2 code to use it on the BS2sx?· If the two chips work significantly differently, where could I get a guide book for the BS2sx? I looked through the Parallax store and there were only BS2 books.

Thanks!

·

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-10-15 07:08
    petep -

    Two things will probably need to be changed. One is the duration in the PULSOUT command, and the second is how·the PAUSE commands are set up. The former is a definite, but the latter is a maybe.

    The BS-2 and BS-2sx have different values for "timer units" (TU's) and thus the program must be modified according to the table in the description of the PULSOUT command in the PBASIC Help file, or PBASIC Reference Manual. Here is a copy:

    Stamp Model·········· BS1········ BS2, BS2e, and BS2pe······· BS2sx, BS2p, and BS2px
    Units in Duration···· 10 µs·············· 2 µs····························· ···· 0.8 µs

    Solving this formula will give you your new durations:

    Old duration···· X New duration
    =
    ··· 2 µs··············· 0.8 µs

    The business with the PAUSE statements just ensures that the servos are refreshed every 20 ms. Servos will not maintain position on their own without this refresh. If the PAUSEs were adequate before, they probably will be now too. If however they were marginal before, they may need to be increased, as almost all instructions execute faster on a BS-2sx.

    Hope that gets you going.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When all else fails, try inserting a new battery.

    Post Edited (Bruce Bates) : 10/15/2008 7:17:32 AM GMT
  • SRLMSRLM Posts: 5,045
    edited 2008-10-15 14:26
    The pause is the same accros all BS models. It's always in ms.
  • peteppetep Posts: 5
    edited 2008-10-15 18:32
    Thanks for both answers.

    In regards to the pause. The way I understand it, if I was relying on a program execution time of 20ms to give me a pause, the execution time would now be faster than 20ms. So I would need to add a Pause to make up the time.

    The way I have it set up, uses a PAUSE 20 after a pulsout. So since I am not using the program execution time to give me a pause, I don't need to worry about pauses.

    For my PULSOUT command,

    Right now PULSOUT 750 gives me a stop on the servo motors. With the SX chip I should use:

    750 * 2us = X * 0.8us

    X = (750 * 2 us) / 0.8us

    X = 1875

    So I should use PULSOUT 1875 for a stop on the servo motors.

    I'll try this tonight, when I get home. But let me know if I'm on the wrong track!

    Now, not wanting to rewrite my code incase I go back to using the BS2 chip. I think I'm going to add this code:


    '
    INITALIZE

    #SELECT $STAMP
    #CASE BS2, BS2E
    Scale CON 65535
    #CASE BS2SX, BS2P, BS2PX
    Scale CON·26214 ' (2us/.8us = 2.5) or we could divide by 0.4 (0.4 * 65536 = 26214)
    #ENDSELECT

    '----IN MY MOTOR SUBROUTINE

    forward_pulse
    PULSOUT 13, 850 / (1** Scale)
    PULSOUT 12, 650 / (1** Scale)
    PAUSE 20
    RETURN


    Am I on the right track with that piece of code?

    Thanks, Pete

    Post Edited (petep) : 10/15/2008 8:55:53 PM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-10-15 18:45
    Pete -

    Perhaps I'm missing something. Where did the 65536 come from? Other than that, your technique seems okay.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When all else fails, try inserting a new battery.
  • peteppetep Posts: 5
    edited 2008-10-15 20:51
    Well, to my understanding, you can't use decimals in PBASIC code. So I couldn't take 750 and divide by 0.4 to get my pulsout or 1825 for the BS2sx. To use decimals you need to use the "**" operator. From the help manual:

    "An interesting application of the ** operator is to multiply by a known fractional value less than one. The fraction value is expressed in units of 1/65536. To find the fractional ** parameter, multiply the fraction part by 65536."

    So I could divide·by 26214/65536 which is (0.4) but not 0.4 itself.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-10-15 21:06
    Pete -

    Oops, sorry about that. Don't know how I overlooked that.

    Looks fine then.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When all else fails, try inserting a new battery.
  • duhzzzduhzzz Posts: 7
    edited 2008-10-24 12:41
    Hi,

    Is there a way to generate or substitute a PAUSE command that will hold for 0.4ms.
    The min time for the command is 1ms and I need to pause for 0.4ms only.

    Thanks
  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-24 13:21
    The PAUSE statement works in units of 1ms, so the minimum pause is 1ms. If you have a spare I/O pin, you can use something like a PULSOUT to that I/O pin. This has a unit size of 0.8us on the BS2sx, so a pulse width of 500 gives you a delay of slightly more than 0.4ms. On the BS2, the unit is 2us. You have to adjust this count lower to account for the execution time of the statements between the two actions you're trying to time.
  • duhzzzduhzzz Posts: 7
    edited 2008-10-24 13:36
    Thank u very much
  • ercoerco Posts: 20,256
    edited 2008-10-24 15:24
    http://www.parallax.com/dl/docs/cols/nv/vol2/col/nv71.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
Sign In or Register to comment.