Variables - VAR vs RAM

rfeyer

Active Member
Am I understanding the following correctly:
 
There are only 16 allowed variables with PLC - 8 VAR and 8 RAM other than the hard coded variables of time/temp etc
 
The only difference between VAR and RAM is the ability for VAR to store DELAY values
 
Rainer
 
I believe that VAR variables keep their values through a reboot but I cannot find mention in the docs. If the EPROM spqce is used you may want to limit usage to infrequent to not wear the EPROM out. Recent technology has reduced this problem considerably.
 
RAM variables have special opcodes to break them down into smaller segments to help lack of memory location resources. eg: RAM1B15
 
Wayne will need to clarify the first one.
 
VAR does not keep value through power cycle.
VAR can be visible on web browser, so that it is useful for debugging
VAR is also accessible through HTTP protocol, RAM can not.
 
RAM can be accessed through byte, RAM1 can be accessed through bit. VAR can not, due to there is a delay associated with whole VAR.
 
Thank you very much -
what is the difefrence between accessibility bite versus bit (other than one being a larger value)?
 
Just a cheap and easy way of breaking down ram space into more and smaller quantities without bit-twiddling code.
 
In view of the shortage of scratchpad space CAI created a more efficient way with macro Opcodes.
 
 
In the ole' days to get at a bit inside an integer
 - load compound variable data
 - shift bits left
 - shift bits left
...                            # had to count shifts  to isolate one bit  - the lsbits were usually shifted right for shorter code.
 - shift bits left
 - test zero or carry flag
 - branch if zero or carry flag was set.
 
 
another way
 - load compound variable data
 - logical AND with 0x00100000000000 # use a mask to isolate bits
 - branch if result =/= 0
 
 
current PLC way
     TSTEQ RAM1B8 1   # check RAM1 for bit 8 (note: there is no bit 0) as the usual standard)
     GOTO BIT_SET
BIT_CLEAR:
 
 
or more compact yet
     BNZ RAM1B28  BIT_SET     #check RAM1 bit 28 and branch if set.
BIT_CLEAR:
 
Ouch - the old days were not the easy days (although I am actually old :)
 
So, it is then semi infinite (well large quantities) of variables that could be addressed in this one RAM1 container?
Not that I would be able to, but for the purpose of learning

Rainer
 
rfeyer said:
So, it is then semi infinite (well large quantities) of variables that could be addressed in this one RAM1 container?
Not that I would be able to, but for the purpose of learning
 
With the bit-wide constructs, you can easily address up to 32 "flags". Far from "infinite" or "large quantities", but "enough for many purposes"
 
It means though, that it is simple to set flags for things you want done once (eg sending an alert) or want to know if an event has happened (has the door opened? has the temperature gone over a set point?) are now "almost trivial" to achieve, and far more efficient (and in many cases more readable) code can be written.
 
If you have first 8 bits in RAM1 as flags and condition for bit1 through bit4 are 1, then bit5 to bit8  are  all zero, then act_one
you can simply calculate the above condition is 15D, so that
TSTEQ RAM10 15
callsub ACT_ONE
 
Or you can use byte2 to store a state, if ALLINS or ALLOUTS match that stored state byte, take an action.
WC8 has limited memory, this way, it will speed up processing and use the space more efficient.
 
That is, though, great to know and gives at least some additional variables since variable declarations do not seem possible.

TY ALL!
 
Back
Top