Variable Sharing between slots
Guido
Posts: 195
I was under the understanding that you could share a Variable between slots. If I save a word variable in slot one using the the PUT command and read it on slot 0, or use the same word variable in Slot·1 again using the Put command, I seem not to be able to read the value in slot 0. Each program would run, Slot 0,Slot 1,and Slot 2. Each Word Variable is Put (*)·and debugged in the same program....Seems it does not like to have this variable shared.
Comments
Store X in scratchpad RAM like this:
PUT 3,x.LOWBYTE:PUT 4,x.HIGHBYTE
Yes it's that simple! This stores the value of X in Scratchpad ram locations 3 and 4 for example.
Retrieve X like this from any other slot or the current slot:
GET 3,lowpart:GET 4,highpart: X=HIGHPART*256+LOWPART
'x will equal 63106
Can't get any simpler right?
Good luck. I just figured that out over the weekend so I had to share it with you. I'm not sure if there's even a better way to exchange word variables between slots but the above method works and is very intuitive to understand.
Engin
When you "PUT" a 'variable', I believe you save that variable in the 'scratchpad' memory of the PIC. This is a different topic than what Parallax means when they say "sharing variables between slots". I'm sure there's a technique that can work, however.
I believe, only the BS2p and BS2pe have 'scratchpad' memory.
Engin
I think your right about what you are saying. Basically I am running a DS1620, in two seperate slots. I am trying to save (PUT)·TempF,Low temp, High Temp·and display them in Slot 0. I assume since the stamp program is line by line that there should be no problem, but there is. Like you said it displays the first slot on Low temp and High temp.
PUT 0,TEMPF.LOWBYTE:PUT 1,TEMPF.HIGHBYTE
PUT 2,TL.LOWBYTE:PUT 3,TL.HIGHBYTE
PUT 4,TH.LOWBYTE:PUT 5,TH.HIGHBYTE
....Any Ideas or is this not possible.
Thanks
Guido
You can also use the PBASIC 2.5 syntax,
PUT 0, WORD tempf ' uses locations 0 and 1
PUT 2, WORD tlo ' 2 and 3
PUT 4, WORD thi ' 4 and 5
That amounts to the same thing, but it saves you some typing. On the other end,
GET 0, WORD tempf
GET 2, WORD tlo
GET 4, WORD thi
One common mistake//bug is using a READ where it should be a GET. Not what you want!
The BS2sx and BS2e each have 63 bytes of user scratchpad (adress 0 to 62), while the BS2p, BS2pe and BS2px each have 127 bytes (address 0-126). The original BS2 does not have any scratchpad.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thanks for the reply, I was using the GET statement and actually was using the PBASIC 2.5 style you listed....I just had to try low and High byte to see if I was reading it wrong. I have to run,but I will post the code tomorrow and see if anyone can figure out what this brainless Italian is doing wrong.....Also how can you run Inialize only one time when running slots....Setting TH=000 and TL=999...
Thanks Again Tracy!
Guido
·
·· When switching slots if you don’t want to run certain initialization code you can set a flag within the initialization code (or even an SPRAM location) then upon entry into the slot you have a BRANCH command (or IF…THEN) which bypasses that code if the flag is set.· I hope this helps.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
I thought about using a Flag, but it seemed to me that when I went back to a certain bank it would clear the Flag. But like you said I could save it in scratch pad.
Thanks Again
Guido
if com = 1 then writeit
Then somewhere in your program you want to jump to READIT in Bank 1.· You would write:
com = 1
RUN 1
At the very beginning of Bank 1 you write:
if com = 1 then readit
At the end of READIT you write:
com = 1
RUN 0
I have a program with six banks and I can jump to a precise routine in any bank and then return to a precise point in any other bank.
I hope you understand what I have said.
Sid
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Don't have VGA?
Newzed@aol.com
·
·
·· The variables (flags) are only cleared if you don’t declare the variables the same in each slot.· Of course, they’re not really cleared, just re-mapped when you don’t declare them the same.· So definitely copy and paste your variable declarations between slots.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
Thanks
Guido
The first 5 word variables in all 3 slots are the same. That is good:
tempIn VAR Word ' RAW TEMPERATURE
tempC VAR Word ' Celsius
tempF VAR Word ' Fahrenheit
TL VAR Word ' LOW TEMPERATURE WORD
TH VAR Word ' HIGH TEMPERATURE WORD
Slot 1 reads the outside temperature and populates all 5 of those varaiables. At the end of slot 1 there is a RUN 2 command, whereupon the code in slot 2 reads the other DS1620. But it reuses exactly the same variables as slot 1, so the readings that were acquired in slot 1 are lost. Also, nothing is ever PUT into the scrachpad ram. Now at the end of slot 2 there is a RUN 0 command. Slot 0 is evidently where the data display is to take place. When slot 0 starts up, the temperatures that were acquired in slot 2 are still held in the above 5 variables. However, the slot 0 code GETs bytes from SPRAM locations 0, 1, 2, and overwrites the results that were stored there by the temperature measurement in slot 2. The code does some math, and displays the results (expecting them to be the two temperatures?), but not. Never was any reading PUT into the scratchpad.
Guido, I think maybe you have a confusion between the scratchpad RAM and the main Stamp RAM. They are two completely different memory spaces.
Exercise 1:
Try this simplified version:
It will give the wrong answer the first time through, but the second pass and subsequently, it should display the temperature readings acquired in slot 2 from the indoor sensor. No GET or PUT involved. The main RAM variables hold the consistent data between slots.
Once you have that working, you can move on to include slot 1 in the loop, 0->1->2->0... To do that will require that you either set aside additional unique variables in the main RAM for outdoor and indoor temperatures, or else define a word data buffer in the scratchpad RAM to hold the outdoor and indoor readings.
Is that making any sense now? I didn't actually check over the DS1620 logic carefully. Does that work okay?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I use your technique but taken to another level if you will. The reason why I like to do it the way I do is because it's nearly self-documenting, it compacts some potentially bulky code and it's easy to use on a program-to-program basis:
'Common Variables: Copy EXACTLY into the beginning of each slot used!
Return_Code VAR BYTE
R_C VAR Return_Code
Iternations VAR NIB
...etc. ...
Return_Code = 255 ' Defaul location set
Primary_Loop:
'Return_Code (R_C) can be set in this slot or any other slot to modify the future program execution
ON R_C (RTN0. RTN1, RTN2, RTN3, RTN4, RTN5, RTN6, RTN7, RTN8, RTN9, RTN10)
'Errors and Default drop through above instruction
Default_RTN:
...
'Initialization code
...
RTN0:
...process...
R_C = 4 'Set to return to RTN4 on next run through
RUN 1
'NO RETURN HERE
...
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->