Peek/Poke Problem

So from the help from people on the forum, I found out about storing varribles in internal memory in the PICAXE. So I had something to store over 30 measurements from an ultrasonic sensor. But when I tested peek and poke with two measurements, one came out the same and the other turned out different. Either it's something wrong with the code or PICAXE.

Here's my code.

main:
servo B.0, 120   'servo looks one way
low B.1             ' measurement is taken
high B.1
pause 1
pulsin B.1, 1, w2
debug w2         'measurement is debugged for me to write down
pause 3000
poke 58, word w2 'stored in internal memory
servo B.0, 180      'servo looks another way
low B.1                'takes measurement
high B.1
pause 1
pulsin B.1, 1, w1
debug w1               'debugged for me to write down
pause 3000
poke 57, word w1    ' stored
pause 1000
peek 58, word w0    'first measurement is pulled out
debug w0               'debugged
pause 5000
peek 57, word w0    'second measurement is pulled out
debug w0               'debugged
pause 5000
w0 = 0
poke 57, word w0     'internal memory is reset to 0
poke 58, word w0     'internal memory is reset to 0
goto main

 

here are pics of what i got

2010-06-29_16_37_13.jpg

As you can see w1 = 643 and w2 = 820. These are stored.

 


 

When the number for w2 is pulled back out, it changes.

2010-06-29_16_37_34.jpg

as you can see, the value pulled out of internal memory and placed into w0 is 770. not 815. Now whats even stranger is that when it pulls out the number for w1 it's the same!

2010-06-29_16_37_58.jpg

see when it pulls it out. its the same as w1. 643 and 643. That's what i don't get. Why does it change for the other varriable.

Bytes and words

A word consists of 2 bytes -i.e. w0=b1:b0 . All internal memory stores one byte per address. When you wrote a word variable to address 58, the first byte of the word was written at 58 and the second byte was written to 59. When you wrote to 57, the second byte of the word was written over address 58 thus screwing up your numbers.

BTW --I am using write/read address etc just for the sake of expanation. --Peek and poke may use different terminolgy.

OH. So i need to write onne

OH. So i need to write onne to 57 and then skip 58 and write the next one to 59. Got it.