Resetting scratch pad

russbow

Senior Member
i need to reset a number of values that were stored with the write command. Rather than go through a long write n,x sequence I thought the PTR and PTRINC would be the quick answer.
I have used BPTR often but not PTR. After many failures I tried this from manual 2 -

Code:
#picaxe20m2

ptr=1 ' reset scratchpad pointer to 1

for b1 = 1 to 5
sertxd (@ptrinc) ‘ re-transmit those 5 values
next b1
It fails syntax on the first line with "unknown symbol - ptr"
What am I missing, doing wrong, or totally misunderstanding ?
 
Last edited:

oracacle

Senior Member
i have never used ptr, but a quick look in in editor seem to mean that it is a variable that has to be defined, changing it to bptr allow it to pass but it then fail on @ptrinc, again adding the b to make @bptrinc allow it to pass.

i quick scan through that part of manual 2 show that in the paragraph previous to that example you appear to be using it is referred to as bptr and not ptr
 

srnet

Senior Member
If you get a syntax error, just search the manual for whats causing the error, in this case search the manual for 'ptr'

ptr is there, but only listed against X1 & X2 parts.
 

Goeytex

Senior Member
Let's not confuse general purpose/storage variables and scratchpad @ptr variables. They reside in different ram locations and are accessed with different commands. Only X2 and 28X1 Picaxe chips have scratch memory.

i need to reset a number of values that were stored with the write command
Since you are using an M2, there is no SP memory and any attempt to use "ptr" will return a syntax error. So to clear the variables that were written to EEPROM with the write command, you would use @bptr.

for bptr = 0 to 15
@bptr = 0
next

The above will reset B0 - B15 to a value of '0'
 

hippy

Technical Support
Staff member
i need to reset a number of values that were stored with the write command. Rather than go through a long write n,x sequence...
I think you firstly need to clarify exactly what needs to be reset; are you trying to reset values held in Data Eeprom or something else ?
 

russbow

Senior Member
Thank you all. Now totally confused.

Where am I putting data with Write 1, variable, write 2, variable, .......write n.x etc. I thought it was the scratchpad. Using the 20m2 they go somewhere and seem to be retrievable.

Can I reset these locations to zero without having to program n write x,y statements.
 

Goeytex

Senior Member
"WRITE" stores data in EEPROM, not scratchpad. To clear these locations yo will have to write a "0" to each location.
Code:
symbol loc = b0

for loc = 0 to 15
write loc,0
next
This will clear EEPROM locations 0 - 15

Perhaps you should tell us why you are using eeprom/write for temp data storage.
 
Last edited:

srnet

Senior Member
Write puts bytes into EEPROM, although the entry in the manual for the write command could be clearer, it does give a clue;

Information:
The write command allows byte data to be written into the microcontrollers data
memory. The contents of this memory is not lost when the power is removed.

(Its contents of EEPROM that is not lost when power is removed).
 

russbow

Senior Member
Thanks all. I guess this sums it up -
"WRITE" stores data in EEPROM, not scratchpad. To clear these locations yo will have to write a "0" to each location.
I struggled before with a different chip and cleared up the bptr and ptr difference. Assumed the 20m2 was the same. Can I run a for next loop -

Code:
 for b0=0 to 9
write b0,0
next b0
 

lbenson

Senior Member
But ... if you worry about writing too much to eeprom (writing every second for a few weeks will do it), you can use bptr to access the 512 bytes of RAM in the 20M2. Note that bptr can access b0-b27, and you don't want to accidentally overwrite them.

RAM is volatile, and will be erased when you power-cycle.
 
Top