Unexplained Variable

ZOR

Senior Member
I have some code that has been stripped down to minimum to try and find why I am getting a variable b2 appearing in my debug. I was using b2 for something else but found it did not work properly. Trying to make code accept either ADC from pot, or optically with IR remote. Thanks

Is b2 reserved?

main:

IRIN [100, cd], C.1, b1
debug
IF b1=16 then goto UP

cd:
' code in here to read pot value
goto main


UP:
' Increase Brightness
w1=w1+1
PwmOut C.2, 63, w1
goto main
If I hold down the remote control to create value to goto UP, I get an acumalative b2 value show in debug window
 

ZOR

Senior Member
Many thanks, so now I need to find a reference list of user numeric and word variables. I thought all w's were words and b's were numeric. Thanks again, back to manuals.
 

IronJungle

Senior Member
A word (w) var is simply two byte (b) vars.

Some functions require a w var. I think 'random' is one of those examples. Other times you need the w to get a higher max value or better resolution.

There is a handy colorful chart that some forum user created. I have it on my hard drive and use it often. I would page slap you with a link to it, but searching from my iPhone is clunky.
 

ZOR

Senior Member
Thanks IronJungle for the information. Fortunately I have not had to call on using too many variables, and thanks eclectic the link made good reference to what was happening. Have a good weekend both.
 

westaust55

Moderator
Many thanks, so now I need to find a reference list of user numeric and word variables. I thought all w's were words and b's were numeric. Thanks again, back to manuals.
See my PICAXE variable map and M2 SRF'S charts in this thread: http://www.picaxeforum.co.uk/showthread.php?11514-PICAXE-Memory-Map-and-SFR-Details-Chart/page3

With care, you can use the same variable for different purposes throughout a program provided you keep track of usage and where in the main code and subroutines.
 
Last edited:

ZOR

Senior Member
Excellent looking work, however way over my head. Good to know of a few to use independent numeric variables, word variables both for short words, low numbers. I'm okay for now thanks
 

MikeAusP

Member
This is part of what I use at the start of every new 20M2 program to make it easier to avoid such traps -

Code:
'SYMBOL table - aliases for byte values
SYMBOL ChangeMe00 = B0  ' Danger B1-B0 overmapped by W0 & by bit0 - bit7
SYMBOL ChangeMe01 = B1 
SYMBOL ChangeMe02 = B2  ' Danger B3-B2 overmapped by W1 & by bit8 - bit15
SYMBOL ChangeMe03 = B3
SYMBOL ChangeMe04 = B4  ' Danger B5-B4 overmapped by W2 & by bit16 - bit31
SYMBOL ChangeMe05 = B5
SYMBOL ChangeMe06 = B6  ' Danger B7-B6 overmapped by W3
SYMBOL ChangeMe07 = B7
SYMBOL ChangeMe08 = B8  ' Danger B9-B8 overmapped by W4
SYMBOL ChangeMe09 = B9
SYMBOL ChangeMe10 = B10 ' Danger B11-10 overmapped by W5
SYMBOL ChangeMe11 = B11
SYMBOL ChangeMe12 = B12 ' Danger B13-B12 overmapped by W6
SYMBOL ChangeMe13 = B13
SYMBOL ChangeMe14 = B14 ' Danger B15-B14 overmapped by W7
SYMBOL ChangeMe15 = B15
SYMBOL ChangeMe16 = B16 ' Danger B17-B16 overmapped by W8
SYMBOL ChangeMe17 = B17
SYMBOL ChangeMe18 = B18 ' Danger B19-B18 overmapped by W9
SYMBOL ChangeMe19 = B19

'SYMBOL table - aliases for word values
Symbol ChangeMe99 = W10
SYMBOL ChangeMe98 = W11
SYMBOL ChangeMe97 = W12
SYMBOL ChangeMe96 = W13
It also helps remind me which variables are still free.

When using Words, I start with W10 because there will be no conflict if I later need more Bytes.
 
Last edited:

westaust55

Moderator
@MikeAusP,

your bit vairable allocations are not correct. To avoid confusion you might like to change your temple to:
Code:
'SYMBOL table - aliases for byte values
SYMBOL ChangeMe00 = B0  ' Danger B1-B0 overmapped by W0 & by bit0 - bit7
SYMBOL ChangeMe01 = B1[COLOR="#B22222"] ;                                 overmapped by bit8 - bit15[/COLOR]
SYMBOL ChangeMe02 = B2  ' Danger B3-B2 overmapped by W1 & by [COLOR="#FF0000"]bit16 - bit23[/COLOR]
SYMBOL ChangeMe03 = B3 [COLOR="#FF0000"];                                 overmapped by bit24 - bit31[/COLOR]
SYMBOL ChangeMe04 = B4  ' Danger B5-B4 overmapped by W2 [s]& by bit16 - bit31[/s]
SYMBOL ChangeMe05 = B5
:
:
:
 

ZOR

Senior Member
Many thanks both, that should prevent me allocating pitfall variables in the future, thanks for the work in doing this.
 

IronJungle

Senior Member
The memory map I was referring to is attached. I use the excellent westaust55 one as well. This one is more 'bare bones' for understanding bytes and word memory.

I got this chart from the forum. I did not create it, but thanks to whoever did!

View attachment picaxebytes.pdf
 
Last edited:
Top