Shop OBEX P1 Docs P2 Docs Learn Events
Stamp type at run time — Parallax Forums

Stamp type at run time

bob kruggelbob kruggel Posts: 50
edited 2005-05-26 02:49 in BASIC Stamp
Is it possible to determine what type of stamp (BS2, BS2p, etc) is running my program at run time? If yes, then I can adjust clock dependent instructions, I.E. PULSOUT, to run correctly at run time. It's obvious that the editor can perform this by using the identify icon.
Bob Kruggel

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-24 23:12
    Bob,

    ·· If you use conditional compilation for the instructions that are timing dependant, then the program will compile each time using the correct values for those commands.· Jon Williams can elaborate on this and has a template you could use, and even add the remaining instructions to.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • bob kruggelbob kruggel Posts: 50
    edited 2005-05-24 23:20
    Chris,

    I know it is possible to do a conditional compile. My question is whether I can determine the type of Basic Stamp at run time if my code is running in a stamp type different than the one I used when I wrote my code.

    Bob Kruggel
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-24 23:30
    Bob,

    ·· No, there is no way you can do this, however, the real point to understand is that the compiled code cannot migrate from one stamp to another.· The fact that it's compiled for a specific stamp means that your variables and such would already be taken care of at compile time prior to the download.

    ·· Once it's downloaded onto the stamp there's no longer a need to change these parameters.· They really should be addressed at compile time.· To that end I don't see why you would want to change these values at run-time.




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com


    Post Edited (Chris Savage (Parallax)) : 5/24/2005 11:33:40 PM GMT
  • bob kruggelbob kruggel Posts: 50
    edited 2005-05-24 23:49
    Chris,

    I thought the TOKENIZER allows a developer to download the tokens to a stamp and that this is a way to upgrade·code in the field without distributing source code. Isn't it possible under these conditions to need to identify stamp type at run time? I could certainly have installed my code in different stamp versions by using the conditional compile, but how can I upgrade the code without knowing the stamp version being used?

    Bob Kruggel
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-25 00:04
    Not at run time, but you can do it at compile-time.· Before attempting a download the compiler queries the BASIC Stamp module for its type to make sure the instructions used are compatible for the module.· You can't, for example, use LCDCMD, LCDOUT, or LCDIN with a stock BS2 -- this requires the BS2 family.

    When you use the "Create Object Code" option in the compiler, it will require a module type and the resultant code can only be downloaded to that type.· Again, this has to do with the token set created for the target module.
    bob kruggel said...
    Is it possible to determine what type of stamp (BS2, BS2p, etc) is running my program at run time? If yes, then I can adjust clock dependent instructions, I.E. PULSOUT, to run correctly at run time. It's obvious that the editor can perform this by using the identify icon.
    Bob Kruggel
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • NewzedNewzed Posts: 2,503
    edited 2005-05-25 00:11
    Jon, did you mean the BS2p family?

    Sid
  • bob kruggelbob kruggel Posts: 50
    edited 2005-05-25 00:15
    Jon,

    I just read the tokenizer document (BASIC Stamp Programming Protocol) which shows how to interrogate a stamp to determine stamp type. I assume the purpose of this is to multiple version of tokenized code for different stamp types. My question my be irrational, but I guess I'm asking if a stamp can interrogate itself to find out what type it is.

    Bob
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-25 00:21
    That's actually an interesting question ... and the answer is No. Again, the only tokens allowed to be downloaded to a BASIC Stamp are those that will actually work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • bob kruggelbob kruggel Posts: 50
    edited 2005-05-25 00:29
    Chris and Jon,

    Thanks for your responses. I'll chew on this for awhile and try to figure out if a stamp can talk to itself through the serial port. I think I'm in over my head.

    Bob
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-25 00:48
    Just keep in mind that the compiler will never allow you to download code to a module that it can't run on. Perhaps you can use a couple spare pins to determine what type module you're running, that way the code can make adjustments to things like the baud rate parameter in SERIN/SEROUT.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • bob kruggelbob kruggel Posts: 50
    edited 2005-05-25 00:54
    Jon,

    Am I incorrect to assume that the code I write fo BS2 uses the same tokevs in a BSsx or BS2p. I'm not trying to make a BS2 run code that uses statements unique to BS2p.

    Bob
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-05-25 01:00
    Bob,

    ·· If you read the docs for the compiler you would find that the Stamp responds with a version after being reset and sent a command to do so within a very short window.· Because the Stamp module is being reset, it cannot be done from within the Stamp itself, only by the host PC, which is generating the reset via the DTR line.

    ·· The bottom line is that when you compile the code and download it to the Stamp module, it's locked in to that Stamp Module.· You cannot forcibly remove it and place it in another Stamp, so there is no need to change any paramaters at run-time.

    ·· Jon's condition compilation template shows an example of how these parameters can be substituted at compile time, and the appropriate ones downloaded to the Stamp at compile time.· Then when you pop in·a new Stamp Module and re-compile, the changes are made by the compiler for the new Stamp Module.· You must provide this information only once in your source code to be cross-module compatible.· These examples can be found in various places in these forums.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-25 01:09
    BS2 programs will run on the BS2sx and BS2p ... but some time-oriented instructions must be adjusted due to the speed of the module.· Using the suggestion I mentioned earlier you might do something like this at the top of your program:

    Reset:
    · module = INA & %0011
    · SELECT module
    ··· CASE %00················ ' BS2
    ····· baud = 84············· '·T9600
    ··· CASE %01················ ' BS2p
    ····· baud = 240
    ··· CASE %10················ ' BS2px
    ····· baud =·396
    · ENDSELECT

    This examines jumpers connected to P0 and P1 for the module type, then sets a variable that will be used in SERIN and SEROUT.· The only issue, of course, is that you use up variable(s) to store values required to adjust for the different modules.· Or, you could use a similar structure and put in redundant instructions that satisfy the requirements of the modules you might use.· This saves variable space, but consumes more program space.
    bob kruggel said...

    Jon,

    Am I incorrect to assume that the code I write fo BS2 uses the same tokevs in a BSsx or BS2p. I'm not trying to make a BS2 run code that uses statements unique to BS2p.

    Bob

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-05-25 15:15
    Hi Bob,

    The multi-bank stamps all have scratchpad RAM, 63 bytes in the 'sx and 'e, and 127 bytes in the p, pe and px,, so your program can attempt to write and read locations 62 or 126 and sort into these groups, (BS2) (2e, 2sx) (2pe, 2p, 2px).

    The '2pe has 32kb of EEPROM, so you can identify a 2pe by writing/reading bank 15. (BS2) (2e, 2sx, 2p, 2px) (2pe)

    Jon mentioned using an extra pin on the Stamp to provide the type information. Another way to use the pin would be to hang an RC circuit there. By measuring RCtime, the Stamp could identify itself down to timing group, (2uS: 2, 2e, 2pe), (0.8uS: 2sx), (0.75uS: 2p, 2px). If your system has an accurate timing source (like, an RTC with a 1 second pulse pin), you could use PULSIN to achieve greater accuracy. In fact, there is variation (~1%) in the timing from Stamp to Stamp within each family, due to the tolerance of ceramic resonators. An accurate crystal timing reference from an RTC can allow a Stamp to "calibrate" itself.

    You might find this URL informative, about the programming algorithm, and how one Stamp can program another:
    http://www.emesys.com/BS2clone.htm


    bob kruggel said...
    Is it possible to determine what type of stamp (BS2, BS2p, etc) is running my program at run time? If yes, then I can adjust clock dependent instructions, I.E. PULSOUT, to run correctly at run time. It's obvious that the editor can perform this by using the identify icon.
    Bob Kruggel
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • bob kruggelbob kruggel Posts: 50
    edited 2005-05-25 16:35
    Tracy,
    Thanks or some additional thoughts. I keep hoping someone will give me the memory locations that contain the type information used to send that info to the editor. I'll let all this simmer for a couple of days.
    Bob Kruggel
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-05-25 17:13
    Hmm, I know in the protocol, when the IDE programs the stamp, one of the first things the stamp sends to the IDE is what kind of stamp it is. I assume (since it is so early in the protocol) that this information is stored on the PIC 16C54's Flash RAM when it is manufactured by Parallax. You don't have access to the Flash RAM, that's where the Parallax proprietary run-time engine is stored.

    Now you COULD create a 'DATA' entry on your Stamp projects, and put there some number which your program can 'READ' and interpret to be the stamp type (DATA and READ access the on-stamp EEPROM where your program is stored). This would be easier (and would not use a BS2 pin) than dedicating a pin to the purpose. And I suppose you could use the #define approach to set the value of the byte going into the EEPROM, so it automatically changes based on what Stamp you compile for.

    And regarding "adjusting the timing" of built-in commands -- probably not a good thing to do.· You only have programmatic control of the PIC using PBasic -- 2000 to 10,000 Basic Instructions Per Second.· This is way slow compared to the PIC process rate in the run-time.· Meaning that the IDE will do a MUCH better job of making sure all the timings are correct than you can.

    Unless there's something I really don't understand about your question.

    Post Edited (allanlane5) : 5/25/2005 5:16:37 PM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-05-25 17:24
    Hmm again. So it sounds like you want to have multiple stamps in the field. You then want to upgrade their programs, without sending source -- so you generate 'loadable' versions of the programs. Now, the field installer needs to know which kind of stamp is in the device -- I assume opening the box and looking at the label is not something you want.

    Then the field installer can choose the appropriate EXE to load the correct Stamp type program into the correct type stamp.

    Since you have to attach to the programming port to install the program, you could use hyperterm to connect to the port. You could have your BS2xxx program output a serial message when reset, which said what kind of BS2 was inside. Connect your programming PC, run the terminal, hit reset, the BS2 tells you. Select the right upgrader program, and run it.

    Does this solve your problem?
  • bob kruggelbob kruggel Posts: 50
    edited 2005-05-26 02:49
    With all the suggestions you've given me, plus the description I found for using the tokenizer, I'll just assume I need an external method to determine the stamp type and download thge appropiate version of code.
    Bob Kruggel
Sign In or Register to comment.