Stamp type at run time
bob kruggel
Posts: 50
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
Bob Kruggel
Comments
·· 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
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
·· 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
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
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Sid
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 Williams
Applications Engineer, Parallax
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 Williams
Applications Engineer, Parallax
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
·· 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
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.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
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
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
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 Kruggel