I can't write sfr as a word??

Hansb56

New Member
I can't write time (sfr) as a word??

Hello,
My name is Hans, I'm from the Netherlands and I'm reading quite a while on the forum. I also made some simple projects.

Now I've a problem.
For a project I measure time with de timer Time.(14M2)
To hold some values I write them to memory (eprom)
That goes fine as long the value does not exceet the byte value.
Values bigger than 256 (word values) can't I write directly.

write 26, time puts the value of time in place 26

I can do it with the use of a normal wordvariabele:

Let W0 = Time
write 30, word W0

will do the job


What doen not work is:

Write 30, word time

I replaced time bij s_w7, no difference.
Also I tried with Poke to write time to memory, the same results.

What do I wrong???

Greetings,

Hans
 
Last edited:

Jeremy Harris

Senior Member
Because the EEPROM is arranged as 8 bit bytes you need to store word values as two bytes. This is fairly easy to do, as, for example, w0 is really made up of the two byte variables b0 and b1, so by saving b0 and then saving b1 to two consecutive EEPROM locations you are saving the word value in w0. To retrieve this from EEPROM you can read back the two bytes into b0 and b1 and recreate the original word value in w0.
 

Hansb56

New Member
Yeah, thanks for your reply.
But that's not the problem.
With the addition of the word WORD in the expression you can directly write a wordvariabele to memory.
Just the variabele time can't be written as a wordvariabele (e.g. in the simulaton) I haven't had the opportunity to check it with hardware becouse of the holidays.

Hans
 

westaust55

Moderator
Welcome to the PICAXE forum.

I recall (but may be in error) that this or a similar situation was highlighted in the past where the system variables eg s_w7 ( = time) could not be handled with the inclusion of the WORD parameter for saving the time value in RAM/EEPROM.
Recall that Rev Ed were looking to a fix to the PE to overcome this situaiton.
 
Last edited:

westaust55

Moderator
Which version of the Programming Editor are you using.

Currently it is at V5.5.6

At V5.5.1, the above fix was included:

Added write/read/peek/poke support for WORD option with the s_Wx variables​

See the "FREE Software" button at the top of the forum pages to download the latest version.
 
Last edited:

Hansb56

New Member
Westaus55, thanks.

When it's a problem in PE I can understand why it doesn't work.
A new problem is that I use the latest version of PE. In the list of fixes I just found your remark with the V5.5.1.
When I come home tonight I try it on another PC, I think I have 5.5.6 on the laptop and 5.5.5 on the desktop. Probably there is some difference.
I understand You can write with the WORD option?

Hans
 

Goeytex

Senior Member
USING PE 5.5.6

With a 14M2 (Firmware 6.A) the compiler accepts "Write 0, WORD time" . The command works as expected in both the simulator and the silicon. (See Attachment).

Test Code
Code:
#Picaxe 14M2 
#No_Data

Pause 100
time = 250  'pre-load time variable

do
    write 0, WORD time
    pause 500
    read 0,WORD W2
    sertxd (#W2," ")
loop
With a 20X2 (Firmware C.2) the compiler will not accept " Write 0, WORD time " where it responds with, "Error: Word variable required!. 20X2 Test Code is identical to above.

However,with the same 20X2 .... " Write 0, WORD timer" works as expected in both the simulator & silicon.
 

Attachments

Last edited:

westaust55

Moderator
USING PE 5.5.6

With a 14M2 (Firmware 6.A) the compiler accepts "Write 0, WORD time" . The command works as expected in both the simulator and the silicon.

With a 20X2 (Firmware C.2) the compiler will not accept " Write 0, WORD time " where it responds with, "Error: Word variable required!. 20X2 Test Code is identical to above

With a 20X2 .... " Write 0, WORD timer" works as expected in both the simulator & silicon.
Yes exactly as one would expect. From manual 2 V7.9 page 13


The M2 parts have 8 word variables:
s_w7 time elapsed time

The X1 and X2 parts have 8 word variables and 1 flags byte
s_w7 timer timer value
 

Goeytex

Senior Member
I also tested on 5.5.1 and it works fine. So I doubt that switching from 5.5.5 to 5.5.6 will make any difference
 

Hansb56

New Member
Hmmm,

Not good enough at the moment.
I use PE V5.4.0 on the laptop. There I get the message
'write0, word time ..............Error, word variable required.

This is the old version of PE, I have to update is.

On the other hand,

On the desktop I use PE V5.5.5.

I get no error message, but it still does not work.
When I use the code of Goeytex, it works fine, his preload is just 250 and smaller than a byte.

Edit: And Yes, I was a little fast with this reaction, with the preload of 250 you can within some seconds see if the wordfunction works.:)

When I change 250 in 1250 it doesn't work anymore. No error-messages, but when I simulate I see no action in de memory.

I will try with connection of some hardware, maybe it will work and just there is a failure in the simulator

Hans
 
Last edited:

Hansb56

New Member
Ok,
Here an update.

I updated the PE on the laptop (which I normaly use for programming)

There I tryed the program of Goeytex again, with the preload 250 as well as a higher preload.

In the simulator it works with small values of time (<256) bigger values don't work.

With hardware connected (I had a 20m2 on an board availeble) it works fine :)

Conclusion: It works with hardware, but not with the simulator.

Hans
 

hippy

Ex-Staff (retired)
In the simulator it works with small values of time (<256) bigger values don't work.

Conclusion: It works with hardware, but not with the simulator.
Please accept our apologies for the simulation issue. I have made a note to have that investigated.
 

Hansb56

New Member
Hippy,

No problem:).
Just when something works different then you expect it's a good reason to examen en search the forum.
So I solved a lot of problems, each time learning more about picaxe.

Hans
 
Top