Shop OBEX P1 Docs P2 Docs Learn Events
I had a misconception about the BS2px24 — Parallax Forums

I had a misconception about the BS2px24

MovieMakerMovieMaker Posts: 502
edited 2008-12-01 13:23 in BASIC Stamp
I thought when you hit the buttons up there in the stamp editor that switched from the say BS2 to the chip of your choice and hit the buttons to switch to 2.5 basic, I thought that it automatically changed the syntax for you. I mean, if you had a program that worked perfectly on the basic stamp 2 and you upgraded the chip to a higher cpu like the BS2px24 like mine it would automatically change things to match the new parameters. So, if I am understanding correctly, you have to do your calculations and change the formulas to match the speeds of the cpus. I guess I am understanding correctly. If I am, this would make the whole picture of why things were not working correctly on my bots. Timing is everything.

Am I correct in the above statements?

Thanks,


tongue.gif

Comments

  • Ken GraceyKen Gracey Posts: 7,387
    edited 2008-11-30 03:25
    MovieMaker,

    You are correct. You will need to change any constants in commands involving timing (i.e., SERIN, SEROUT, PULSIN, PULSOUT, FREQOUT, and others). The BASIC Stamp Windows Editor doesn't do this for you - it only puts a BS2px directive at the top of your program. Changing the values is up to the programmer.

    Considering timing is everything, this is why your BS2 code won't function as expected in other BS2-style modules.

    Ken Gracey
  • FranklinFranklin Posts: 4,747
    edited 2008-11-30 03:44
    Found this in a NV article on the ping
    Okay, time to get back to conditional compilation. While most PBASIC instructions do not
    require parameter changes when moving from one module to another, there are a few that do:
    
    COUNT Units for Duration of COUNT window
    DTMFOUT Units for OnTime
    FREQOUT Units for Duration, Freq1, and Freq2
    PULSIN Units for Variable (measured pulse)
    PULSOUT Units for Duration
    PWM Units for Duration
    RCTIME Units for Variable (measured RC delay)
    SERIN Units in Timeout, value of Baudmode
    SEROUT Units in Pace and Timeout, value of Baudmode
    


    There also was a template file you would use that had a select/case that set parameters for the different chips but I can't find it now.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • SRLMSRLM Posts: 5,045
    edited 2008-11-30 04:08
    Seems like that would have been a good option to have: "Click here to change code to fit the BS2XX controller". I say option because yes, there are probably lots of small things that don't relate well to syntax (like time dependent constants), but it would be a useful feature anyway. Perhaps with a check list like this:

    [noparse]/noparse Change Serial Rates
    [noparse]/noparse Change Shift Rates
    [noparse]/noparse Change Constant _____ to ____
  • MovieMakerMovieMaker Posts: 502
    edited 2008-11-30 05:04
    OK, then there is my answer why I have been in so much trouble. Now that I know that, I can make some progress. Thank you guys so much for your help.

    Stephen, if you see the temple I would love to have a link.

    It has taken months, but now things are becomming in focus! I thank the person who I read in another thread an article that made me think of such a possibility.


    God Bless!~
  • skylightskylight Posts: 1,915
    edited 2008-11-30 11:52
    If changes are up to the programmer then what purpose does the directive do?
    Is it merely to inform the programmer that the following program is specific to that stamp but otherwise has no effect on the compiled program?
    just interested to understand the thinking behind it.
  • MSDTechMSDTech Posts: 342
    edited 2008-11-30 13:30
    Not all commands are implemented in all stamps. If you specify a specific model, the compiler can warn you when you use a command that is not valid for that model.
    Also, you can use conditional compilation based on the model of stamp you are using. Many of the Parallax examples are written to work with multiple models. You will see code like:
    #SELECT $STAMP
    · #CASE BS2, BS2E, BS2PE
    ··· T2400 CON 396
    ··· T9600 CON 84
    ··· T19K2 CON 32
    · #CASE BS2SX, BS2P , BS2PX
    ··· T2400 CON 1021
    ··· T9600 CON 240
    ··· T19K2 CON 110
    #ENDSELECT
    This will substitute the correct baud rate constant depending on the model of stamp specified.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2008-11-30 13:36
    skylight -

    I'm not sure what the thinking was behind it, but this may assist in your understanding of the PBASIC directives. The real source for these questions is the author of the PBASIC language. Since he's not available at the moment, I guess this will have to do.

    I guess the best way I'd describe the PBASIC $STAMP Directive is to say that there are differences among the different PBASIC Stamp models, such that the interpreter knows which one its dealing with. The author of the IDE may have different PCODEs for the different Stamp models. This is a supposition on my part, so don't take it as gospel. If you would like to see what the PBASIC Help file says, here it is:

    "The $STAMP directive is a special compiler command that must be included (usually near the top) in a program to indicate the model of BASIC Stamp targeted." In addition to that, its also used to indicate the names of each of the programs which are to be fetched for inclusion in the each of the banks which are used in a multi-bank project. A project is just a collection of separate PBASIC programs which comprise one single and cohesive unit.

    As far as the PBASIC $PORT directive is concerned, here's what the PBASIC Help file says:

    "The purpose of the $PORT directive is to select a specific serial port for programming the BASIC Stamp. Both standard serial and USB ports (with proper adapter circuitry) may be used. The syntax is as follows:

    ' {$PORT COM#}

    where # is a valid port number. When any PBASIC program containing this directive is downloaded, all other ports will be ignored. This directive is especially important if using two of the same BASIC Stamp models (such as two BS2 modules) on two COM ports and you have two different PBASIC programs to download (one for each BS2). Without this directive, developing and downloading in this case would be a tedious task of always answering the "which Stamp?" prompt."

    Lastly, here is what the PBASIC Help file says about $PBASIC:

    "The $PBASIC directive allows the programmer to specify the syntax level for the compiler to use. Example:

    ' {$PBASIC 1.0} ' use version 1.0 syntax (BS1 only)
    ' {$PBASIC 2.0} ' use version 2.0 syntax
    ' {$PBASIC 2.5} ' use version 2.5 syntax

    Note that while the $PBASIC directive is optional, only version 1.0 syntax is allowed when using a BS1 module. If an attempt is made to select an incompatible syntax for the specified $STAMP directive, the editor will generate a warning. Buttons on the editor tool bar simplify adding or modifying the $PBASIC directive.

    That is a summary of the various PBASIC Directives.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When all else fails, try inserting a new battery.
  • MovieMakerMovieMaker Posts: 502
    edited 2008-11-30 17:25
    Thank You Gentlemen for your input.

    smile.gif
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-11-30 17:39
    The stamp directive is used by the editor for other reasons as well. Besides needing to know if a BASIC Stamp is multi-bank, it also needs to know how to talk to it and at what speed. For example, unlike other BASIC Stamps, the BS2px24 programs and DEBUGs at 19.2Kbps rather than 9600bps.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering


    Post Edited (Chris Savage (Parallax)) : 12/1/2008 11:15:39 PM GMT
  • skylightskylight Posts: 1,915
    edited 2008-12-01 13:23
    Thanks for clearing that up
Sign In or Register to comment.