Shop OBEX P1 Docs P2 Docs Learn Events
BS2 to BS1 code help needed — Parallax Forums

BS2 to BS1 code help needed

KristenKristen Posts: 19
edited 2008-10-29 16:53 in BASIC Stamp
Hello,

I am new to stamp and have short code for the BS2 completed.· I am now switching to BS1 and need to change the code.· Is there anyone who could help me convert the code?

Thanks!· Kristen

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-16 19:04
    There are several application notes on converting BS1 to BS2 code (here www.parallax.com/tabid/440/Default.aspx). Even though you want to go the other way, these should give you enough information and examples (along with the Stamp Basic Manual) to get started.
  • KristenKristen Posts: 19
    edited 2008-10-24 13:52
    Sorry, but I am still stuck.· I managed to convert the definition section but can not find how to change the rest over.· There is such great documentation for the BS2 components.· Can anyone help me convert my short code from BSx to BS1?· Thanks!
  • ercoerco Posts: 20,256
    edited 2008-10-24 15:13
    Have a look at http://www.parallax.com/dl/docs/prod/stamps/BS1nBS2ConvTips.pdf

    If you post your code, you'll have a good chance of getting help. Lots of terrific people here wanting to assist!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."

    Post Edited (erco) : 10/24/2008 3:24:49 PM GMT
  • KristenKristen Posts: 19
    edited 2008-10-24 15:35
    Thanks.· That link actually has some helpful parts.· Here's my BS2 code attached.
  • KristenKristen Posts: 19
    edited 2008-10-24 15:53
    Here's my BS1 code so far, but it has a lot of errors.
  • ercoerco Posts: 20,256
    edited 2008-10-24 17:10
    Good effort! The beauty of the Editor program is that it highlights syntax errors as you go, which eliminates many problems. It's worlds better than the old floppy-based DOS editor, so you're way ahead of where many of us started. Sounds like you're well on your way to editing your program to work on the BS1. That's really the best way to learn, to tough it out and try to reason out every line of code for yourself. Once you get it, it will be SO easy for you. Maybe even fun. Meanwhile, if you get stuck at any particular point, ask here again. Cheers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • KristenKristen Posts: 19
    edited 2008-10-24 17:18
    Thanks for the vote of confidence.· However, I posted both codes because I am stuck and can't find the reason in the convert pdf you posted.· Any ideas on the TM=7 and the motor controller portions?
  • ercoerco Posts: 20,256
    edited 2008-10-24 17:31
    It thinks TM (and later FM) is a label, not a variable... you'll do the right thing. You can either define them properly as variables, or forget the variable and simply fix your statements to SEROUT 6,... and SERIN 7,...

    I see NOCONFIRM_13 (and others) used both as a variable in a SERIN command and also as a label. Can't be both.

    Are you using a motor driver chip, if so, which one?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • KristenKristen Posts: 19
    edited 2008-10-24 17:38
    I am. It is the Motor Mind B Enhanced controller.
  • KristenKristen Posts: 19
    edited 2008-10-24 17:43
    Here's my BS1 code attempt thus far.· Still getting an error on the GOTO and not sure why.· ALso, have no idea if the motor subs are okay.
  • ercoerco Posts: 20,256
    edited 2008-10-24 19:01
    Haven't used that controller, so I'll let others with specific experience help you there.

    But you are trying to use "THEN GOTO", but PBasic 1 has some "peculiarities". For instance:

    IF PIN6 = 0 AND Time = 60 THEN GOTO MotorClose

    should be:

    IF PIN6 = 0 AND Time = 60 THEN MotorClose

    The GOTO is implied. THEN automatically will "goto" (label) Motorclose



    As for: IF PIN2 = 1 OR PIN4 = 1 THEN Time = 0

    I believe IF statements in PBasic1 can only result in that implied "goto" statement. That is, you can't change variable Time. Not directly, anyway. Here's how I do it by adding new labels "newlabel1" and "newlabel2":

    IF PIN2 = 1 OR PIN4 = 1 THEN newlabel1
    goto newlabel2
    newlabel1:Time = 0
    newlabel2: ...

    or more directly (changing your IF statement) with new label "skipreset":

    IF PIN2=0 AND PIN4=0 then skipreset
    Time=0
    skipreset: ...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."

    Post Edited (erco) : 10/24/2008 7:09:08 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-24 19:04
    I don't think the DO LOOP construct is allowed in BS1 Basic. It probably thinks DO: is a label. You might want to change it to something else and replace the LOOP with a GOTO to the something else.

    The BS1 does not support SERIN timeouts and the format of SERIN and SEROUT statements is slightly different from BS2 Basic.

    You really need to sit down with the Basic Stamp Manual and your program, look at the various statements you're using, and
    check the manual for each one to see what's different from BS2 to BS1. You might go through the conversion tips again.
    It's a tedious process, but straightforward once you familiarize yourself with the differences.
  • ercoerco Posts: 20,256
    edited 2008-10-25 16:27
    Mike: Good call on that DO interpreted as a label. I had not noticed that.

    Kristen: Don't be frustrated by the BS1 differences, it's a great chip and well-suited to many applications. I have enjoyed this thread just to remind myself of the BS1, where I started in 1994!

    Have you verified that the BS1 serout/Serin speeds are fast enough for your Motor Mind controller? I found that the BS1 was not fast enough to send serout data to the SX Video Module, so I was forced to use a BS2 in that application.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • KristenKristen Posts: 19
    edited 2008-10-27 18:32
    Okay.· I have spent the weekend struggling with this.· I am really confused on the motor controller segments.· I followed all the conversion tips.

    For the main do loop.· I understand the loop becoming a GOTO Main, but what would the Do change to?· Neither is in the conversion doc.



    Regarding the serin/out with the BS1, I think I should be all set.· I confirmed each of my components with the Parallax tech guys before trying to switch to the BS1.· The BS2 is a great board, just a lot more than is required for this application.

    I've attached my work in progress thus far.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-10-27 19:39
    When the compiler encounters a DO, it normally creates an address for it. When the loop is encountered it essentially translates to a GOTO the address of the DO command, assuming there were no conditionals. So where DO is you could just create a label such as:
    Main:
    Time = 0
    Cycle:
    DEBUG Time,CR
    DEBUG PIN2,CR
    DEBUG PIN4,CR
    IF PIN6 = 0 AND  Time = 60 THEN MotorClose
        PAUSE 1000
        Time = Time + 1
        IF PIN2 = 1 OR PIN4 = 1 THEN NewLabel1
        IF PIN5 = 0 AND PIN4 = 0 THEN MotorClose
        IF PIN3 = 0 THEN MotorOpen
    GOTO Cycle
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • KristenKristen Posts: 19
    edited 2008-10-28 15:15
    Thanks.· That was a big help.· I also saw how to eliminate the newlabel1 since the time=0 was already in Main.

    Now, the remaining issue seems to be with my motormind b enhanced portions (MotorClose, Off, MotorOpen) and the few related lines before Main.· I followed all the conversion doc tips and eliminated the [noparse]/noparse and the GOTO's.



    Does anyone know how to convert the final motor sections?



    Thanks!
  • KristenKristen Posts: 19
    edited 2008-10-28 16:45
    Cleaned up a bit more.· Still having trouble with the SERIN lines.· ANyone know where I can find BS1 programming help for motormind b enhanced?
  • ercoerco Posts: 20,256
    edited 2008-10-29 13:46
    Kristin:

    Please add·generous comments throughout your motor control section so we can see exactly what you're trying to do. I see you have a few "PAUSE 1" commands, which will only pause for 1 millisecond. Is that what you wanted? Did this code work perfectly with a BS2? Do you have a link to a Motor Mind spec page?

    erco

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • JDJD Posts: 570
    edited 2008-10-29 16:53
    Kristen,

    Here is·a BS1·sample code for the Motor Mind B Enhanced. Notice there are no timeout commands in this example since it's not supported by·PBASIC 1.0. In the·following example, it will move the motor and send DEBUG commands to the terminal to indicate action; also the BS1 uses only 1 I/O (0 in the·example) for TM and FM.

    I hope this helps

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Joshua Donelson

    www.parallax.com

    Post Edited (Joshua Donelson (Parallax)) : 10/29/2008 11:27:45 PM GMT
Sign In or Register to comment.